Hi Michael,

On 26/04/2013 14:40, Michael Droettboom wrote:
On 04/26/2013 02:57 AM, Werner F. Bruhin wrote:
Hi,

Anyone can provide some info on what "agg.buffer_rgba" returns and maybe
even some suggestion on how to resolve this issue in the wxagg backend.
It returns a Python buffer object on Python 2, though on Python 3 it is
a memoryview, since buffer was deprecated.  Perhaps wx is also doing
something different depending on the version of Python.
As of Phoenix 2.9.5.81-r73873 matplot works with Phoenix, here is Robin Dunn's comment to the change he did on Phoenix with regards to the buffer handling.

Quote

The new buffer APIs go as far back as 2.6, IIRC, and the memoryview and bytearray object types are available in 2.7 in addition to 3.x and that I what I'm using in Phoenix. I would have expected MPL to do so also since numpy is an integral part of MPL and the new buffer interface was basically designed for and by numpy...

Anyway, while double checking all this I realized that it would not be hard for me to accept old or new buffer objects for source buffers (I'll still use memoryviews or bytearrays when on the producer side of things) so try again after the next snapshot build. My unittests with array.arrrays started working after the change so I expect that MPL's rgba buffer should work too.

EndQuote

Enclosed is the patch for backend_wx.py and for embedding_in_wx5.py which I used for testing, in the later I use wxversion.select to force selection of a particular version - I think the distribution should still just use ensureMinimal.

FYI, documentation for wxPython Phoenix are here:
http://wxpython.org/Phoenix/docs/html/index.html

And snapshots can be found here:
http://wxpython.org/Phoenix/snapshot-builds/

I tested only on Python 2.7.2 on Windows 7.

Werner
 examples/user_interfaces/embedding_in_wx5.py | 20 ++++++--
 lib/matplotlib/backends/backend_wx.py        | 74 ++++++++++++++++++++--------
 2 files changed, 69 insertions(+), 25 deletions(-)

diff --git a/examples/user_interfaces/embedding_in_wx5.py 
b/examples/user_interfaces/embedding_in_wx5.py
index fd3969a..9d39896 100644
--- a/examples/user_interfaces/embedding_in_wx5.py
+++ b/examples/user_interfaces/embedding_in_wx5.py
@@ -1,9 +1,14 @@
 # Used to guarantee to use at least Wx2.8
 import wxversion
-wxversion.ensureMinimal('2.8')
+#wxversion.ensureMinimal('2.8')
+#wxversion.select('2.8')
+wxversion.select('2.9.6') # phoenix
+
 
 import wx
-import wx.aui
+print wx.VERSION_STRING
+
+import wx.lib.agw.aui as aui
 import matplotlib as mpl
 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
 from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as Toolbar
@@ -20,11 +25,17 @@ class Plot(wx.Panel):
         sizer.Add(self.canvas,1,wx.EXPAND)
         sizer.Add(self.toolbar, 0 , wx.LEFT | wx.EXPAND)
         self.SetSizer(sizer)
+        self.Bind(wx.EVT_PAINT, self.OnPaint)
+        
+    def OnPaint(self, event):
+        self.canvas.draw()
+        event.Skip()
+        
 
 class PlotNotebook(wx.Panel):
     def __init__(self, parent, id = -1):
         wx.Panel.__init__(self, parent, id=id)
-        self.nb = wx.aui.AuiNotebook(self)
+        self.nb = aui.AuiNotebook(self)
         sizer = wx.BoxSizer()
         sizer.Add(self.nb, 1, wx.EXPAND)
         self.SetSizer(sizer)
@@ -36,7 +47,8 @@ class PlotNotebook(wx.Panel):
 
 
 def demo():
-    app = wx.PySimpleApp()
+    import wx.lib.mixins.inspection as wit
+    app = wit.InspectableApp()
     frame = wx.Frame(None,-1,'Plotter')
     plotter = PlotNotebook(frame)
     axes1 = plotter.add('figure 1').gca()
diff --git a/lib/matplotlib/backends/backend_wx.py 
b/lib/matplotlib/backends/backend_wx.py
index b58433f..251bac0 100644
--- a/lib/matplotlib/backends/backend_wx.py
+++ b/lib/matplotlib/backends/backend_wx.py
@@ -665,8 +665,6 @@ class FigureCanvasWx(FigureCanvasBase, wx.Panel):
         wx.WXK_DELETE          : 'delete',
         wx.WXK_HOME            : 'home',
         wx.WXK_END             : 'end',
-        wx.WXK_PRIOR           : 'pageup',
-        wx.WXK_NEXT            : 'pagedown',
         wx.WXK_PAGEUP          : 'pageup',
         wx.WXK_PAGEDOWN        : 'pagedown',
         wx.WXK_NUMPAD0         : '0',
@@ -689,8 +687,6 @@ class FigureCanvasWx(FigureCanvasBase, wx.Panel):
         wx.WXK_NUMPAD_RIGHT    : 'right',
         wx.WXK_NUMPAD_DOWN     : 'down',
         wx.WXK_NUMPAD_LEFT     : 'left',
-        wx.WXK_NUMPAD_PRIOR    : 'pageup',
-        wx.WXK_NUMPAD_NEXT     : 'pagedown',
         wx.WXK_NUMPAD_PAGEUP   : 'pageup',
         wx.WXK_NUMPAD_PAGEDOWN : 'pagedown',
         wx.WXK_NUMPAD_HOME     : 'home',
@@ -734,7 +730,10 @@ class FigureCanvasWx(FigureCanvasBase, wx.Panel):
 
 
         # Create the drawing bitmap
-        self.bitmap =wx.EmptyBitmap(w, h)
+        if 'phoenix' in wx.PlatformInfo:
+            self.bitmap =wx.Bitmap(w, h)
+        else:
+            self.bitmap =wx.EmptyBitmap(w, h)
         DEBUG_MSG("__init__() - bitmap w:%d h:%d" % (w,h), 2, self)
         # TODO: Add support for 'point' inspection and plot navigation.
         self._isDrawn = False
@@ -1055,7 +1054,10 @@ The current aspect ratio will be kept."""
             bind(self, wx.EVT_TIMER, self.stop_event_loop, id=id)
 
         # Event loop handler for start/stop event loop
-        self._event_loop = wx.EventLoop()
+        if 'phoenix' in wx.PlatformInfo:
+            self.event_loop = wx.GUIEventLoop()
+        else:
+            self._event_loop = wx.EventLoop()
         self._event_loop.Run()
         timer.Stop()
 
@@ -1105,10 +1107,13 @@ The current aspect ratio will be kept."""
             if drawDC is None:
                 drawDC=wx.ClientDC(self)
 
-            drawDC.BeginDrawing()
-            drawDC.DrawBitmap(self.bitmap, 0, 0)
-            drawDC.EndDrawing()
-            #wx.GetApp().Yield()
+                if 'phoenix' in wx.PlatformInfo:
+                    drawDC.DrawBitmap(self.bitmap, 0, 0)
+                else:
+                    drawDC.BeginDrawing()
+                    drawDC.DrawBitmap(self.bitmap, 0, 0)
+                    drawDC.EndDrawing()
+                    #wx.GetApp().Yield()
         else:
             pass
 
@@ -1159,7 +1164,10 @@ The current aspect ratio will be kept."""
         width = int(math.ceil(width))
         height = int(math.ceil(height))
 
-        self.bitmap = wx.EmptyBitmap(width, height)
+        if 'phoenix' in wx.PlatformInfo:
+            self.bitmap = wx.Bitmap(width, height)
+        else:
+            self.bitmap = wx.EmptyBitmap(width, height)
         renderer = RendererWx(self.bitmap, self.figure.dpi)
 
         gc = renderer.new_gc()
@@ -1220,7 +1228,10 @@ The current aspect ratio will be kept."""
         DEBUG_MSG("_onSize()", 2, self)
         # Create a new, correctly sized bitmap
         self._width, self._height = self.GetClientSize()
-        self.bitmap =wx.EmptyBitmap(self._width, self._height)
+        if 'phoenix' in wx.PlatformInfo:
+            self.bitmap =wx.Bitmap(self._width, self._height)
+        else:
+            self.bitmap =wx.EmptyBitmap(self._width, self._height)
         self._isDrawn = False
 
         if self._width <= 1 or self._height <= 1: return # Empty figure
@@ -1237,8 +1248,10 @@ The current aspect ratio will be kept."""
         FigureCanvasBase.resize_event(self)
 
     def _get_key(self, evt):
-
-        keyval = evt.m_keyCode
+        if 'phoenix' in wx.PlatformInfo:
+            keyval = evt.KeyCode
+        else:
+            keyval = evt.m_keyCode
         if keyval in self.keyvald:
             key = self.keyvald[keyval]
         elif keyval < 256:
@@ -1812,13 +1825,29 @@ class NavigationToolbar2Wx(NavigationToolbar2, 
wx.ToolBar):
             if text is None:
                 self.AddSeparator()
                 continue
-            self.wx_ids[text] = wx.NewId()
-            if text in ['Pan', 'Zoom']:
-               self.AddCheckTool(self.wx_ids[text], _load_bitmap(image_file + 
'.png'),
-                                 shortHelp=text, longHelp=tooltip_text)
+            self.wx_ids[text] = int(wx.NewId())
+            if 'phoenix' in wx.PlatformInfo:
+                if text in ['Pan', 'Zoom']:
+                    self.AddTool(self.wx_ids[text], label=text,
+                                 bitmap=_load_bitmap(image_file + '.png'),
+                                 bmpDisabled=wx.NullBitmap,
+                                 shortHelpString=text,
+                                 longHelpString=tooltip_text,
+                                 kind=wx.ITEM_CHECK)
+                else:
+                    self.AddTool(self.wx_ids[text], label=text,
+                                 bitmap=_load_bitmap(image_file + '.png'),
+                                 bmpDisabled=wx.NullBitmap,
+                                 shortHelpString=text,
+                                 longHelpString=tooltip_text,
+                                 kind=wx.ITEM_NORMAL)
             else:
-               self.AddSimpleTool(self.wx_ids[text], _load_bitmap(image_file + 
'.png'),
-                                  text, tooltip_text)
+                if text in ['Pan', 'Zoom']:
+                    self.AddCheckTool(self.wx_ids[text], 
_load_bitmap(image_file + '.png'),
+                                      shortHelp=text, longHelp=tooltip_text)
+                else:
+                    self.AddSimpleTool(self.wx_ids[text], 
_load_bitmap(image_file + '.png'),
+                                       text, tooltip_text)
             bind(self, wx.EVT_TOOL, getattr(self, callback), 
id=self.wx_ids[text])
 
         self.Realize()
@@ -1877,7 +1906,10 @@ class NavigationToolbar2Wx(NavigationToolbar2, 
wx.ToolBar):
                 error_msg_wx(str(e))
 
     def set_cursor(self, cursor):
-        cursor =wx.StockCursor(cursord[cursor])
+        if 'phoenix' in wx.PlatformInfo:
+            cursor = wx.Cursor(cursord[cursor])            
+        else:
+            cursor = wx.StockCursor(cursord[cursor])
         self.canvas.SetCursor( cursor )
 
     def release(self, event):
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to