On Fri, Mar 6, 2009 at 22:24, Sandro Tosi <mo...@debian.org> wrote:
> On Fri, Mar 6, 2009 at 22:12, Sandro Tosi <mo...@debian.org> wrote:
>>>>> import wxversion
>>>>> wxversion.select('2.8')
>>>>> from wx import *
>>>>> wx.__version__
>> '2.8.7.1'
>>
>> That solves the problem of multi-wx on a system.
>>
>> What do you think about adding those 2 line into wx examples?
>
> Moreover, I will provide a patch to move from

Here it is the promised patch (sorry for the late, that proves how
busy I am these days).

It uses the 'wxversion.ensureMinimal' function as Chris pointed out,
and move from "from wx import *" to "import wx".

I tested them on a sys (Debian sid) with both wx2.6 and wx2.8: before
the patch the examples goes in abort, after they select wx2.8 and uses
it displaying the windows (even though ex2 and 3 seems a little "too
compress" do not know if it's due to code or patch ;) ).

HTH, cheers,
-- 
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi
Index: examples/user_interfaces/embedding_in_wx2.py
===================================================================
--- examples/user_interfaces/embedding_in_wx2.py	(revision 6971)
+++ examples/user_interfaces/embedding_in_wx2.py	(working copy)
@@ -4,6 +4,10 @@
 toolbar - comment out the setA_toolbar line for no toolbar
 """
 
+# Used to guarantee to use at least Wx2.8
+import wxversion
+wxversion.ensureMinimal('2.8')
+
 from numpy import arange, sin, pi
 
 import matplotlib
@@ -20,15 +24,15 @@
 
 from matplotlib.figure import Figure
 
-from wx import *
+import wx
 
-class CanvasFrame(Frame):
+class CanvasFrame(wx.Frame):
 
     def __init__(self):
-        Frame.__init__(self,None,-1,
+        wx.Frame.__init__(self,None,-1,
                          'CanvasFrame',size=(550,350))
 
-        self.SetBackgroundColour(NamedColor("WHITE"))
+        self.SetBackgroundColour(wx.NamedColor("WHITE"))
 
         self.figure = Figure()
         self.axes = self.figure.add_subplot(111)
@@ -38,8 +42,8 @@
         self.axes.plot(t,s)
         self.canvas = FigureCanvas(self, -1, self.figure)
 
-        self.sizer = BoxSizer(VERTICAL)
-        self.sizer.Add(self.canvas, 1, LEFT | TOP | GROW)
+        self.sizer = wx.BoxSizer(wx.VERTICAL)
+        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
         self.SetSizer(self.sizer)
         self.Fit()
 
@@ -49,7 +53,7 @@
     def add_toolbar(self):
         self.toolbar = NavigationToolbar2Wx(self.canvas)
         self.toolbar.Realize()
-        if Platform == '__WXMAC__':
+        if wx.Platform == '__WXMAC__':
             # Mac platform (OSX 10.3, MacPython) does not seem to cope with
             # having a toolbar in a sizer. This work-around gets the buttons
             # back, but at the expense of having the toolbar at the top
@@ -62,8 +66,8 @@
             # By adding toolbar in sizer, we are able to put it at the bottom
             # of the frame - so appearance is closer to GTK version.
             # As noted above, doesn't work for Mac.
-            self.toolbar.SetSize(Size(fw, th))
-            self.sizer.Add(self.toolbar, 0, LEFT | EXPAND)
+            self.toolbar.SetSize(wx.Size(fw, th))
+            self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
         # update the axes menu on the toolbar
         self.toolbar.update()
 
@@ -71,7 +75,7 @@
     def OnPaint(self, event):
         self.canvas.draw()
 
-class App(App):
+class App(wx.App):
 
     def OnInit(self):
         'Create the main window and insert the custom frame'
Index: examples/user_interfaces/embedding_in_wx3.py
===================================================================
--- examples/user_interfaces/embedding_in_wx3.py	(revision 6971)
+++ examples/user_interfaces/embedding_in_wx3.py	(working copy)
@@ -18,6 +18,11 @@
 Thanks to matplotlib and wx teams for creating such great software!
 
 """
+
+# Used to guarantee to use at least Wx2.8
+import wxversion
+wxversion.ensureMinimal('2.8')
+
 import sys, time, os, gc
 import matplotlib
 matplotlib.use('WXAgg')
@@ -26,18 +31,18 @@
 from matplotlib.figure import Figure
 import numpy as npy
 
-from wx import *
-from wx.xrc import *
+import wx
+import wx.xrc as xrc
 
 ERR_TOL = 1e-5 # floating point slop for peak-detection
 
 
 matplotlib.rc('image', origin='lower')
 
-class PlotPanel(Panel):
+class PlotPanel(wx.Panel):
 
     def __init__(self, parent):
-        Panel.__init__(self, parent, -1)
+        wx.Panel.__init__(self, parent, -1)
 
         self.fig = Figure((5,4), 75)
         self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
@@ -46,11 +51,11 @@
         #self.toolbar.set_active([0,1])
 
         # Now put all into a sizer
-        sizer = BoxSizer(VERTICAL)
+        sizer = wx.BoxSizer(wx.VERTICAL)
         # This way of adding to sizer allows resizing
-        sizer.Add(self.canvas, 1, LEFT|TOP|GROW)
+        sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
         # Best to allow the toolbar to resize!
-        sizer.Add(self.toolbar, 0, GROW)
+        sizer.Add(self.toolbar, 0, wx.GROW)
         self.SetSizer(sizer)
         self.Fit()
 
@@ -94,43 +99,43 @@
         # this is supposed to prevent redraw flicker on some X servers...
         pass
 
-class MyApp(App):
+class MyApp(wx.App):
     def OnInit(self):
         xrcfile = os.path.join(os.path.dirname(__file__),"..","data",
                                "embedding_in_wx3.xrc")      
-        self.res = XmlResource(xrcfile)
+        self.res = xrc.XmlResource(xrcfile)
 
         # main frame and panel ---------
 
         self.frame = self.res.LoadFrame(None,"MainFrame")
-        self.panel = XRCCTRL(self.frame,"MainPanel")
+        self.panel = xrc.XRCCTRL(self.frame,"MainPanel")
 
         # matplotlib panel -------------
 
         # container for matplotlib panel (I like to make a container
         # panel for our panel so I know where it'll go when in XRCed.)
-        plot_container = XRCCTRL(self.frame,"plot_container_panel")
-        sizer = BoxSizer(VERTICAL)
+        plot_container = xrc.XRCCTRL(self.frame,"plot_container_panel")
+        sizer = wx.BoxSizer(wx.VERTICAL)
 
         # matplotlib panel itself
         self.plotpanel = PlotPanel(plot_container)
         self.plotpanel.init_plot_data()
 
         # wx boilerplate
-        sizer.Add(self.plotpanel, 1, EXPAND)
+        sizer.Add(self.plotpanel, 1, wx.EXPAND)
         plot_container.SetSizer(sizer)
 
         # whiz button ------------------
 
-        whiz_button = XRCCTRL(self.frame,"whiz_button")
-        EVT_BUTTON(whiz_button, whiz_button.GetId(),
-                   self.plotpanel.OnWhiz)
+        whiz_button = xrc.XRCCTRL(self.frame,"whiz_button")
+        wx.EVT_BUTTON(whiz_button, whiz_button.GetId(),
+                      self.plotpanel.OnWhiz)
 
         # bang button ------------------
 
-        bang_button = XRCCTRL(self.frame,"bang_button")
-        EVT_BUTTON(bang_button, bang_button.GetId(),
-                   self.OnBang)
+        bang_button = xrc.XRCCTRL(self.frame,"bang_button")
+        wx.EVT_BUTTON(bang_button, bang_button.GetId(),
+                      self.OnBang)
 
         # final setup ------------------
 
Index: examples/user_interfaces/embedding_in_wx4.py
===================================================================
--- examples/user_interfaces/embedding_in_wx4.py	(revision 6971)
+++ examples/user_interfaces/embedding_in_wx4.py	(working copy)
@@ -4,6 +4,10 @@
 toolbar
 """
 
+# Used to guarantee to use at least Wx2.8
+import wxversion
+wxversion.ensureMinimal('2.8')
+
 from numpy import arange, sin, pi
 
 import matplotlib
@@ -16,13 +20,13 @@
 from matplotlib.figure import Figure
 from numpy.random import rand
 
-from wx import *
+import wx
 
 class MyNavigationToolbar(NavigationToolbar2WxAgg):
     """
     Extend the default wx toolbar with your own event handlers
     """
-    ON_CUSTOM = NewId()
+    ON_CUSTOM = wx.NewId()
     def __init__(self, canvas, cankill):
         NavigationToolbar2WxAgg.__init__(self, canvas)
 
@@ -30,7 +34,7 @@
         # probably want to add your own.
         self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap('stock_left.xpm'),
                            'Click me', 'Activate custom contol')
-        EVT_TOOL(self, self.ON_CUSTOM, self._on_custom)
+        wx.EVT_TOOL(self, self.ON_CUSTOM, self._on_custom)
 
     def _on_custom(self, evt):
         # add some text to the axes in a random location in axes (0,1)
@@ -51,13 +55,13 @@
         evt.Skip()
 
 
-class CanvasFrame(Frame):
+class CanvasFrame(wx.Frame):
 
     def __init__(self):
-        Frame.__init__(self,None,-1,
+        wx.Frame.__init__(self,None,-1,
                          'CanvasFrame',size=(550,350))
 
-        self.SetBackgroundColour(NamedColor("WHITE"))
+        self.SetBackgroundColour(wx.NamedColor("WHITE"))
 
         self.figure = Figure(figsize=(5,4), dpi=100)
         self.axes = self.figure.add_subplot(111)
@@ -68,14 +72,14 @@
 
         self.canvas = FigureCanvas(self, -1, self.figure)
 
-        self.sizer = BoxSizer(VERTICAL)
-        self.sizer.Add(self.canvas, 1, TOP | LEFT | EXPAND)
+        self.sizer = wx.BoxSizer(wx.VERTICAL)
+        self.sizer.Add(self.canvas, 1, wx.TOP | wx.LEFT | wx.EXPAND)
         # Capture the paint message
-        EVT_PAINT(self, self.OnPaint)
+        wx.EVT_PAINT(self, self.OnPaint)
 
         self.toolbar = MyNavigationToolbar(self.canvas, True)
         self.toolbar.Realize()
-        if Platform == '__WXMAC__':
+        if wx.Platform == '__WXMAC__':
             # Mac platform (OSX 10.3, MacPython) does not seem to cope with
             # having a toolbar in a sizer. This work-around gets the buttons
             # back, but at the expense of having the toolbar at the top
@@ -88,8 +92,8 @@
             # By adding toolbar in sizer, we are able to put it at the bottom
             # of the frame - so appearance is closer to GTK version.
             # As noted above, doesn't work for Mac.
-            self.toolbar.SetSize(Size(fw, th))
-            self.sizer.Add(self.toolbar, 0, LEFT | EXPAND)
+            self.toolbar.SetSize(wx.Size(fw, th))
+            self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
 
         # update the axes menu on the toolbar
         self.toolbar.update()
@@ -101,7 +105,7 @@
         self.canvas.draw()
         event.Skip()
 
-class App(App):
+class App(wx.App):
 
     def OnInit(self):
         'Create the main window and insert the custom frame'
Index: examples/user_interfaces/embedding_in_wx5.py
===================================================================
--- examples/user_interfaces/embedding_in_wx5.py	(revision 6971)
+++ examples/user_interfaces/embedding_in_wx5.py	(working copy)
@@ -1,3 +1,7 @@
+# Used to guarantee to use at least Wx2.8
+import wxversion
+wxversion.ensureMinimal('2.8')
+
 import wx
 import wx.aui
 import matplotlib as mpl
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to