Skip to content

Commit 5499980

Browse files
committed
- get wx backends compatible with wxPython Phoenix
1 parent 9661a02 commit 5499980

File tree

2 files changed

+71
-26
lines changed

2 files changed

+71
-26
lines changed

lib/matplotlib/backends/backend_wx.py

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,6 @@ class FigureCanvasWx(FigureCanvasBase, wx.Panel):
667667
wx.WXK_DELETE : 'delete',
668668
wx.WXK_HOME : 'home',
669669
wx.WXK_END : 'end',
670-
wx.WXK_PRIOR : 'pageup',
671-
wx.WXK_NEXT : 'pagedown',
672670
wx.WXK_PAGEUP : 'pageup',
673671
wx.WXK_PAGEDOWN : 'pagedown',
674672
wx.WXK_NUMPAD0 : '0',
@@ -691,8 +689,6 @@ class FigureCanvasWx(FigureCanvasBase, wx.Panel):
691689
wx.WXK_NUMPAD_RIGHT : 'right',
692690
wx.WXK_NUMPAD_DOWN : 'down',
693691
wx.WXK_NUMPAD_LEFT : 'left',
694-
wx.WXK_NUMPAD_PRIOR : 'pageup',
695-
wx.WXK_NUMPAD_NEXT : 'pagedown',
696692
wx.WXK_NUMPAD_PAGEUP : 'pageup',
697693
wx.WXK_NUMPAD_PAGEDOWN : 'pagedown',
698694
wx.WXK_NUMPAD_HOME : 'home',
@@ -736,7 +732,10 @@ def do_nothing(*args, **kwargs):
736732

737733

738734
# Create the drawing bitmap
739-
self.bitmap =wx.EmptyBitmap(w, h)
735+
if 'phoenix' in wx.PlatformInfo:
736+
self.bitmap =wx.Bitmap(w, h)
737+
else:
738+
self.bitmap =wx.EmptyBitmap(w, h)
740739
DEBUG_MSG("__init__() - bitmap w:%d h:%d" % (w,h), 2, self)
741740
# TODO: Add support for 'point' inspection and plot navigation.
742741
self._isDrawn = False
@@ -873,7 +872,10 @@ def start_event_loop(self, timeout=0):
873872
bind(self, wx.EVT_TIMER, self.stop_event_loop, id=id)
874873

875874
# Event loop handler for start/stop event loop
876-
self._event_loop = wx.EventLoop()
875+
if 'phoenix' in wx.PlatformInfo:
876+
self._event_loop = wx.GUIEventLoop()
877+
else:
878+
self._event_loop = wx.EventLoop()
877879
self._event_loop.Run()
878880
timer.Stop()
879881

@@ -897,7 +899,7 @@ def _get_imagesave_wildcards(self):
897899
'return the wildcard string for the filesave dialog'
898900
default_filetype = self.get_default_filetype()
899901
filetypes = self.get_supported_filetypes_grouped()
900-
sorted_filetypes = list(six.iteritems(filetypes))
902+
sorted_filetypes = filetypes.items()
901903
sorted_filetypes.sort()
902904
wildcards = []
903905
extensions = []
@@ -923,9 +925,12 @@ def gui_repaint(self, drawDC=None):
923925
if drawDC is None:
924926
drawDC=wx.ClientDC(self)
925927

926-
drawDC.BeginDrawing()
927-
drawDC.DrawBitmap(self.bitmap, 0, 0)
928-
drawDC.EndDrawing()
928+
if 'phoenix' in wx.PlatformInfo:
929+
drawDC.DrawBitmap(self.bitmap, 0, 0)
930+
else:
931+
drawDC.BeginDrawing()
932+
drawDC.DrawBitmap(self.bitmap, 0, 0)
933+
drawDC.EndDrawing()
929934
#wx.GetApp().Yield()
930935
else:
931936
pass
@@ -979,7 +984,11 @@ def _print_image(self, filename, filetype, *args, **kwargs):
979984
width = int(math.ceil(width))
980985
height = int(math.ceil(height))
981986

982-
self.bitmap = wx.EmptyBitmap(width, height)
987+
if 'phoenix' in wx.PlatformInfo:
988+
self.bitmap =wx.Bitmap(width, height)
989+
else:
990+
self.bitmap =wx.EmptyBitmap(width, height)
991+
983992
renderer = RendererWx(self.bitmap, self.figure.dpi)
984993

985994
gc = renderer.new_gc()
@@ -1052,7 +1061,11 @@ def _onSize(self, evt):
10521061
DEBUG_MSG("_onSize()", 2, self)
10531062
# Create a new, correctly sized bitmap
10541063
self._width, self._height = self.GetClientSize()
1055-
self.bitmap =wx.EmptyBitmap(self._width, self._height)
1064+
if 'phoenix' in wx.PlatformInfo:
1065+
self.bitmap =wx.Bitmap(self._width, self._height)
1066+
else:
1067+
self.bitmap =wx.EmptyBitmap(self._width, self._height)
1068+
10561069
self._isDrawn = False
10571070

10581071
if self._width <= 1 or self._height <= 1: return # Empty figure
@@ -1636,12 +1649,25 @@ def _init_toolbar(self):
16361649
self.AddSeparator()
16371650
continue
16381651
self.wx_ids[text] = wx.NewId()
1639-
if text in ['Pan', 'Zoom']:
1640-
self.AddCheckTool(self.wx_ids[text], _load_bitmap(image_file + '.png'),
1641-
shortHelp=text, longHelp=tooltip_text)
1652+
if 'phoenix' in wx.PlatformInfo:
1653+
if text in ['Pan', 'Zoom']:
1654+
kind = wx.ITEM_CHECK
1655+
else:
1656+
kind = wx.ITEM_NORMAL
1657+
self.AddTool(self.wx_ids[text], label=text,
1658+
bitmap=_load_bitmap(image_file + '.png'),
1659+
bmpDisabled=wx.NullBitmap,
1660+
shortHelpString=text,
1661+
longHelpString=tooltip_text,
1662+
kind=kind)
16421663
else:
1643-
self.AddSimpleTool(self.wx_ids[text], _load_bitmap(image_file + '.png'),
1644-
text, tooltip_text)
1664+
if text in ['Pan', 'Zoom']:
1665+
self.AddCheckTool(self.wx_ids[text], _load_bitmap(image_file + '.png'),
1666+
shortHelp=text, longHelp=tooltip_text)
1667+
else:
1668+
self.AddSimpleTool(self.wx_ids[text], _load_bitmap(image_file + '.png'),
1669+
text, tooltip_text)
1670+
16451671
bind(self, wx.EVT_TOOL, getattr(self, callback), id=self.wx_ids[text])
16461672

16471673
self.Realize()
@@ -1700,7 +1726,10 @@ def save_figure(self, *args):
17001726
error_msg_wx(str(e))
17011727

17021728
def set_cursor(self, cursor):
1703-
cursor =wx.StockCursor(cursord[cursor])
1729+
if 'phoenix' in wx.PlatformInfo:
1730+
cursor = wx.Cursor(cursord[cursor])
1731+
else:
1732+
cursor = wx.StockCursor(cursord[cursor])
17041733
self.canvas.SetCursor( cursor )
17051734

17061735
def release(self, event):
@@ -1737,7 +1766,8 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
17371766

17381767

17391768
dc.ResetBoundingBox()
1740-
dc.BeginDrawing()
1769+
if not 'phoenix' in wx.PlatformInfo:
1770+
dc.BeginDrawing()
17411771
height = self.canvas.figure.bbox.height
17421772
y1 = height - y1
17431773
y0 = height - y0
@@ -1754,7 +1784,8 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
17541784
else: dc.DrawRectangle(*lastrect) #erase last
17551785
self.lastrect = rect
17561786
dc.DrawRectangle(*rect)
1757-
dc.EndDrawing()
1787+
if not 'phoenix' in wx.PlatformInfo:
1788+
dc.EndDrawing()
17581789

17591790
def set_status_bar(self, statbar):
17601791
self.statbar = statbar

lib/matplotlib/backends/backend_wxagg.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ def _convert_agg_to_wx_image(agg, bbox):
136136
"""
137137
if bbox is None:
138138
# agg => rgb -> image
139-
image = wx.EmptyImage(int(agg.width), int(agg.height))
139+
if 'phoenix' in wx.PlatformInfo:
140+
image = wx.Image(int(agg.width), int(agg.height))
141+
else:
142+
image = wx.EmptyImage(int(agg.width), int(agg.height))
140143
image.SetData(agg.tostring_rgb())
141144
return image
142145
else:
@@ -153,8 +156,12 @@ def _convert_agg_to_wx_bitmap(agg, bbox):
153156
"""
154157
if bbox is None:
155158
# agg => rgba buffer -> bitmap
156-
return wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
157-
agg.buffer_rgba())
159+
if 'phoenix' in wx.PlatformInfo:
160+
return wx.Bitmap.FromBufferRGBA(int(agg.width), int(agg.height),
161+
agg.buffer_rgba())
162+
else:
163+
return wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
164+
agg.buffer_rgba())
158165
else:
159166
# agg => rgba buffer -> bitmap => clipped bitmap
160167
return _WX28_clipped_agg_as_bitmap(agg, bbox)
@@ -170,12 +177,19 @@ def _WX28_clipped_agg_as_bitmap(agg, bbox):
170177
r = l + width
171178
t = b + height
172179

173-
srcBmp = wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
174-
agg.buffer_rgba())
180+
if 'phoenix' in wx.PlatformInfo:
181+
srcBmp = wx.Bitmap.FromBufferRGBA(int(agg.width), int(agg.height),
182+
agg.buffer_rgba())
183+
else:
184+
srcBmp = wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
185+
agg.buffer_rgba())
175186
srcDC = wx.MemoryDC()
176187
srcDC.SelectObject(srcBmp)
177188

178-
destBmp = wx.EmptyBitmap(int(width), int(height))
189+
if 'phoenix' in wx.PlatformInfo:
190+
destBmp = wx.Bitmap(int(width), int(height))
191+
else:
192+
destBmp = wx.EmptyBitmap(int(width), int(height))
179193
destDC = wx.MemoryDC()
180194
destDC.SelectObject(destBmp)
181195

0 commit comments

Comments
 (0)