comparison scripts/plot/waitbar.m @ 17447:359366a4994f

waitbar.m: Use Octave coding conventions. * scripts/plot/waitbar.m: Rename 'retval' to 'h' to match documentation. Use 'hf', 'hp' for figure and patch graphics handles.
author Rik <rik@octave.org>
date Thu, 19 Sep 2013 14:26:47 -0700
parents efd8963f925f
children
comparison
equal deleted inserted replaced
17446:9e4e24a0a118 17447:359366a4994f
36 ## of the specific waitbar to modify. 36 ## of the specific waitbar to modify.
37 ## @end deftypefn 37 ## @end deftypefn
38 38
39 ## Author: jwe 39 ## Author: jwe
40 40
41 function retval = waitbar (varargin) 41 function h = waitbar (varargin)
42 42
43 persistent curr_waitbar; 43 persistent curr_waitbar;
44 44
45 if (nargin < 1) 45 if (nargin < 1)
46 print_usage (); 46 print_usage ();
53 error ("waitbar: FRAC must be between 0 and 1"); 53 error ("waitbar: FRAC must be between 0 and 1");
54 endif 54 endif
55 55
56 ## Use existing waitbar if it still points to a valid graphics handle. 56 ## Use existing waitbar if it still points to a valid graphics handle.
57 if (nargin == 1 && ishandle (curr_waitbar)) 57 if (nargin == 1 && ishandle (curr_waitbar))
58 h = curr_waitbar; 58 hf = curr_waitbar;
59 else 59 else
60 h = false; 60 hf = false;
61 endif 61 endif
62 62
63 if (! isempty (varargin) && isnumeric (varargin{1})) 63 if (! isempty (varargin) && isnumeric (varargin{1}))
64 if (! ishandle (varargin{1})) 64 hf = varargin{1};
65 varargin(1) = [];
66 if (! isfigure (hf) || ! strcmp (get (hf, "tag"), "waitbar"))
65 error ("waitbar: H must be a handle to a waitbar object"); 67 error ("waitbar: H must be a handle to a waitbar object");
66 else
67 h = varargin{1};
68 varargin(1) = [];
69 if (! isfigure (h) || ! strcmp (get (h, "tag"), "waitbar"))
70 error ("waitbar: H must be a handle to a waitbar object");
71 endif
72 endif 68 endif
73 endif 69 endif
74 70
75 msg = false; 71 msg = false;
76 72
81 error ("waitbar: MSG must be a character string or cell array of strings"); 77 error ("waitbar: MSG must be a character string or cell array of strings");
82 endif 78 endif
83 endif 79 endif
84 80
85 if (rem (numel (varargin), 2) != 0) 81 if (rem (numel (varargin), 2) != 0)
86 error ("waitbar: invalid number of property-value pairs"); 82 error ("waitbar: invalid number of property/value pairs");
87 endif 83 endif
88 84
89 if (h) 85 if (hf)
90 gd = get (h, "__guidata__"); 86 gd = get (hf, "__guidata__");
91 ## Get the cached handles. 87 ## Get the cached handles.
92 ax = gd(1); 88 ax = gd(1);
93 p = gd(2); 89 hp = gd(2);
94 90
95 set (p, "xdata", [0; frac; frac; 0]); 91 set (hp, "xdata", [0; frac; frac; 0]);
96 92
97 if (ischar (msg) || iscellstr (msg)) 93 if (ischar (msg) || iscellstr (msg))
98 th = get (ax, "title"); 94 th = get (ax, "title");
99 curr_msg = get (th, "string"); 95 curr_msg = get (th, "string");
100 ## graphics handles always store data as column vectors 96 ## graphics handles always store data as column vectors
108 endif 104 endif
109 else 105 else
110 ## Save and restore current figure 106 ## Save and restore current figure
111 cf = get (0, "currentfigure"); 107 cf = get (0, "currentfigure");
112 108
113 h = figure ("position", [250, 500, 400, 100], 109 hf = figure ("position", [250, 500, 400, 100],
114 "numbertitle", "off", 110 "numbertitle", "off",
115 "toolbar", "none", "menubar", "none", 111 "menubar", "none", "toolbar", "none",
116 "integerhandle", "off", 112 "integerhandle", "off",
117 "handlevisibility", "callback", 113 "handlevisibility", "callback",
118 "tag", "waitbar", 114 "tag", "waitbar",
119 varargin{:}); 115 varargin{:});
120 116
121 ax = axes ("parent", h, "xtick", [], "ytick", [], 117 ax = axes ("parent", hf,
118 "xtick", [], "ytick", [],
122 "xlim", [0, 1], "ylim", [0, 1], 119 "xlim", [0, 1], "ylim", [0, 1],
123 "xlimmode", "manual", "ylimmode", "manual",
124 "position", [0.1, 0.3, 0.8, 0.2]); 120 "position", [0.1, 0.3, 0.8, 0.2]);
125 121
126 p = patch (ax, [0; frac; frac; 0], [0; 0; 1; 1], [0, 0.35, 0.75]); 122 hp = patch (ax, [0; frac; frac; 0], [0; 0; 1; 1], [0, 0.35, 0.75]);
127 123
128 ## Cache the axes and patch handles. 124 ## Cache the axes and patch handles.
129 set (h, "__guidata__", [ax p]); 125 set (hf, "__guidata__", [ax hp]);
130 126
131 if (! (ischar (msg) || iscellstr (msg))) 127 if (! (ischar (msg) || iscellstr (msg)))
132 msg = "Please wait..."; 128 msg = "Please wait...";
133 endif 129 endif
134 title (ax, msg); 130 title (ax, msg);
139 endif 135 endif
140 136
141 drawnow (); 137 drawnow ();
142 138
143 if (nargout > 0) 139 if (nargout > 0)
144 retval = h; 140 h = hf;
145 endif 141 endif
146 142
147 ## If there were no errors, update current waitbar. 143 ## If there were no errors, update current waitbar.
148 curr_waitbar = h; 144 curr_waitbar = hf;
149 145
150 endfunction 146 endfunction
151 147
152 148
153 %!demo 149 %!demo
197 193
198 %% Test input validation 194 %% Test input validation
199 %!error <FRAC must be between 0 and 1> waitbar (-0.5) 195 %!error <FRAC must be between 0 and 1> waitbar (-0.5)
200 %!error <FRAC must be between 0 and 1> waitbar (1.5) 196 %!error <FRAC must be between 0 and 1> waitbar (1.5)
201 %!error <MSG must be a character string> waitbar (0.5, struct ()) 197 %!error <MSG must be a character string> waitbar (0.5, struct ())
202 %!error <invalid number of property-value pairs> waitbar (0.5, "msg", "Name") 198 %!error <invalid number of property/value pairs> waitbar (0.5, "msg", "Name")
203 199