Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88b95e2

Browse files
author
pkienzle
committed
Use bind() function to hide wx version differences
svn path=/trunk/matplotlib/; revision=5840
1 parent 67b6127 commit 88b95e2

1 file changed

Lines changed: 49 additions & 111 deletions

File tree

lib/matplotlib/backends/backend_wx.py

Lines changed: 49 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ def write(self, msg):
145145
# WxLogger =wx.LogStderr()
146146
# sys.stderr = fake_stderr
147147

148+
# Event binding code changed after version 2.5
149+
if wx.VERSION_STRING >= '2.5':
150+
def bind(actor,event,action,**kw):
151+
actor.Bind(event,action,**kw)
152+
else:
153+
def bind(actor,event,action,id=None):
154+
if id is not None:
155+
event(actor, id, action)
156+
else:
157+
event(actor,action)
148158

149159
import matplotlib
150160
from matplotlib import verbose
@@ -161,10 +171,6 @@ def write(self, msg):
161171
from matplotlib.widgets import SubplotTool
162172
from matplotlib import rcParams
163173

164-
##import wx
165-
##backend_version = wx.VERSION_STRING
166-
167-
168174
# the True dots per inch on the screen; should be display dependent
169175
# see http://groups.google.com/groups?q=screen+dpi+x11&hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=7077.26e81ad5%40swift.cs.tcd.ie&rnum=5 for some info about screen dpi
170176
PIXELS_PER_INCH = 75
@@ -698,39 +704,20 @@ def do_nothing(*args, **kwargs):
698704
self._isConfigured = False
699705
self._printQued = []
700706

701-
if wx.VERSION_STRING >= '2.5':
702-
# Event handlers 2.5
703-
self.Bind(wx.EVT_SIZE, self._onSize)
704-
self.Bind(wx.EVT_PAINT, self._onPaint)
705-
self.Bind(wx.EVT_KEY_DOWN, self._onKeyDown)
706-
self.Bind(wx.EVT_KEY_UP, self._onKeyUp)
707-
self.Bind(wx.EVT_RIGHT_DOWN, self._onRightButtonDown)
708-
self.Bind(wx.EVT_RIGHT_DCLICK, self._onRightButtonDown)
709-
self.Bind(wx.EVT_RIGHT_UP, self._onRightButtonUp)
710-
self.Bind(wx.EVT_MOUSEWHEEL, self._onMouseWheel)
711-
self.Bind(wx.EVT_LEFT_DOWN, self._onLeftButtonDown)
712-
self.Bind(wx.EVT_LEFT_DCLICK, self._onLeftButtonDown)
713-
self.Bind(wx.EVT_LEFT_UP, self._onLeftButtonUp)
714-
self.Bind(wx.EVT_MOTION, self._onMotion)
715-
self.Bind(wx.EVT_LEAVE_WINDOW, self._onLeave)
716-
self.Bind(wx.EVT_IDLE, self._onIdle)
717-
else:
718-
# Event handlers 2.4
719-
wx.EVT_SIZE(self, self._onSize)
720-
wx.EVT_PAINT(self, self._onPaint)
721-
wx.EVT_KEY_DOWN(self, self._onKeyDown)
722-
wx.EVT_KEY_UP(self, self._onKeyUp)
723-
wx.EVT_RIGHT_DOWN(self, self._onRightButtonDown)
724-
wx.EVT_RIGHT_DCLICK(self, self._onRightButtonDown)
725-
wx.EVT_RIGHT_UP(self, self._onRightButtonUp)
726-
wx.EVT_MOUSEWHEEL(self, self._onMouseWheel)
727-
wx.EVT_LEFT_DOWN(self, self._onLeftButtonDown)
728-
wx.EVT_LEFT_DCLICK(self, self._onLeftButtonDown)
729-
wx.EVT_LEFT_UP(self, self._onLeftButtonUp)
730-
wx.EVT_MOTION(self, self._onMotion)
731-
wx.EVT_LEAVE_WINDOW(self, self._onLeave)
732-
wx.EVT_IDLE(self, self._onIdle)
733-
707+
bind(self, wx.EVT_SIZE, self._onSize)
708+
bind(self, wx.EVT_PAINT, self._onPaint)
709+
bind(self, wx.EVT_KEY_DOWN, self._onKeyDown)
710+
bind(self, wx.EVT_KEY_UP, self._onKeyUp)
711+
bind(self, wx.EVT_RIGHT_DOWN, self._onRightButtonDown)
712+
bind(self, wx.EVT_RIGHT_DCLICK, self._onRightButtonDown)
713+
bind(self, wx.EVT_RIGHT_UP, self._onRightButtonUp)
714+
bind(self, wx.EVT_MOUSEWHEEL, self._onMouseWheel)
715+
bind(self, wx.EVT_LEFT_DOWN, self._onLeftButtonDown)
716+
bind(self, wx.EVT_LEFT_DCLICK, self._onLeftButtonDown)
717+
bind(self, wx.EVT_LEFT_UP, self._onLeftButtonUp)
718+
bind(self, wx.EVT_MOTION, self._onMotion)
719+
bind(self, wx.EVT_LEAVE_WINDOW, self._onLeave)
720+
bind(self, wx.EVT_IDLE, self._onIdle)
734721

735722
self._event_loop = wx.EventLoop()
736723

@@ -1225,17 +1212,6 @@ def draw_if_interactive():
12251212
if figManager is not None:
12261213
figManager.canvas.draw()
12271214

1228-
# Event binding code changed after version 2.5
1229-
if wx.VERSION_STRING >= '2.5':
1230-
def bind(actor,event,action,**kw):
1231-
actor.Bind(event,action,**kw)
1232-
else:
1233-
def bind(actor,event,action,id=None):
1234-
if id is not None:
1235-
event(actor, id, action)
1236-
else:
1237-
event(actor,action)
1238-
12391215
def show():
12401216
"""
12411217
Current implementation assumes that matplotlib is executed in a PyCrust
@@ -1333,12 +1309,7 @@ def __init__(self, num, fig):
13331309

13341310
self.figmgr = FigureManagerWx(self.canvas, num, self)
13351311

1336-
if wx.VERSION_STRING >= '2.5':
1337-
# Event handlers 2.5
1338-
self.Bind(wx.EVT_CLOSE, self._onClose)
1339-
else:
1340-
# Event handlers 2.4
1341-
wx.EVT_CLOSE(self, self._onClose)
1312+
bind(self, wx.EVT_CLOSE, self._onClose)
13421313

13431314
def _get_toolbar(self, statbar):
13441315
if matplotlib.rcParams['toolbar']=='classic':
@@ -1485,14 +1456,9 @@ def __init__(self, parent):
14851456
self._menu.Append(self._invertId, "Invert", "Invert axes selected", False)
14861457
self._menu.AppendSeparator()
14871458

1488-
if wx.VERSION_STRING >= '2.5':
1489-
self.Bind(wx.EVT_BUTTON, self._onMenuButton, id=_NTB_AXISMENU_BUTTON)
1490-
self.Bind(wx.EVT_MENU, self._handleSelectAllAxes, id=self._allId)
1491-
self.Bind(wx.EVT_MENU, self._handleInvertAxesSelected, id=self._invertId)
1492-
else:
1493-
wx.EVT_BUTTON(self, _NTB_AXISMENU_BUTTON, self._onMenuButton)
1494-
wx.EVT_MENU(self, self._allId, self._handleSelectAllAxes)
1495-
wx.EVT_MENU(self, self._invertId, self._handleInvertAxesSelected)
1459+
bind(self, wx.EVT_BUTTON, self._onMenuButton, id=_NTB_AXISMENU_BUTTON)
1460+
bind(self, wx.EVT_MENU, self._handleSelectAllAxes, id=self._allId)
1461+
bind(self, wx.EVT_MENU, self._handleInvertAxesSelected, id=self._invertId)
14961462

14971463
def Destroy(self):
14981464
self._menu.Destroy()
@@ -1546,11 +1512,7 @@ def updateAxes(self, maxAxis):
15461512
self._axisId.append(menuId)
15471513
self._menu.Append(menuId, "Axis %d" % i, "Select axis %d" % i, True)
15481514
self._menu.Check(menuId, True)
1549-
1550-
if wx.VERSION_STRING >= '2.5':
1551-
self.Bind(wx.EVT_MENU, self._onMenuItemSelected, id=menuId)
1552-
else:
1553-
wx.EVT_MENU(self, menuId, self._onMenuItemSelected)
1515+
bind(self, wx.EVT_MENU, self._onMenuItemSelected, id=menuId)
15541516
self._toolbar.set_active(range(len(self._axisId)))
15551517

15561518
def getActiveAxes(self):
@@ -1645,22 +1607,13 @@ def _init_toolbar(self):
16451607
self.AddSimpleTool(_NTB2_SAVE, _load_bitmap('filesave.png'),
16461608
'Save', 'Save plot contents to file')
16471609

1648-
if wx.VERSION_STRING >= '2.5':
1649-
self.Bind(wx.EVT_TOOL, self.home, id=_NTB2_HOME)
1650-
self.Bind(wx.EVT_TOOL, self.forward, id=self._NTB2_FORWARD)
1651-
self.Bind(wx.EVT_TOOL, self.back, id=self._NTB2_BACK)
1652-
self.Bind(wx.EVT_TOOL, self.zoom, id=self._NTB2_ZOOM)
1653-
self.Bind(wx.EVT_TOOL, self.pan, id=self._NTB2_PAN)
1654-
self.Bind(wx.EVT_TOOL, self.configure_subplot, id=_NTB2_SUBPLOT)
1655-
self.Bind(wx.EVT_TOOL, self.save, id=_NTB2_SAVE)
1656-
else:
1657-
wx.EVT_TOOL(self, _NTB2_HOME, self.home)
1658-
wx.EVT_TOOL(self, self._NTB2_FORWARD, self.forward)
1659-
wx.EVT_TOOL(self, self._NTB2_BACK, self.back)
1660-
wx.EVT_TOOL(self, self._NTB2_ZOOM, self.zoom)
1661-
wx.EVT_TOOL(self, self._NTB2_PAN, self.pan)
1662-
wx.EVT_TOOL(self, _NTB2_SUBPLOT, self.configure_subplot)
1663-
wx.EVT_TOOL(self, _NTB2_SAVE, self.save)
1610+
bind(self, wx.EVT_TOOL, self.home, id=_NTB2_HOME)
1611+
bind(self, wx.EVT_TOOL, self.forward, id=self._NTB2_FORWARD)
1612+
bind(self, wx.EVT_TOOL, self.back, id=self._NTB2_BACK)
1613+
bind(self, wx.EVT_TOOL, self.zoom, id=self._NTB2_ZOOM)
1614+
bind(self, wx.EVT_TOOL, self.pan, id=self._NTB2_PAN)
1615+
bind(self, wx.EVT_TOOL, self.configure_subplot, id=_NTB2_SUBPLOT)
1616+
bind(self, wx.EVT_TOOL, self.save, id=_NTB2_SAVE)
16641617

16651618
self.Realize()
16661619

@@ -1859,34 +1812,19 @@ def _create_controls(self, can_kill):
18591812
'Save', 'Save plot contents as images')
18601813
self.AddSeparator()
18611814

1862-
if wx.VERSION_STRING >= '2.5':
1863-
self.Bind(wx.EVT_TOOL, self._onLeftScroll, id=_NTB_X_PAN_LEFT)
1864-
self.Bind(wx.EVT_TOOL, self._onRightScroll, id=_NTB_X_PAN_RIGHT)
1865-
self.Bind(wx.EVT_TOOL, self._onXZoomIn, id=_NTB_X_ZOOMIN)
1866-
self.Bind(wx.EVT_TOOL, self._onXZoomOut, id=_NTB_X_ZOOMOUT)
1867-
self.Bind(wx.EVT_TOOL, self._onUpScroll, id=_NTB_Y_PAN_UP)
1868-
self.Bind(wx.EVT_TOOL, self._onDownScroll, id=_NTB_Y_PAN_DOWN)
1869-
self.Bind(wx.EVT_TOOL, self._onYZoomIn, id=_NTB_Y_ZOOMIN)
1870-
self.Bind(wx.EVT_TOOL, self._onYZoomOut, id=_NTB_Y_ZOOMOUT)
1871-
self.Bind(wx.EVT_TOOL, self._onSave, id=_NTB_SAVE)
1872-
self.Bind(wx.EVT_TOOL_ENTER, self._onEnterTool, id=self.GetId())
1873-
if can_kill:
1874-
self.Bind(wx.EVT_TOOL, self._onClose, id=_NTB_CLOSE)
1875-
self.Bind(wx.EVT_MOUSEWHEEL, self._onMouseWheel)
1876-
else:
1877-
wx.EVT_TOOL(self, _NTB_X_PAN_LEFT, self._onLeftScroll)
1878-
wx.EVT_TOOL(self, _NTB_X_PAN_RIGHT, self._onRightScroll)
1879-
wx.EVT_TOOL(self, _NTB_X_ZOOMIN, self._onXZoomIn)
1880-
wx.EVT_TOOL(self, _NTB_X_ZOOMOUT, self._onXZoomOut)
1881-
wx.EVT_TOOL(self, _NTB_Y_PAN_UP, self._onUpScroll)
1882-
wx.EVT_TOOL(self, _NTB_Y_PAN_DOWN, self._onDownScroll)
1883-
wx.EVT_TOOL(self, _NTB_Y_ZOOMIN, self._onYZoomIn)
1884-
wx.EVT_TOOL(self, _NTB_Y_ZOOMOUT, self._onYZoomOut)
1885-
wx.EVT_TOOL(self, _NTB_SAVE, self._onSave)
1886-
wx.EVT_TOOL_ENTER(self, self.GetId(), self._onEnterTool)
1887-
if can_kill:
1888-
wx.EVT_TOOL(self, _NTB_CLOSE, self._onClose)
1889-
wx.EVT_MOUSEWHEEL(self, self._onMouseWheel)
1815+
bind(self, wx.EVT_TOOL, self._onLeftScroll, id=_NTB_X_PAN_LEFT)
1816+
bind(self, wx.EVT_TOOL, self._onRightScroll, id=_NTB_X_PAN_RIGHT)
1817+
bind(self, wx.EVT_TOOL, self._onXZoomIn, id=_NTB_X_ZOOMIN)
1818+
bind(self, wx.EVT_TOOL, self._onXZoomOut, id=_NTB_X_ZOOMOUT)
1819+
bind(self, wx.EVT_TOOL, self._onUpScroll, id=_NTB_Y_PAN_UP)
1820+
bind(self, wx.EVT_TOOL, self._onDownScroll, id=_NTB_Y_PAN_DOWN)
1821+
bind(self, wx.EVT_TOOL, self._onYZoomIn, id=_NTB_Y_ZOOMIN)
1822+
bind(self, wx.EVT_TOOL, self._onYZoomOut, id=_NTB_Y_ZOOMOUT)
1823+
bind(self, wx.EVT_TOOL, self._onSave, id=_NTB_SAVE)
1824+
bind(self, wx.EVT_TOOL_ENTER, self._onEnterTool, id=self.GetId())
1825+
if can_kill:
1826+
bind(self, wx.EVT_TOOL, self._onClose, id=_NTB_CLOSE)
1827+
bind(self, wx.EVT_MOUSEWHEEL, self._onMouseWheel)
18901828

18911829
def set_active(self, ind):
18921830
"""

0 commit comments

Comments
 (0)