On Fri, Jul 18, 2008 at 07:36:03AM +0200, Gael Varoquaux wrote:
> On Thu, Jul 17, 2008 at 08:55:59AM -0500, John Hunter wrote:
> > I think we could do a 0.98.3 release.
> I am right now implementing a wx frontend to ipython, and I can see in
> the near future a score of people complaining that "from pylab import *;
> show()" crashes it because it calls the wrong backend. Do people mind if
> I prepare a patch that does some magic as pylab is loaded to:
> a) Look if 'wx' is in sys.module
> b) Check if the wx mainloop is running,
> and if so changes the backend automatically to wx and wxAgg.
OK, no replies tonight, so I went ahead and coded a patch, in the
interest of getting this in before the next release. It is attached.
Comments are welcome.
Gaƫl
Index: trunk/matplotlib/lib/matplotlib/pyplot.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/pyplot.py (revision 5785)
+++ trunk/matplotlib/lib/matplotlib/pyplot.py (working copy)
@@ -32,7 +32,22 @@
MaxNLocator
+## Backend detection ##
+# If the wx Mainloop is started, starting another mainloop will crash
+# python, so we need to change to wx backend
+import sys
+if 'wx' in sys.modules:
+ import wx
+ if wx.App.IsMainLoopRunning():
+ from matplotlib import rcParams, use
+ if rcParams['backend'].endswith('Agg'):
+ use('wxAgg')
+ else:
+ use('wx')
+
+
+
## Global ##
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel