13803
|
1 ## Copyright (C) 2011 John W. Eaton |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {@var{h} =} waitbar (@var{frac}, @var{msg}) |
|
21 ## @deftypefnx {Function File} {@var{h} =} waitbar (@var{frac}, @var{h}, @var{msg}) |
|
22 ## Craete a waitbar and display an optional message. |
|
23 ## @end deftypefn |
|
24 |
|
25 ## Author: jwe |
|
26 |
|
27 function h = waitbar (varargin) |
|
28 |
|
29 msg = " "; |
|
30 |
|
31 h = 0; |
|
32 |
|
33 if (nargin > 0) |
|
34 |
|
35 frac = varargin{1}; |
|
36 varargin(1) = []; |
|
37 |
|
38 if (! (isnumeric (frac) && isscalar (frac) && frac >= 0 && frac <= 1)) |
|
39 error ("waitbar: frac must be in between 0 and 1"); |
|
40 endif |
|
41 |
|
42 if (numel (varargin) > 0 && ishandle (varargin{1})) |
|
43 h = varargin{1}; |
|
44 varargin(1) = []; |
|
45 ## FIXME -- also check that H is really a waitbar? |
|
46 if (! isfigure (h)) |
|
47 error ("handle must be a waitbar object"); |
|
48 endif |
|
49 endif |
|
50 |
|
51 if (numel (varargin) > 0) |
|
52 msg = varargin{1}; |
|
53 varargin(1) = []; |
|
54 if (! ischar (msg)) |
|
55 error ("waitbar: msg must be a character string"); |
|
56 endif |
|
57 endif |
|
58 |
|
59 if (rem (numel (varargin), 2) != 0) |
|
60 error ("waitbar: invalid number of property-value pairs"); |
|
61 endif |
|
62 |
|
63 if (h) |
|
64 p = findobj (h, "type", "patch"); |
|
65 if (p) |
|
66 delete (p); |
|
67 endif |
|
68 ax = findobj (h, "type", "axes"); |
|
69 else |
|
70 h = __go_figure__ (Inf, "position", [250, 500, 400, 100], |
|
71 "numbertitle", "off", |
|
72 "handlevisibility", "callback", |
|
73 varargin{:}); |
|
74 |
|
75 ax = axes ("parent", h, "xtick", [], "ytick", [], |
|
76 "xlim", [0, 1], "ylim", [0, 1], |
|
77 "xlimmode", "manual", "ylimmode", "manual", |
|
78 "position", [0.1, 0.3, 0.8, 0.2]); |
|
79 endif |
|
80 |
|
81 patch (ax, [0, frac, frac, 0], [0, 0, 1, 1], [0, 0.35, 0.75]); |
|
82 title (ax, msg); |
|
83 drawnow (); |
|
84 |
|
85 else |
|
86 print_usage (); |
|
87 endif |
|
88 |
|
89 endfunction |
|
90 |
|
91 %!demo |
|
92 %! h = 0; |
|
93 %! for i = 0:0.01:1 |
|
94 %! if (h) |
|
95 %! waitbar (i, h, sprintf ("%.2f%%", 100*i)); |
|
96 %! else |
|
97 %! h = waitbar (i, sprintf ("%.2f%%", 100*i)); |
|
98 %! endif |
|
99 %! endfor |