Mercurial > hg > octave-nkf
comparison scripts/plot/close.m @ 17093:e5ded64def41
close.m: Fix close to remove hidden figures with "all hidden" argument.
* scripts/plot/close.m: Use allchild to get list off all hidden figures
from root window.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 25 Jul 2013 16:17:06 -0700 |
parents | 5d3a684236b0 |
children | eaab03308c0b |
comparison
equal
deleted
inserted
replaced
17092:498b9f62199a | 17093:e5ded64def41 |
---|---|
16 ## along with Octave; see the file COPYING. If not, see | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Command} {} close | 20 ## @deftypefn {Command} {} close |
21 ## @deftypefnx {Command} {} close (@var{n}) | 21 ## @deftypefnx {Command} {} close (@var{h}) |
22 ## @deftypefnx {Command} {} close all | 22 ## @deftypefnx {Command} {} close all |
23 ## @deftypefnx {Command} {} close all hidden | 23 ## @deftypefnx {Command} {} close all hidden |
24 ## Close figure window(s) by calling the function specified by the | 24 ## Close figure window(s). |
25 ## @code{"closerequestfcn"} property for each figure. By default, the | 25 ## |
26 ## function @code{closereq} is used. | 26 ## @code{close} operates by calling the function specified by the |
27 ## @seealso{closereq} | 27 ## @code{"closerequestfcn"} property for each figure. By default, the function |
28 ## @code{closereq} is used. | |
29 ## | |
30 ## When called with no arguments, close the current figure. This is equivalent | |
31 ## to @code{close (gcf)}. If the input is a graphic handle @var{h} or vector | |
32 ## of graphics handles then close each figure in @var{h}. | |
33 ## | |
34 ## If the argument "all" is given then all figures with visible handles | |
35 ## (HandleVisibility = "on") are closed. | |
36 ## | |
37 ## If the argument "all hidden" is given then all figures, including hidden | |
38 ## ones, are closed. | |
39 ## | |
40 ## Implementation Note: @code{close} calls a function to dispose of the figure. | |
41 ## It is possible that the function will delay or abort removing the figure. | |
42 ## To remove a figure without calling any callback functions use @code{delete}. | |
43 ## | |
44 ## @seealso{closereq, delete} | |
28 ## @end deftypefn | 45 ## @end deftypefn |
29 | 46 |
30 ## Author: jwe | 47 ## Author: jwe |
31 ## 2010-05-02 PBig allow empty argument | 48 ## 2010-05-02 PBig allow empty argument |
32 | 49 |
33 function retval = close (arg1, arg2) | 50 function retval = close (arg1, arg2) |
34 | 51 |
35 figs = []; | 52 figs = []; |
36 | 53 |
37 if (nargin == 0) | 54 if (nargin > 2) |
38 ## Close current figure. Don't use gcf because that will open a new | 55 print_usage (); |
39 ## plot window if one doesn't exist. | 56 elseif (nargin == 0) |
57 ## Close current figure. | |
58 ## Can't use gcf because it opens a new plot window if one does not exist. | |
40 figs = get (0, "currentfigure"); | 59 figs = get (0, "currentfigure"); |
41 if (! isempty (figs) && figs == 0) | 60 if (figs == 0) # don't close root figure |
42 figs = []; | 61 figs = []; |
43 endif | 62 endif |
44 elseif (nargin == 1) | 63 elseif (nargin == 1) |
45 if (ischar (arg1) && strcmpi (arg1, "all")) | 64 if (ischar (arg1) && strcmpi (arg1, "all")) |
46 close_all_figures (false); | 65 figs = (get (0, "children"))'; |
66 figs = figs(isfigure (figs)); | |
47 elseif (isfigure (arg1)) | 67 elseif (isfigure (arg1)) |
48 figs = arg1; | 68 figs = arg1; |
49 elseif (isempty (arg1)) | 69 elseif (isempty (arg1)) |
50 figs = []; | 70 figs = []; |
51 else | 71 else |
52 error ("close: expecting argument to be \"all\" or a figure handle"); | 72 error ('close: expecting argument to be "all" or a figure handle'); |
53 endif | 73 endif |
54 elseif (nargin == 2 | 74 elseif ( ischar (arg1) && strcmpi (arg1, "all") |
55 && ischar (arg1) && strcmpi (arg1, "all") | |
56 && ischar (arg2) && strcmpi (arg2, "hidden")) | 75 && ischar (arg2) && strcmpi (arg2, "hidden")) |
57 close_all_figures (true); | 76 figs = (allchild (0))'; |
58 else | 77 figs = figs(isfigure (figs)); |
59 print_usage (); | |
60 endif | 78 endif |
61 | 79 |
62 for h = figs | 80 for h = figs |
63 __go_execute_callback__ (h, "closerequestfcn"); | 81 __go_execute_callback__ (h, "closerequestfcn"); |
64 endfor | 82 endfor |
65 | 83 |
66 if (nargout > 0) | 84 if (nargout > 0) |
67 retval = 1; | 85 retval = 1; |
68 endif | 86 endif |
69 | |
70 endfunction | |
71 | |
72 function close_all_figures (close_hidden_figs) | |
73 | |
74 while (! isempty (fig = get (0, "currentfigure"))) | |
75 ## handlevisibility = get (fig, "handlevisibility") | |
76 ## if (close_hidden_figs || ! strcmpi (handlevisibility, "off")) | |
77 close (fig); | |
78 ## endif | |
79 endwhile | |
80 | 87 |
81 endfunction | 88 endfunction |
82 | 89 |
83 | 90 |
84 %!test | 91 %!test |