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 1 commit
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
Prev Previous commit
Next Next commit
- wxPython Phoenix
  • Loading branch information
wernerfb committed May 10, 2013
commit 165f2a2a23d4efdc29864237bf5975ca77b5620c
29 changes: 23 additions & 6 deletions examples/user_interfaces/embedding_in_wx5.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# 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

if 'phoenix' in wx.PlatformInfo:
import wx.lib.agw.aui as aui
else:
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 +30,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
84 changes: 56 additions & 28 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
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 @@ -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',
Expand Down Expand Up @@ -734,7 +730,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 @@ -780,11 +779,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 @@ -1055,7 +1054,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 @@ -1105,10 +1107,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 @@ -1159,7 +1164,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 @@ -1220,7 +1228,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 @@ -1237,8 +1248,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 @@ -1411,11 +1424,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 @@ -1812,13 +1825,25 @@ 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']:
kind = wx.ITEM_CHECK
else:
kind = wx.ITEM_NORMAL
self.AddTool(self.wx_ids[text], label=text,
bitmap=_load_bitmap(image_file + '.png'),
bmpDisabled=wx.NullBitmap,
shortHelpString=text,
longHelpString=tooltip_text,
kind=kind)
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 @@ -1877,7 +1902,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