Hi Giacomo,
sorry for the delay.
On Fri, Mar 6, 2009 at 08:48, Giacomo Boffi <[email protected]> wrote:
> Sandro Tosi writes:
>
> about --- from wx import * ---
>
> > Mh, there is no reasons why "from <module> import *" should not work,
> > and indeed there is a bug already reported about it: #488532
>
> i have googled around, it seems that this problem was repeatedly
> reported to distributions and upstream, but never resolved
>
> the usual upstream reply is sort of
>
> "from * import *" is bad practice anyway,
> please do "import wx"
>
>
> about --- import wx.aui ---
>
> > This is because the default python wrapper on your machine is v2.6, on
> > 2.8 that module is present:
>
> i had both the 2.6 and the 2.8 wrappers, both automatically installed,
> and apparently python finds first the older one
>
> after i removed 2.6 and its reverse dependencies, the example file n.5
> works OK, python finding the wx.aui module
>
> in summary, i think that my bug is upstream, either in wxpython or in
> matplotlib
The problem was that matplotlib requires wx2.8, but on debian when
both 2.6 and 2.8 are installed, 2.6 is chosed. I sent a patch upstream
to convert to "import wx" together with a way to choose wx2.8 (using
wxversion)
> i understand that "from wx import *" should work, but it seems that
> it's not going to work anytime soon
with wx2.8 it works as expected.
> may i suggest that you, speaking as the debian mantainer, could report
> to matplotlib developers the opportunity of modifying all the wx
> examples that do the "wrong" thing when importing wx? they are
That's what the patch I forged do. I attached here too, just in case
you want to look at and apply it locally.
Anyhow, I don't plan an upload to just fix these examples, so this bug
will be fixed when upstream will release a new version.
Regards,
--
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
_______________________________________________
Python-modules-team mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/python-modules-team