Skip to content

wx backend changes for wxPython Phoenix #1974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions examples/user_interfaces/embedding_in_wx5.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# Used to guarantee to use at least Wx2.8
import wxversion
wxversion.ensureMinimal('2.8')
#wxversion.select('2.8')
#wxversion.select('2.9.5') # 2.9.x classic
#wxversion.select('2.9.6-msw-phoenix') # 2.9.x phoenix


import wx
import wx.aui
print wx.VERSION_STRING

import wx.lib.agw.aui as aui
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with v2.8?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 07/05/2013 12:52, Phil Elson wrote:

In examples/user_interfaces/embedding_in_wx5.py:

import wx
-import wx.aui
+print wx.VERSION_STRING
+
+import wx.lib.agw.aui as aui

Does this work with v2.8?

I testet with 2.8.12.1, as per changes.html in 2.8.12:

2.8.9.2

  • 16-Feb-2009

Added the wx.lib.agw package ........

So, only as of 2.8.9+ will it work, if that is not acceptable that one
could do:

     if 'phoenix' in wx.PlatformInfo:
            import wx.lib.agw.aui as aui
     else:
            import wx.aui as aui

Werner

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more general way to handle it would be

try:
    import wx.lib.agw.aui as aui
except ImportError:
    import wx.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
Expand All @@ -20,23 +26,30 @@ def __init__(self, parent, id = -1, dpi = None, **kwargs):
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)

def add(self,name="plot"):
page = Plot(self.nb)
self.nb.AddPage(page,name)
return page.figure
page = Plot(self.nb)
self.nb.AddPage(page,name)
return page.figure


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()
Expand Down
88 changes: 60 additions & 28 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these don't exist any more in wx?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

On 07/05/2013 12:58, Phil Elson wrote:

In lib/matplotlib/backends/backend_wx.py:

@@ -666,8 +666,6 @@ class FigureCanvasWx(FigureCanvasBase, wx.Panel):
wx.WXK_DELETE : 'delete',
wx.WXK_HOME : 'home',
wx.WXK_END : 'end',

  •    wx.WXK_PRIOR           : 'pageup',
    

Looks like these don't exist any more in wx?

Prior yes, the others are still there:
wxpython.org/Phoenix/docs/html/KeyCode.enumeration.html

Werner

wx.WXK_PAGEDOWN : 'pagedown',
wx.WXK_NUMPAD0 : '0',
Expand All @@ -690,8 +688,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',
Expand Down Expand Up @@ -735,7 +731,10 @@ def do_nothing(*args, **kwargs):


# 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
Expand Down Expand Up @@ -781,11 +780,11 @@ def Copy_to_Clipboard(self, event=None):
bmp_obj.SetBitmap(self.bitmap)

if not wx.TheClipboard.IsOpened():
open_success = wx.TheClipboard.Open()
if open_success:
wx.TheClipboard.SetData(bmp_obj)
wx.TheClipboard.Close()
wx.TheClipboard.Flush()
open_success = wx.TheClipboard.Open()
if open_success:
wx.TheClipboard.SetData(bmp_obj)
wx.TheClipboard.Close()
wx.TheClipboard.Flush()

def Printer_Init(self):
"""
Expand Down Expand Up @@ -1056,7 +1055,10 @@ def start_event_loop(self, timeout=0):
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()

Expand Down Expand Up @@ -1106,10 +1108,13 @@ def gui_repaint(self, drawDC=None):
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

Expand Down Expand Up @@ -1160,7 +1165,10 @@ def _print_image(self, filename, filetype, *args, **kwargs):
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()
Expand Down Expand Up @@ -1221,7 +1229,10 @@ def _onSize(self, evt):
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
Expand All @@ -1238,8 +1249,10 @@ def _onSize(self, evt):
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:
Expand Down Expand Up @@ -1412,11 +1425,11 @@ def _onEnter(self, evt):

def _create_wx_app():
"""
Creates a wx.PySimpleApp instance if a wx.App has not been created.
Creates a wx.App instance if a wx.App has not been created.
"""
wxapp = wx.GetApp()
if wxapp is None:
wxapp = wx.PySimpleApp()
wxapp = wx.App()
wxapp.SetExitOnFrameDelete(True)
# retain a reference to the app object so it does not get garbage
# collected and cause segmentation faults
Expand Down Expand Up @@ -1813,13 +1826,29 @@ def _init_toolbar(self):
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like "kind" is the only difference here - probably worth putting "kind" in a variable and having the AddTool outside of the if statement.

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()
Expand Down Expand Up @@ -1878,7 +1907,10 @@ def save_figure(self, *args):
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):
Expand Down
13 changes: 10 additions & 3 deletions lib/matplotlib/backends/backend_wxagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ def _convert_agg_to_wx_image(agg, bbox):
"""
if bbox is None:
# agg => rgb -> image
image = wx.EmptyImage(int(agg.width), int(agg.height))
if 'phoenix' in wx.PlatformInfo:
image = wx.Image(int(agg.width), int(agg.height))
else:
image = wx.EmptyImage(int(agg.width), int(agg.height))
image.SetData(agg.tostring_rgb())
return image
else:
Expand All @@ -165,8 +168,12 @@ def _convert_agg_to_wx_bitmap(agg, bbox):
"""
if bbox is None:
# agg => rgba buffer -> bitmap
return wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
agg.buffer_rgba())
if 'phoenix' in wx.PlatformInfo:
return wx.Bitmap.FromBufferRGBA(int(agg.width), int(agg.height),
agg.buffer_rgba())
else:
return wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
agg.buffer_rgba())
else:
# agg => rgba buffer -> bitmap => clipped bitmap
return _WX28_clipped_agg_as_bitmap(agg, bbox)
Expand Down