bug in CVS gtk-agg? doesn't return from gtk.main() when window is closed

John,

I updated from CVS, made a one-line change to contour.py to add alpha support, and tested using contour_demo.py from bash shell--and found that with linux default gtk-agg backend, the gtk.main() doesn't return when the plot window is closed. I have to Ctl-C to get out.

Eric

Eric Firing wrote:

John,

I updated from CVS, made a one-line change to contour.py to add alpha support, and tested using contour_demo.py from bash shell--and found that with linux default gtk-agg backend, the gtk.main() doesn't return when the plot window is closed. I have to Ctl-C to get out.

Eric

John,

The following patch fixes the problem for me, and makes sense to me:

Index: backend_gtk.py

ยทยทยท

===================================================================
RCS file: /cvsroot/matplotlib/matplotlib/lib/matplotlib/backends/backend_gtk.py,v
retrieving revision 1.123
diff -u -r1.123 backend_gtk.py
--- backend_gtk.py 24 Feb 2006 20:00:28 -0000 1.123
+++ backend_gtk.py 26 Feb 2006 02:30:42 -0000
@@ -76,8 +76,8 @@
          manager.window.show()

      if mainloop and gtk.main_level() == 0:
- gtk.main()
          show._mainloop = True
+ gtk.main()
  show._mainloop = False

  def new_figure_manager(num, *args, **kwargs):

You have show._mainloop = True after the call to gtk.main(), but that doesn't return; when the windows are deleted, the mainloop is still running but the flag has not been set, so deleting the last window does not end the loop. So the obvious solution (above) is to set the flag before calling gtk.main()

I was about to simply make the change, but decided to leave it to you, since I don't understand the bug you were trying to fix in the first place. Maybe some sort of locking is actually needed to make sure nothing unexpected can happen in another thread between the setting of the flag and the call to gtk.main().

Eric