# HG changeset patch # User John W. Eaton # Date 1320346234 14400 # Node ID a73c0811d2fad56a24c569cb079b0fb75c73814a # Parent b3cdef33ac0e469909736bce1711b73f4c82932c more updates for waitbar * waitbar.m: Keep track of current waitbar. Update patch and title objects instead of replacing them. New demos. diff -r b3cdef33ac0e -r a73c0811d2fa scripts/plot/waitbar.m --- a/scripts/plot/waitbar.m Thu Nov 03 09:54:57 2011 -0700 +++ b/scripts/plot/waitbar.m Thu Nov 03 14:50:34 2011 -0400 @@ -35,6 +35,8 @@ function retval = waitbar (varargin) + persistent curr_waitbar; + if (nargin < 1) print_usage (); endif @@ -47,7 +49,12 @@ endif msg = false; - h = 0; + + if (isempty (varargin) && ! isempty (curr_waitbar)) + h = curr_waitbar; + else + h = false; + endif if (! isempty (varargin) && ishandle (varargin{1})) h = varargin{1}; @@ -72,13 +79,19 @@ if (h) p = findobj (h, "type", "patch"); - if (p) - delete (p); + set (p, "xdata", [0; frac; frac; 0]); + ax = findobj (h, "type", "axes"); + if (ischar (msg)) + th = get (ax, "title"); + curr_msg = get (th, "string"); + if (! strcmp (msg, curr_msg)) + set (th, "string", msg); + endif endif - ax = findobj (h, "type", "axes"); else h = __go_figure__ (Inf, "position", [250, 500, 400, 100], "numbertitle", "off", + "toolbar", "none", "menubar", "none", "handlevisibility", "callback", varargin{:}); @@ -86,26 +99,44 @@ "xlim", [0, 1], "ylim", [0, 1], "xlimmode", "manual", "ylimmode", "manual", "position", [0.1, 0.3, 0.8, 0.2]); + patch (ax, [0; frac; frac; 0], [0; 0; 1; 1], [0, 0.35, 0.75]); + + if (ischar (msg)) + title (ax, msg); + endif endif - patch (ax, [0, frac, frac, 0], [0, 0, 1, 1], [0, 0.35, 0.75]); - if (ischar (msg)) - title (ax, msg); - endif drawnow (); if (nargout > 0) retval = h; endif + ## If there were no errors, update current waitbar. + curr_waitbar = h; + endfunction - %!demo %! h = waitbar (0, "0.00%"); %! for i = 0:0.01:1 %! waitbar (i, h, sprintf ("%.2f%%", 100*i)); %! endfor +%! close (h); + +%!demo +%! h = waitbar (0, "please wait..."); +%! for i = 0:0.01:1 +%! waitbar (i, h); +%! endfor +%! close (h); + +%!demo +%! h = waitbar (0, "please don't be impatient..."); +%! for i = 0:0.01:1 +%! waitbar (i); +%! endfor +%! close (h); %% Test input validation %!error waitbar (-0.5)