annotate scripts/gui/waitbar.m @ 26989:a7ad08ed3cb7 stable

waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963). * waitbar.m: Don't use addlistener on "createcancelbtn" property until after properties have been applied to waitbar figure. Tweak code to conform to Octave style guidelines.
author Rik <rik@octave.org>
date Wed, 27 Mar 2019 12:25:05 -0700
parents 98afb8bbd1f6
children 4d6d21839dfd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26015
diff changeset
1 ## Copyright (C) 2012-2019 John W. Eaton
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 ##
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 ## This file is part of Octave.
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24423
diff changeset
5 ## Octave is free software: you can redistribute it and/or modify it
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24423
diff changeset
7 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
8 ## (at your option) any later version.
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ##
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## GNU General Public License for more details.
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ##
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24423
diff changeset
17 ## <https://www.gnu.org/licenses/>.
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20716
diff changeset
20 ## @deftypefn {} {@var{h} =} waitbar (@var{frac})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20716
diff changeset
21 ## @deftypefnx {} {@var{h} =} waitbar (@var{frac}, @var{msg})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20716
diff changeset
22 ## @deftypefnx {} {@var{h} =} waitbar (@dots{}, "createcancelbtn", @var{fcn}, @dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20716
diff changeset
23 ## @deftypefnx {} {@var{h} =} waitbar (@dots{}, @var{prop}, @var{val}, @dots{})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20716
diff changeset
24 ## @deftypefnx {} {} waitbar (@var{frac})
21819
972a06f5fa02 Clarify docs for waitbar (bug #48094)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21758
diff changeset
25 ## @deftypefnx {} {} waitbar (@var{frac}, @var{h})
972a06f5fa02 Clarify docs for waitbar (bug #48094)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21758
diff changeset
26 ## @deftypefnx {} {} waitbar (@var{frac}, @var{h}, @var{msg})
972a06f5fa02 Clarify docs for waitbar (bug #48094)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21758
diff changeset
27 ## Return a handle @var{h} to a new progress indicator ("waitbar") object.
17122
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14313
diff changeset
28 ##
eaab03308c0b doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents: 14313
diff changeset
29 ## The waitbar is filled to fraction @var{frac} which must be in the range
20173
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
30 ## [0, 1].
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
31 ##
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
32 ## The optional message @var{msg} is centered and displayed above the waitbar.
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
33 ##
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
34 ## A cancel button can be added to the bottom of the waitbar using the
20716
1ecee53513d7 doc: Peridodic grammar check of documentation.
Rik <rik@octave.org>
parents: 20715
diff changeset
35 ## @qcode{"createcancelbtn"} property of waitbar figures. The action to be
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
36 ## executed when the user presses the button is specified using a string or
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
37 ## function handle @var{fcn}.
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
38 ##
20173
777f26aa8e3e doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
39 ## The appearance of the waitbar figure window can be configured by passing
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
40 ## @var{prop}/@var{val} pairs to the function.
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18578
diff changeset
41 ##
13832
2e4252228f73 waitbar.m: Eliminate docstring reference to waitbar(frac,msg)
Rik <octave@nomad.inbox5.com>
parents: 13822
diff changeset
42 ## When called with a single input the current waitbar, if it exists, is
2e4252228f73 waitbar.m: Eliminate docstring reference to waitbar(frac,msg)
Rik <octave@nomad.inbox5.com>
parents: 13822
diff changeset
43 ## updated to the new value @var{frac}. If there are multiple outstanding
21819
972a06f5fa02 Clarify docs for waitbar (bug #48094)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21758
diff changeset
44 ## waitbars they can be updated individually by passing the handle @var{h}
13832
2e4252228f73 waitbar.m: Eliminate docstring reference to waitbar(frac,msg)
Rik <octave@nomad.inbox5.com>
parents: 13822
diff changeset
45 ## of the specific waitbar to modify.
21819
972a06f5fa02 Clarify docs for waitbar (bug #48094)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21758
diff changeset
46 ##
972a06f5fa02 Clarify docs for waitbar (bug #48094)
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21758
diff changeset
47 ## @seealso{delete}
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 ## @end deftypefn
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 ## Author: jwe
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
52 function h = waitbar (varargin)
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
53
13806
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
54 persistent curr_waitbar;
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
55
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
56 if (nargin < 1)
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
57 print_usage ();
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
58 endif
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
60 frac = varargin{1};
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
61 varargin(1) = [];
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
63 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
64 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
65 endif
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
66
13821
4d1927edf194 waitbar: use previous bar if nargin == 1, not nargout == 1
John W. Eaton <jwe@octave.org>
parents: 13818
diff changeset
67 ## Use existing waitbar if it still points to a valid graphics handle.
24423
1d52db450db4 Change ishandle to return true for Java objects for Matlab compatibility.
Rik <rik@octave.org>
parents: 23220
diff changeset
68 if (nargin == 1 && ishghandle (curr_waitbar))
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
69 hf = curr_waitbar;
13806
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
70 else
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
71 hf = false;
13806
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
72 endif
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73
13817
b3e1f9ae64dc waitbar.m: More improvements.
Rik <octave@nomad.inbox5.com>
parents: 13816
diff changeset
74 if (! isempty (varargin) && isnumeric (varargin{1}))
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
75 hf = varargin{1};
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
76 varargin(1) = [];
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
77 if (! isfigure (hf) || ! strcmp (get (hf, "tag"), "waitbar"))
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
78 error ("waitbar: H must be a handle to a waitbar object");
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 endif
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
80 endif
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81
13817
b3e1f9ae64dc waitbar.m: More improvements.
Rik <octave@nomad.inbox5.com>
parents: 13816
diff changeset
82 msg = false;
b3e1f9ae64dc waitbar.m: More improvements.
Rik <octave@nomad.inbox5.com>
parents: 13816
diff changeset
83
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
84 if (! isempty (varargin))
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
85 msg = varargin{1};
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
86 varargin(1) = [];
13847
9fc597693b0b allow waitbar message to be a cellstr object
John W. Eaton <jwe@octave.org>
parents: 13832
diff changeset
87 if (! (ischar (msg) || iscellstr (msg)))
9fc597693b0b allow waitbar message to be a cellstr object
John W. Eaton <jwe@octave.org>
parents: 13832
diff changeset
88 error ("waitbar: MSG must be a character string or cell array of strings");
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 endif
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
90 endif
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
92 if (rem (numel (varargin), 2) != 0)
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
93 error ("waitbar: invalid number of property/value pairs");
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
94 endif
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
96 if (hf)
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
97 gd = get (hf, "__guidata__");
17141
13da13e1e17f waitbar.m: Cache axes and patch handles in figure's __guidata__.
Philipp Kutin <philipp.kutin@gmail.com>
parents: 17122
diff changeset
98 ## Get the cached handles.
13da13e1e17f waitbar.m: Cache axes and patch handles in figure's __guidata__.
Philipp Kutin <philipp.kutin@gmail.com>
parents: 17122
diff changeset
99 ax = gd(1);
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
100 hp = gd(2);
17141
13da13e1e17f waitbar.m: Cache axes and patch handles in figure's __guidata__.
Philipp Kutin <philipp.kutin@gmail.com>
parents: 17122
diff changeset
101
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
102 set (hp, "xdata", [0; frac; frac; 0]);
17141
13da13e1e17f waitbar.m: Cache axes and patch handles in figure's __guidata__.
Philipp Kutin <philipp.kutin@gmail.com>
parents: 17122
diff changeset
103
13847
9fc597693b0b allow waitbar message to be a cellstr object
John W. Eaton <jwe@octave.org>
parents: 13832
diff changeset
104 if (ischar (msg) || iscellstr (msg))
13806
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
105 th = get (ax, "title");
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
106 curr_msg = get (th, "string");
14238
1facbe04b00c Fix regression in 9fc597693b0b preventing updating of waitbar text string.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
107 ## graphics handles always store data as column vectors
1facbe04b00c Fix regression in 9fc597693b0b preventing updating of waitbar text string.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
108 if (iscellstr (msg))
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 18578
diff changeset
109 msg = msg(:);
14238
1facbe04b00c Fix regression in 9fc597693b0b preventing updating of waitbar text string.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
110 endif
13847
9fc597693b0b allow waitbar message to be a cellstr object
John W. Eaton <jwe@octave.org>
parents: 13832
diff changeset
111 cmp = strcmp (msg, curr_msg);
14238
1facbe04b00c Fix regression in 9fc597693b0b preventing updating of waitbar text string.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
112 if (! all (cmp(:)))
13806
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
113 set (th, "string", msg);
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
114 endif
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 endif
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
116 else
17203
efd8963f925f waitbar.m: Fix 2nd window pop-up when using gnuplot (bug #35773).
Rik <rik@octave.org>
parents: 17141
diff changeset
117 ## Save and restore current figure
efd8963f925f waitbar.m: Fix 2nd window pop-up when using gnuplot (bug #35773).
Rik <rik@octave.org>
parents: 17141
diff changeset
118 cf = get (0, "currentfigure");
efd8963f925f waitbar.m: Fix 2nd window pop-up when using gnuplot (bug #35773).
Rik <rik@octave.org>
parents: 17141
diff changeset
119
18495
1ec884e5ff00 waitbar.m: Force pixel units for waitbar figure (bug #41645).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17744
diff changeset
120 hf = figure ("units", "pixels",
1ec884e5ff00 waitbar.m: Force pixel units for waitbar figure (bug #41645).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 17744
diff changeset
121 "position", [250, 500, 400, 100],
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
122 "numbertitle", "off",
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
123 "menubar", "none", "toolbar", "none",
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
124 "integerhandle", "off",
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
125 "handlevisibility", "callback",
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
126 "tag", "waitbar");
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
127
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
128 ax = axes ("parent", hf,
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
129 "xtick", [], "ytick", [],
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
130 "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
131 "position", [0.1, 0.3, 0.8, 0.2]);
13821
4d1927edf194 waitbar: use previous bar if nargin == 1, not nargout == 1
John W. Eaton <jwe@octave.org>
parents: 13818
diff changeset
132
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
133 ## Add createcancelbtn property
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
134 addproperty ("createcancelbtn", hf, "figurebuttondownfcn");
26989
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
135 ## FIXME: Can't add listener because of bug #55963.
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
136 #addlistener (hf, "createcancelbtn", {@updatecancelbutton, ax});
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
137
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
138 if (! isempty (varargin))
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
139 set (hf, varargin{:});
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
140 endif
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
141
26989
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
142 ## Add listener and create cancel button only after setting properties
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
143 ## which could change "createcancelbtn" property (bug #55963).
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
144 addlistener (hf, "createcancelbtn", {@updatecancelbutton, ax});
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
145 if (any (strcmp ("createcancelbtn", varargin)))
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
146 updatecancelbutton (hf, [], ax);
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
147 endif
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
148
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
149 hp = patch (ax, [0; frac; frac; 0], [0; 0; 1; 1], [0, 0.35, 0.75]);
17141
13da13e1e17f waitbar.m: Cache axes and patch handles in figure's __guidata__.
Philipp Kutin <philipp.kutin@gmail.com>
parents: 17122
diff changeset
150
13da13e1e17f waitbar.m: Cache axes and patch handles in figure's __guidata__.
Philipp Kutin <philipp.kutin@gmail.com>
parents: 17122
diff changeset
151 ## Cache the axes and patch handles.
26989
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
152 set (hf, "__guidata__", [ax, hp]);
13806
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
153
13847
9fc597693b0b allow waitbar message to be a cellstr object
John W. Eaton <jwe@octave.org>
parents: 13832
diff changeset
154 if (! (ischar (msg) || iscellstr (msg)))
13822
38e3bfc4e076 provide default message for waitbar
John W. Eaton <jwe@octave.org>
parents: 13821
diff changeset
155 msg = "Please wait...";
13806
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
156 endif
13822
38e3bfc4e076 provide default message for waitbar
John W. Eaton <jwe@octave.org>
parents: 13821
diff changeset
157 title (ax, msg);
17203
efd8963f925f waitbar.m: Fix 2nd window pop-up when using gnuplot (bug #35773).
Rik <rik@octave.org>
parents: 17141
diff changeset
158
18578
02a61d7c2de0 waitbar.m: Fix regression of plots openin in waitbar window (bug #41914).
Rik <rik@octave.org>
parents: 17744
diff changeset
159 set (0, "currentfigure", cf);
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
160 endif
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
162 drawnow ();
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
164 if (nargout > 0)
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
165 h = hf;
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 endif
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167
13806
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
168 ## If there were no errors, update current waitbar.
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
169 curr_waitbar = hf;
13806
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
170
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171 endfunction
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172
26989
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
173 function updatecancelbutton (hf, ~, hax)
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21580
diff changeset
174
26989
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
175 if (! strcmp (get (hf, "__graphics_toolkit__"), "qt"))
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
176 return;
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
177 endif
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
178
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
179 hbtn = findobj (hf, "type", "uicontrol", "-and", "style", "pushbutton");
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
180 cb = get (hf, "createcancelbtn");
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
181 if (! isempty (cb))
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
182 if (isempty (hbtn))
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21385
diff changeset
183 units = get (hax, "units");
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
184 fpos = get (hf, "position");
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
185 set (hax, "units", "pixels");
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
186 apos = get (hax, "position");
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
187
26989
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
188 fpos(2) -= 40;
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
189 fpos(4) += 40;
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
190 apos(2) += 40;
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
191 set (hf, "position", fpos);
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
192 set (hax, "position", apos, "units", units);
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
193
26989
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
194 hbtn = uicontrol (hf, "style", "pushbutton", "string", "Cancel", ...
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
195 "position", [fpos(3)-100, 10, 60, 25], ...
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
196 "callback", cb);
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
197 else
21385
89fa0694aa2e Fix check-missing-semicolon QA target (bug #47277).
Rik <rik@octave.org>
parents: 20852
diff changeset
198 set (hbtn, "callback", cb);
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
199 endif
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
200 elseif (! isempty (hbtn))
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
201 delete (hbtn);
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21385
diff changeset
202 units = get (hax, "units");
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
203 fpos = get (hf, "position");
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
204 set (hax, "units", "pixels");
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
205 apos = get (hax, "position");
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
206
26989
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
207 fpos(2) += 40;
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
208 fpos(4) -= 40;
a7ad08ed3cb7 waitbar.m: Fix hang when using "createcancelbtn" property (bug #55963).
Rik <rik@octave.org>
parents: 26617
diff changeset
209 apos(2) -= 40;
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
210 set (hf, "position", fpos);
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
211 set (hax, "position", apos, "units", units);
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
212 endif
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 21580
diff changeset
213
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
214 endfunction
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
215
13817
b3e1f9ae64dc waitbar.m: More improvements.
Rik <octave@nomad.inbox5.com>
parents: 13816
diff changeset
216
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 %!demo
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
218 %! h = waitbar (0, '0.00%');
13803
a2e158c3451f provide the waitbar function
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219 %! for i = 0:0.01:1
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
220 %! waitbar (i, h, sprintf ('%.2f%%', 100*i));
26015
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
221 %! if (strcmp (graphics_toolkit (), "qt"))
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
222 %! pause (0.01);
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
223 %! endif
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 21819
diff changeset
224 %! endfor
13806
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
225 %! close (h);
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
226
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
227 %!demo
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
228 %! h = waitbar (0, 'please wait...');
13818
a05e5db7b94e have some fun with waitbar demo #2
John W. Eaton <jwe@octave.org>
parents: 13817
diff changeset
229 %! for i = 0:0.01:0.6
13817
b3e1f9ae64dc waitbar.m: More improvements.
Rik <octave@nomad.inbox5.com>
parents: 13816
diff changeset
230 %! waitbar (i);
26015
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
231 %! if (strcmp (graphics_toolkit (), "qt"))
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
232 %! pause (0.01);
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
233 %! endif
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 21819
diff changeset
234 %! endfor
14112
6e9fee72a01c Add missing ";" to line in waitbar.m demo.
Philip Nienhuis <prnienhuis@users.sf.net>
parents: 13847
diff changeset
235 %! i = 0.3;
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
236 %! waitbar (i, h, 'don''t you hate taking a step backward?');
13832
2e4252228f73 waitbar.m: Eliminate docstring reference to waitbar(frac,msg)
Rik <octave@nomad.inbox5.com>
parents: 13822
diff changeset
237 %! pause (0.5);
13818
a05e5db7b94e have some fun with waitbar demo #2
John W. Eaton <jwe@octave.org>
parents: 13817
diff changeset
238 %! for i = i:0.005:0.7
a05e5db7b94e have some fun with waitbar demo #2
John W. Eaton <jwe@octave.org>
parents: 13817
diff changeset
239 %! waitbar (i, h);
26015
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
240 %! if (strcmp (graphics_toolkit (), "qt"))
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
241 %! pause (0.01);
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
242 %! endif
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 21819
diff changeset
243 %! endfor
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
244 %! waitbar (i, h, 'or stalling?');
13832
2e4252228f73 waitbar.m: Eliminate docstring reference to waitbar(frac,msg)
Rik <octave@nomad.inbox5.com>
parents: 13822
diff changeset
245 %! pause (1);
26015
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
246 %! for i = i:0.003:0.85
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
247 %! waitbar (i, h, 'just a little longer now');
26015
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
248 %! if (strcmp (graphics_toolkit (), "qt"))
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
249 %! pause (0.01);
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
250 %! endif
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 21819
diff changeset
251 %! endfor
13818
a05e5db7b94e have some fun with waitbar demo #2
John W. Eaton <jwe@octave.org>
parents: 13817
diff changeset
252 %! for i = i:0.001:1
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
253 %! waitbar (i, h, 'please don''t be impatient');
26015
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
254 %! if (strcmp (graphics_toolkit (), "qt"))
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
255 %! pause (0.01);
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
256 %! endif
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 21819
diff changeset
257 %! endfor
13806
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
258 %! close (h);
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
259
a73c0811d2fa more updates for waitbar
John W. Eaton <jwe@octave.org>
parents: 13805
diff changeset
260 %!demo
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
261 %! h1 = waitbar (0, 'Waitbar #1');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
262 %! h2 = waitbar (0, 'Waitbar #2');
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
263 %! h2pos = get (h2, 'position');
14249
27abe77158d6 Changes to allow plot demos to be converted and run by Matlab.
Ben Abbott <bpabbott@mac.com>
parents: 14245
diff changeset
264 %! h2pos(1) = h2pos(1) + (h2pos(3) + 50);
14245
4506eade9f04 Use Matlab coding conventions for demos in plot/ directory.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
265 %! set (h2, 'position', h2pos);
13832
2e4252228f73 waitbar.m: Eliminate docstring reference to waitbar(frac,msg)
Rik <octave@nomad.inbox5.com>
parents: 13822
diff changeset
266 %! pause (0.5);
13817
b3e1f9ae64dc waitbar.m: More improvements.
Rik <octave@nomad.inbox5.com>
parents: 13816
diff changeset
267 %! for i = 1:4
b3e1f9ae64dc waitbar.m: More improvements.
Rik <octave@nomad.inbox5.com>
parents: 13816
diff changeset
268 %! waitbar (i/4, h1);
b3e1f9ae64dc waitbar.m: More improvements.
Rik <octave@nomad.inbox5.com>
parents: 13816
diff changeset
269 %! pause (0.5);
b3e1f9ae64dc waitbar.m: More improvements.
Rik <octave@nomad.inbox5.com>
parents: 13816
diff changeset
270 %! waitbar (i/4, h2);
b3e1f9ae64dc waitbar.m: More improvements.
Rik <octave@nomad.inbox5.com>
parents: 13816
diff changeset
271 %! pause (0.5);
22302
1c4cd12987f5 Use Octave syntax in graphics demos.
Rik <rik@octave.org>
parents: 21819
diff changeset
272 %! endfor
13832
2e4252228f73 waitbar.m: Eliminate docstring reference to waitbar(frac,msg)
Rik <octave@nomad.inbox5.com>
parents: 13822
diff changeset
273 %! pause (0.5);
13817
b3e1f9ae64dc waitbar.m: More improvements.
Rik <octave@nomad.inbox5.com>
parents: 13816
diff changeset
274 %! close (h1);
b3e1f9ae64dc waitbar.m: More improvements.
Rik <octave@nomad.inbox5.com>
parents: 13816
diff changeset
275 %! close (h2);
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
276
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
277 %!demo
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
278 %! clf ();
26015
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
279 %! niter = 7;
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
280 %! l = 1;
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
281 %! xx = [0 l];
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
282 %! yy = [0 0];
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
283 %! hli = plot (xx, yy);
26015
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
284 %! pos1 = get (gcf, "position");
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
285 %!
26015
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
286 %! disp ("Push the <cancel> button to stop the process.");
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
287 %! hf = waitbar (0,"0","Name","Building Koch curve ...",...
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
288 %! "createcancelbtn", "setappdata (gcbf,'interrupt', true)");
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
289 %!
26015
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
290 %! pos2 = get (hf, "position");
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
291 %! set (hf, "position", [pos1(1)+(pos1(3)-pos2(3))/2, pos1(2)+pos1(4), pos2(3:4)]);
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
292 %!
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
293 %! for ii = 1:niter
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
294 %! ## Check cancel request
24423
1d52db450db4 Change ishandle to return true for Java objects for Matlab compatibility.
Rik <rik@octave.org>
parents: 23220
diff changeset
295 %! if (! ishghandle (hf))
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21568
diff changeset
296 %! break;
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
297 %! elseif (getappdata (hf, "interrupt"))
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21568
diff changeset
298 %! delete (hf);
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21568
diff changeset
299 %! break;
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
300 %! else
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
301 %! waitbar (ii/niter, hf, sprintf ("Step %d/%d", ii, niter));
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
302 %! endif
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
303 %!
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
304 %! ## Increasingly lengthy computation
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
305 %! l /= 3;
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
306 %! theta = angle (complex (diff (xx), diff (yy)));
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
307 %!
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
308 %! xy = @(th, x0, y0) [cos(th) -sin(th) x0
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
309 %! sin(th) cos(th) y0] * [0 l l*3/2 2*l;
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
310 %! 0 0 l*(3)^.5/2 0;
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
311 %! 1 1 1 1];
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
312 %! tmp = arrayfun (xy, theta, xx(1:end-1), yy(1:end-1),
26015
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
313 %! "uniformoutput", false);
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
314 %!
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
315 %! tmp = cell2mat (tmp);
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
316 %! xx = [tmp(1,:) xx(end)];
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
317 %! yy = [tmp(2,:) yy(end)];
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21568
diff changeset
318 %! set (hli, "xdata", xx, "ydata", yy);
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
319 %! drawnow ();
26015
2e97124a71da waitbar.m: Redo %!demos to be slower with qt toolkit and display better (bug #54935).
Rik <rik@octave.org>
parents: 25054
diff changeset
320 %! pause (0.75);
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
321 %! endfor
20715
5b7643257978 Remove trailing whitespace at end of lines.
Rik <rik@octave.org>
parents: 20271
diff changeset
322 %!
24423
1d52db450db4 Change ishandle to return true for Java objects for Matlab compatibility.
Rik <rik@octave.org>
parents: 23220
diff changeset
323 %! if (ishghandle (hf))
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21568
diff changeset
324 %! delete (hf);
20271
ae68b331d6e4 waitbar.m: add support for "createcancelbtn" property (bug #45364)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 20173
diff changeset
325 %! endif
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
326
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
327 ## Test input validation
13805
b3cdef33ac0e waitbar.m: Update docstring. Only return output handle h if requested.
Rik <octave@nomad.inbox5.com>
parents: 13803
diff changeset
328 %!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
329 %!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
330 %!error <MSG must be a character string> waitbar (0.5, struct ())
17447
359366a4994f waitbar.m: Use Octave coding conventions.
Rik <rik@octave.org>
parents: 17203
diff changeset
331 %!error <invalid number of property/value pairs> waitbar (0.5, "msg", "Name")