diff scripts/plot/drawnow.m @ 6298:4553ff6b7ec7

[project @ 2007-02-10 16:33:33 by jwe]
author jwe
date Sat, 10 Feb 2007 16:33:33 +0000
parents e8c4edcfe43d
children b298a4c12fc3
line wrap: on
line diff
--- a/scripts/plot/drawnow.m
+++ b/scripts/plot/drawnow.m
@@ -26,6 +26,13 @@
 
 function drawnow (term, file)
 
+  ## Use this instead of persistent and mlock so that drawnow can be
+  ## replaced.
+  global __uiobject_close_all_registered__;
+  if (isempty (__uiobject_close_all_registered__))
+    __lock_global__ ("__uiobject_close_all_registered__");
+  endif
+
   ## Use this instead of calling gcf to avoid creating a figure.
 
   h = get (0, "currentfigure");
@@ -42,11 +49,15 @@
         cmd = sprintf ("%s -title \"Figure %d\"", cmd, h);
       endif
       plot_stream = popen (cmd, "w");
+      if (isempty (__uiobject_close_all_registered__))
+	atexit ("__uiobject_close_all__");
+	__uiobject_close_all_registered__ = true;
+      endif
       if (plot_stream < 0)
 	error ("drawnow: failed to open connection to gnuplot");
       else
 	set (h, "__plot_stream__", plot_stream);
-	if (isempty (getenv ("DISPLAY")))
+	if (isunix () && isempty (getenv ("DISPLAY")))
 	  fprintf (plot_stream, "set terminal dumb\n;");
 	endif
       endif
@@ -74,5 +85,4 @@
 
   endif
 
-
 endfunction