Mercurial > hg > octave-lyh
changeset 17096:255d9e7aa494
Merge with official daily
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Sat, 27 Jul 2013 00:39:14 +0800 |
parents | a5aa4ac7d6b6 (current diff) 60228ef13f20 (diff) |
children | ba7725c82ed2 |
files | |
diffstat | 3 files changed, 100 insertions(+), 66 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/plot/clf.m +++ b/scripts/plot/clf.m @@ -17,16 +17,23 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {} clf () -## @deftypefnx {Function File} {} clf ("reset") +## @deftypefn {Function File} {} clf +## @deftypefnx {Function File} {} clf reset ## @deftypefnx {Function File} {} clf (@var{hfig}) ## @deftypefnx {Function File} {} clf (@var{hfig}, "reset") ## @deftypefnx {Function File} {@var{h} =} clf (@dots{}) -## Clear the current figure window. @code{clf} operates by deleting child -## graphics objects with visible handles (@code{handlevisibility} = on). -## If @var{hfig} is specified operate on it instead of the current figure. -## If the optional argument @code{"reset"} is specified, all objects including -## those with hidden handles are deleted. +## Clear the current figure window. +## +## @code{clf} operates by deleting child graphics objects with visible +## handles (HandleVisibility = "on"). +## +## If the optional argument "reset" is specified, delete all child objects +## including those with hidden handles and reset all figure properties to +## their defaults. However, the following properties are not reset: +## Position, Units, PaperPosition, PaperUnits. +## +## If the first argument @var{hfig} is a figure handle, then operate on +## this figure rather than the current figure returned by @code{gcf}. ## ## The optional return value @var{h} is the graphics handle of the figure ## window that was cleared. @@ -35,51 +42,44 @@ ## Author: jwe -function retval = clf (varargin) +function h = clf (varargin) if (nargin > 2) print_usage (); - elseif (nargin > 1) - if (isfigure (varargin{1}) && ischar (varargin{2}) - && strcmpi (varargin{2}, "reset")) - oldfig = gcf; + elseif (nargin == 0) + hfig = gcf; + do_reset = false; + elseif (nargin == 1) + if (isscalar (varargin{1}) && isfigure (varargin{1})) + hfig = varargin{1}; + do_reset = false; + elseif (ischar (varargin{1}) && strcmpi (varargin{1}, "reset")) + hfig = gcf; + do_reset = true; + else + print_usage (); + endif + else + if (isscalar (varargin{1}) && isfigure (varargin{1}) + && ischar (varargin{2}) && strcmpi (varargin{2}, "reset")) hfig = varargin{1}; do_reset = true; else print_usage (); endif - elseif (nargin == 1) - if (isfigure (varargin{1})) - oldfig = gcf; - hfig = varargin{1}; - do_reset = false; - elseif (ischar (varargin{1}) && strcmpi (varargin{1}, "reset")) - hfig = gcf; - oldfig = hfig; - do_reset = true; - else - print_usage (); - endif - else - hfig = gcf; - oldfig = hfig; - do_reset = false; endif if (do_reset) ## Select all the children, including the one with hidden handles. - hc = allchild (hfig); + delete (allchild (hfig)); reset (hfig); else ## Select only the chilren with visible handles. - hc = get (hfig, "children"); + delete (get (hfig, "children")); endif - ## Delete the children. - delete (hc); - if (nargout > 0) - retval = hfig; + h = hfig; endif endfunction @@ -90,6 +90,8 @@ %! unwind_protect %! l = line; %! assert (! isempty (get (gcf, "children"))); +%! clf; +%! assert (isempty (get (gcf, "children"))); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect @@ -103,3 +105,20 @@ %! close (hf); %! end_unwind_protect +%!xtest +%! hf = figure ("visible", "off"); +%! unwind_protect +%! plot (1:10); +%! set (hf, "papertype", "tabloid"); +%! clf (hf); +%! assert (isempty (get (gcf, "children"))); +%! assert (get (hf, "papertype"), "tabloid"); +%! plot (1:10); +%! clf (hf, "reset"); +%! kids = get (hf, "children"); +%! assert (isempty (get (gcf, "children"))); +%! assert (get (hf, "papertype"), "usletter"); +%! unwind_protect_cleanup +%! close (hf); +%! end_unwind_protect +
--- a/scripts/plot/close.m +++ b/scripts/plot/close.m @@ -18,13 +18,30 @@ ## -*- texinfo -*- ## @deftypefn {Command} {} close -## @deftypefnx {Command} {} close (@var{n}) +## @deftypefnx {Command} {} close (@var{h}) ## @deftypefnx {Command} {} close all ## @deftypefnx {Command} {} close all hidden -## Close figure window(s) by calling the function specified by the -## @code{"closerequestfcn"} property for each figure. By default, the -## function @code{closereq} is used. -## @seealso{closereq} +## Close figure window(s). +## +## @code{close} operates by calling the function specified by the +## @code{"closerequestfcn"} property for each figure. By default, the function +## @code{closereq} is used. +## +## When called with no arguments, close the current figure. This is equivalent +## to @code{close (gcf)}. If the input is a graphic handle @var{h} or vector +## of graphics handles then close each figure in @var{h}. +## +## If the argument "all" is given then all figures with visible handles +## (HandleVisibility = "on") are closed. +## +## If the argument "all hidden" is given then all figures, including hidden +## ones, are closed. +## +## Implementation Note: @code{close} calls a function to dispose of the figure. +## It is possible that the function will delay or abort removing the figure. +## To remove a figure without calling any callback functions use @code{delete}. +## +## @seealso{closereq, delete} ## @end deftypefn ## Author: jwe @@ -34,29 +51,30 @@ figs = []; - if (nargin == 0) - ## Close current figure. Don't use gcf because that will open a new - ## plot window if one doesn't exist. + if (nargin > 2) + print_usage (); + elseif (nargin == 0) + ## Close current figure. + ## Can't use gcf because it opens a new plot window if one does not exist. figs = get (0, "currentfigure"); - if (! isempty (figs) && figs == 0) + if (figs == 0) # don't close root figure figs = []; endif elseif (nargin == 1) if (ischar (arg1) && strcmpi (arg1, "all")) - close_all_figures (false); + figs = (get (0, "children"))'; + figs = figs(isfigure (figs)); elseif (isfigure (arg1)) figs = arg1; elseif (isempty (arg1)) figs = []; else - error ("close: expecting argument to be \"all\" or a figure handle"); + error ('close: expecting argument to be "all" or a figure handle'); endif - elseif (nargin == 2 - && ischar (arg1) && strcmpi (arg1, "all") + elseif ( ischar (arg1) && strcmpi (arg1, "all") && ischar (arg2) && strcmpi (arg2, "hidden")) - close_all_figures (true); - else - print_usage (); + figs = (allchild (0))'; + figs = figs(isfigure (figs)); endif for h = figs @@ -69,17 +87,6 @@ endfunction -function close_all_figures (close_hidden_figs) - - while (! isempty (fig = get (0, "currentfigure"))) - ## handlevisibility = get (fig, "handlevisibility") - ## if (close_hidden_figs || ! strcmpi (handlevisibility, "off")) - close (fig); - ## endif - endwhile - -endfunction - %!test %! hf = figure ("visible", "off");
--- a/scripts/plot/isfigure.m +++ b/scripts/plot/isfigure.m @@ -18,8 +18,11 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} isfigure (@var{h}) -## Return true if @var{h} is a graphics handle that contains a figure -## object. +## Return true if @var{h} is a figure graphics handle and false otherwise. +## +## If @var{h} is a matrix then return a logical array which is true where +## the elements of @var{h} are figure graphics handles and false where +## they are not. ## @seealso{ishandle} ## @end deftypefn @@ -27,10 +30,15 @@ function retval = isfigure (h) - if (nargin == 1) - retval = (ishandle (h) && strcmp (get (h, "type"), "figure")); + if (nargin != 1) + print_usage (); + endif + + hlist = ishandle (h); + if (any (hlist)) + retval(hlist) = strcmp (get (h(hlist), "type"), "figure"); else - print_usage (); + retval = hlist; endif endfunction