Mercurial > hg > octave-lyh
view scripts/plot/waitbar.m @ 17126:eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Emphasize clarity, use common "voice", and increase density of seealso links.
* doc/interpreter/plot.txi: Add @findex entries that were in xlim.m
* scripts/miscellaneous/getappdata.m scripts/miscellaneous/setappdata.m,
scripts/plot/allchild.m, scripts/plot/ancestor.m, scripts/plot/area.m,
scripts/plot/axes.m, scripts/plot/axis.m, scripts/plot/bar.m,
scripts/plot/barh.m, scripts/plot/box.m, scripts/plot/caxis.m,
scripts/plot/cla.m, scripts/plot/clabel.m, scripts/plot/clf.m,
scripts/plot/close.m, scripts/plot/closereq.m, scripts/plot/colorbar.m,
scripts/plot/comet.m, scripts/plot/comet3.m, scripts/plot/compass.m,
scripts/plot/contour.m, scripts/plot/contour3.m, scripts/plot/contourc.m,
scripts/plot/contourf.m, scripts/plot/copyobj.m, scripts/plot/cylinder.m,
scripts/plot/daspect.m, scripts/plot/diffuse.m, scripts/plot/ellipsoid.m,
scripts/plot/errorbar.m, scripts/plot/ezcontour.m, scripts/plot/ezcontourf.m,
scripts/plot/ezmesh.m, scripts/plot/ezmeshc.m, scripts/plot/ezplot.m,
scripts/plot/ezplot3.m, scripts/plot/ezpolar.m, scripts/plot/ezsurf.m,
scripts/plot/ezsurfc.m, scripts/plot/feather.m, scripts/plot/figure.m,
scripts/plot/fill.m, scripts/plot/findall.m, scripts/plot/findobj.m,
scripts/plot/fplot.m, scripts/plot/gca.m, scripts/plot/gcbf.m,
scripts/plot/gcbo.m, scripts/plot/gcf.m, scripts/plot/gco.m,
scripts/plot/ginput.m, scripts/plot/graphics_toolkit.m, scripts/plot/grid.m,
scripts/plot/gtext.m, scripts/plot/guidata.m, scripts/plot/guihandles.m,
scripts/plot/hdl2struct.m, scripts/plot/hggroup.m, scripts/plot/hidden.m,
scripts/plot/hist.m, scripts/plot/hold.m, scripts/plot/ishghandle.m,
scripts/plot/ishold.m, scripts/plot/isocolors.m, scripts/plot/isprop.m,
scripts/plot/legend.m, scripts/plot/line.m, scripts/plot/linkprop.m,
scripts/plot/loglog.m, scripts/plot/loglogerr.m, scripts/plot/mesh.m,
scripts/plot/meshc.m, scripts/plot/meshgrid.m, scripts/plot/meshz.m,
scripts/plot/newplot.m, scripts/plot/orient.m, scripts/plot/pareto.m,
scripts/plot/patch.m, scripts/plot/pcolor.m, scripts/plot/peaks.m,
scripts/plot/pie.m, scripts/plot/pie3.m, scripts/plot/plot.m,
scripts/plot/plot3.m, scripts/plot/plotmatrix.m, scripts/plot/plotyy.m,
scripts/plot/polar.m, scripts/plot/print.m, scripts/plot/quiver.m,
scripts/plot/quiver3.m, scripts/plot/rectangle.m, scripts/plot/refresh.m,
scripts/plot/refreshdata.m, scripts/plot/ribbon.m, scripts/plot/rose.m,
scripts/plot/saveas.m, scripts/plot/scatter.m, scripts/plot/scatter3.m,
scripts/plot/semilogx.m, scripts/plot/semilogxerr.m, scripts/plot/semilogy.m,
scripts/plot/semilogyerr.m, scripts/plot/shading.m, scripts/plot/shg.m,
scripts/plot/shrinkfaces.m, scripts/plot/slice.m, scripts/plot/specular.m,
scripts/plot/sphere.m, scripts/plot/stairs.m, scripts/plot/stem.m,
scripts/plot/stem3.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m,
scripts/plot/surf.m, scripts/plot/surface.m, scripts/plot/surfc.m,
scripts/plot/surfl.m, scripts/plot/tetramesh.m, scripts/plot/text.m,
scripts/plot/title.m, scripts/plot/trimesh.m, scripts/plot/triplot.m,
scripts/plot/trisurf.m, scripts/plot/view.m, scripts/plot/waitbar.m,
scripts/plot/waitforbuttonpress.m, scripts/plot/waterfall.m,
scripts/plot/whitebg.m, scripts/plot/xlabel.m, scripts/plot/xlim.m,
scripts/plot/ylabel.m, scripts/plot/ylim.m, scripts/plot/zlabel.m,
scripts/plot/zlim.m: Rewrite docstrings for most plot functions.
Emphasize clarity, use common "voice", and increase density of seealso links.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 31 Jul 2013 13:53:30 -0700 |
parents | 7a7ce92cff56 |
children | 13da13e1e17f |
line wrap: on
line source
## Copyright (C) 2012 John W. Eaton ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 3 of the License, or (at ## your option) any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, see ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- ## @deftypefn {Function File} {@var{h} =} waitbar (@var{frac}) ## @deftypefnx {Function File} {@var{h} =} waitbar (@var{frac}, @var{msg}) ## @deftypefnx {Function File} {@var{h} =} waitbar (@dots{}, "FigureProperty", "Value", @dots{}) ## @deftypefnx {Function File} {} waitbar (@var{frac}) ## @deftypefnx {Function File} {} waitbar (@var{frac}, @var{hwbar}) ## @deftypefnx {Function File} {} waitbar (@var{frac}, @var{hwbar}, @var{msg}) ## Return a handle @var{h} to a new waitbar object. ## ## The waitbar is filled to fraction @var{frac} which must be in the range ## [0, 1]. The optional message @var{msg} is centered and displayed above the ## waitbar. The appearance of the waitbar figure window can be configured by ## passing property/value pairs to the function. ## ## When called with a single input the current waitbar, if it exists, is ## updated to the new value @var{frac}. If there are multiple outstanding ## waitbars they can be updated individually by passing the handle @var{hwbar} ## of the specific waitbar to modify. ## @end deftypefn ## Author: jwe function retval = waitbar (varargin) persistent curr_waitbar; if (nargin < 1) print_usage (); endif frac = varargin{1}; varargin(1) = []; if (! (isnumeric (frac) && isscalar (frac) && frac >= 0 && frac <= 1)) error ("waitbar: FRAC must be between 0 and 1"); endif ## Use existing waitbar if it still points to a valid graphics handle. if (nargin == 1 && ishandle (curr_waitbar)) h = curr_waitbar; else h = false; endif if (! isempty (varargin) && isnumeric (varargin{1})) if (! ishandle (varargin{1})) error ("waitbar: H must be a handle to a waitbar object"); else h = varargin{1}; varargin(1) = []; if (! isfigure (h) || ! strcmp (get (h, "tag"), "waitbar")) error ("waitbar: H must be a handle to a waitbar object"); endif endif endif msg = false; if (! isempty (varargin)) msg = varargin{1}; varargin(1) = []; if (! (ischar (msg) || iscellstr (msg))) error ("waitbar: MSG must be a character string or cell array of strings"); endif endif if (rem (numel (varargin), 2) != 0) error ("waitbar: invalid number of property-value pairs"); endif if (h) p = findobj (h, "type", "patch"); set (p, "xdata", [0; frac; frac; 0]); ax = findobj (h, "type", "axes"); if (ischar (msg) || iscellstr (msg)) th = get (ax, "title"); curr_msg = get (th, "string"); ## graphics handles always store data as column vectors if (iscellstr (msg)) msg = msg(:); endif cmp = strcmp (msg, curr_msg); if (! all (cmp(:))) set (th, "string", msg); endif endif else h = __go_figure__ (NaN, "position", [250, 500, 400, 100], "numbertitle", "off", "toolbar", "none", "menubar", "none", "integerhandle", "off", "handlevisibility", "callback", "tag", "waitbar", varargin{:}); ax = axes ("parent", h, "xtick", [], "ytick", [], "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) || iscellstr (msg))) msg = "Please wait..."; endif 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)); %! end %! close (h); %!demo %! h = waitbar (0, 'please wait...'); %! for i = 0:0.01:0.6 %! waitbar (i); %! end %! i = 0.3; %! waitbar (i, h, 'don''t you hate taking a step backward?'); %! pause (0.5); %! for i = i:0.005:0.7 %! waitbar (i, h); %! end %! waitbar (i, h, 'or stalling?'); %! pause (1); %! for i = i:0.003:0.8 %! waitbar (i, h, 'just a little longer now'); %! end %! for i = i:0.001:1 %! waitbar (i, h, 'please don''t be impatient'); %! end %! close (h); %!demo %! h1 = waitbar (0, 'Waitbar #1'); %! h2 = waitbar (0, 'Waitbar #2'); %! h2pos = get (h2, 'position'); %! h2pos(1) = h2pos(1) + (h2pos(3) + 50); %! set (h2, 'position', h2pos); %! pause (0.5); %! for i = 1:4 %! waitbar (i/4, h1); %! pause (0.5); %! waitbar (i/4, h2); %! pause (0.5); %! end %! pause (0.5); %! close (h1); %! close (h2); %% Test input validation %!error <FRAC must be between 0 and 1> waitbar (-0.5) %!error <FRAC must be between 0 and 1> waitbar (1.5) %!error <MSG must be a character string> waitbar (0.5, struct ()) %!error <invalid number of property-value pairs> waitbar (0.5, "msg", "Name")