From: Fernando P. <Fer...@co...> - 2005-01-31 22:25:48
|
Hi all, we've just run into a nasty problem with the TkAgg backend if close('all') is called. In our setup, we use ipython+pylab with TkAgg because we also need MayaVi to be active, and the GTK/WX backends block Tk windows. But if a call is made to close('all'), matplotlib closes not only all of its own windows, but also it destroys the MayaVi window in some very nasty way. The VTK wrapper complains loudly about improper deletions, and afterwards running any mayavi code is impossible (Tcl/Tk errors come from inside python itself). The problem is that matplotlib should not be touching any windows that don't belong to it. I quickly wrote the following wrapper code to use here to work around this bug: try: mm.all_figures except AttributeError: mm.all_figures = [] def figure(num=1): """Wrapper around mm.figure which updates a global list of held figures.""" mm.figure(num) mm.all_figures.append(num) def close_all(): """Close all open figures managed by our figure() wrapper.""" print 'Closing figures:',mm.all_figures map(mm.close,mm.all_figures) mm.all_figures = [] but it would be nice to see the TkAgg backend do the right thing. I should also mention that when I first wrote my wrapper code, I used in figure() the following: mm.all_figures.append(mm.figure(num)) to append the actual figure handles. This didn't work because the close() call to a handle seems to be also broken. I worked around this other bug by using figure numbers instead of handles. While we're at it, I think it would be nice to extend the close() syntax to allow a sequence of integers or figure handles to be passed to it, so that one could simply say close([1,3,5,21,101]) to only close those windows, or the same with their respective figure handles (nicely stored by ipython in the _NN variables). Regards, f |