Mercurial > hg > octave-lyh
annotate scripts/plot/waitbar.m @ 13816:7ee18dc46bbb
new and improved non-integer figure handles
* waitbar.m: Pass NaN and "integerhandle" property to __go_figure__.
* __init_fltk__.cc (OpenGL_fltk::renumber, plot_window::renumber,
figure_manager::renumber_figure, figure_manager::do_renumber_figure):
New functions.
(figure_manager::hnd2idx): Don't declare double arg as const.
Include figure number in error message.
(fltk_graphics_toolkit::update): Handle ID_INTEGERHANDLE.
* graphics.h.in, graphics.cc (gh_manager::do_get_handle): Rename from
gh_manager::get_handle.
(gh_manager::get_handle): New static function.
(gh_manager::renumber_figure): New static function.
(gh_manager::do_renumber_figure): New function.
(figure::properties::set_integerhandle): New function.
(figure::properties::integerhandle): Tag property declaration with S.
(F__go_figure__): Intercept and handle integerhandle property here.
* graphics.h.in (children_property::renumber): New function.
(base_properties::init_integerhandle): New virtual function.
(figure::properties::init_integerhandle): New function.
(base_properties::renumber_child, base_properties::renumber_parent):
New functions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 04 Nov 2011 06:25:13 -0400 |
parents | 72875370e2d1 |
children | b3e1f9ae64dc |
rev | line source |
---|---|
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 -*- | |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
20 ## @deftypefn {Function File} {} waitbar (@var{frac}) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
21 ## @deftypefn {Function File} {} waitbar (@var{frac}, @var{msg}) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
22 ## @deftypefnx {Function File} {} waitbar (@var{frac}, @var{h}, @dots{}) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
23 ## @deftypefnx {Function File} {} waitbar (@dots{}, "FigureProperty", "Value", @dots{}) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
24 ## @deftypefnx {Function File} {@var{h} = } waitbar (@dots{}) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
25 ## Create a waitbar filled to fraction @var{frac} and display an optional |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
26 ## message @var{msg}. The waitbar fraction must be in the range [0, 1]. If |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
27 ## the optional input @var{h} is specified then update the waitbar in the |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
28 ## specified figure handle. Otherwise, a new waitbar is created. |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
29 ## |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
30 ## The display of the waitbar window can be configured by passing |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
31 ## property/value pairs to the function. |
13803 | 32 ## @end deftypefn |
33 | |
34 ## Author: jwe | |
35 | |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
36 function retval = waitbar (varargin) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
37 |
13806 | 38 persistent curr_waitbar; |
39 | |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
40 if (nargin < 1) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
41 print_usage (); |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
42 endif |
13803 | 43 |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
44 frac = varargin{1}; |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
45 varargin(1) = []; |
13803 | 46 |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
47 if (! (isnumeric (frac) && isscalar (frac) && frac >= 0 && frac <= 1)) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
48 error ("waitbar: FRAC must be between 0 and 1"); |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
49 endif |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
50 |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
51 msg = false; |
13806 | 52 |
53 if (isempty (varargin) && ! isempty (curr_waitbar)) | |
54 h = curr_waitbar; | |
55 else | |
56 h = false; | |
57 endif | |
13803 | 58 |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
59 if (! isempty (varargin) && ishandle (varargin{1})) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
60 h = varargin{1}; |
13803 | 61 varargin(1) = []; |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
62 ## FIXME -- also check that H is really a waitbar? |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
63 if (! isfigure (h)) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
64 error ("waitbar: H must be a handle to a waitbar object"); |
13803 | 65 endif |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
66 endif |
13803 | 67 |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
68 if (! isempty (varargin)) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
69 msg = varargin{1}; |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
70 varargin(1) = []; |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
71 if (! ischar (msg)) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
72 error ("waitbar: MSG must be a character string"); |
13803 | 73 endif |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
74 endif |
13803 | 75 |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
76 if (rem (numel (varargin), 2) != 0) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
77 error ("waitbar: invalid number of property-value pairs"); |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
78 endif |
13803 | 79 |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
80 if (h) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
81 p = findobj (h, "type", "patch"); |
13806 | 82 set (p, "xdata", [0; frac; frac; 0]); |
83 ax = findobj (h, "type", "axes"); | |
84 if (ischar (msg)) | |
85 th = get (ax, "title"); | |
86 curr_msg = get (th, "string"); | |
87 if (! strcmp (msg, curr_msg)) | |
88 set (th, "string", msg); | |
89 endif | |
13803 | 90 endif |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
91 else |
13816
7ee18dc46bbb
new and improved non-integer figure handles
John W. Eaton <jwe@octave.org>
parents:
13813
diff
changeset
|
92 h = __go_figure__ (NaN, "position", [250, 500, 400, 100], |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
93 "numbertitle", "off", |
13806 | 94 "toolbar", "none", "menubar", "none", |
13816
7ee18dc46bbb
new and improved non-integer figure handles
John W. Eaton <jwe@octave.org>
parents:
13813
diff
changeset
|
95 "integerhandle", "off", |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
96 "handlevisibility", "callback", |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
97 varargin{:}); |
13803 | 98 |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
99 ax = axes ("parent", h, "xtick", [], "ytick", [], |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
100 "xlim", [0, 1], "ylim", [0, 1], |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
101 "xlimmode", "manual", "ylimmode", "manual", |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
102 "position", [0.1, 0.3, 0.8, 0.2]); |
13806 | 103 patch (ax, [0; frac; frac; 0], [0; 0; 1; 1], [0, 0.35, 0.75]); |
104 | |
105 if (ischar (msg)) | |
106 title (ax, msg); | |
107 endif | |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
108 endif |
13803 | 109 |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
110 drawnow (); |
13803 | 111 |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
112 if (nargout > 0) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
113 retval = h; |
13803 | 114 endif |
115 | |
13806 | 116 ## If there were no errors, update current waitbar. |
117 curr_waitbar = h; | |
118 | |
13803 | 119 endfunction |
120 | |
121 %!demo | |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
122 %! h = waitbar (0, "0.00%"); |
13803 | 123 %! for i = 0:0.01:1 |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
124 %! waitbar (i, h, sprintf ("%.2f%%", 100*i)); |
13803 | 125 %! endfor |
13806 | 126 %! close (h); |
127 | |
128 %!demo | |
129 %! h = waitbar (0, "please wait..."); | |
130 %! for i = 0:0.01:1 | |
131 %! waitbar (i, h); | |
132 %! endfor | |
133 %! close (h); | |
134 | |
135 %!demo | |
136 %! h = waitbar (0, "please don't be impatient..."); | |
137 %! for i = 0:0.01:1 | |
138 %! waitbar (i); | |
139 %! endfor | |
140 %! close (h); | |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
141 |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
142 %% Test input validation |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
143 %!error <FRAC must be between 0 and 1> waitbar (-0.5) |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
144 %!error <FRAC must be between 0 and 1> waitbar (1.5) |
13813
72875370e2d1
allow waitbar test to succeed even if figure 1 exists
John W. Eaton <jwe@octave.org>
parents:
13806
diff
changeset
|
145 %!error <MSG must be a character string> waitbar (0.5, struct ()) |
13805
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
146 %!error <invalid number of property-value pairs> waitbar (0.5, "msg", "Name") |
b3cdef33ac0e
waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents:
13803
diff
changeset
|
147 |