changeset 21657:b45d53d1d638

prevent proliferation of figure windows when running demos * demo.m: If any figures are open, close all but one figure before each demo, clearing the last remaining figure.
author John W. Eaton <jwe@octave.org>
date Fri, 29 Apr 2016 16:35:41 -0400
parents 6b5f90d9a10b
children 2f9078956a63
files scripts/testfun/demo.m
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/testfun/demo.m	Fri Apr 29 15:33:56 2016 -0400
+++ b/scripts/testfun/demo.m	Fri Apr 29 16:35:41 2016 -0400
@@ -126,10 +126,12 @@
   else
     doidx = 1:(length (idx) - 1);
   endif
+  clear_figures ();
   for i = 1:length (doidx)
     ## Pause between demos
     if (i > 1)
       input ("Press <enter> to continue: ", "s");
+      clear_figures ();
     endif
 
     ## Process each demo without failing
@@ -149,6 +151,19 @@
 
 endfunction
 
+function clear_figures ()
+  ## Prevent proliferation of figure windows.  If any figure windows
+  ## exist, close all but one and clear the one remaining.
+  figs = __go_figure_handles__ ();
+  if (! isempty (figs))
+    if (numel (figs) > 1)
+      figs = sort (figs);
+      figs(1) = [];
+      close (figs);
+    endif
+    clf ("reset");
+  endif
+endfunction
 
 %!demo
 %! t = 0:0.01:2*pi;