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

Skip to content

Commit 80ffe40

Browse files
authored
Merge pull request #9187 from RobinD42/fix-AddTool-for-wxPy4.0.0b2
Fix wx_compat code for wxPython >= 4.0.0b2
2 parents ffa4803 + a6f38ab commit 80ffe40

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ install:
124124
echo 'PyQt5 is available' ||
125125
echo 'PyQt5 is not available'
126126
pip install -U --pre \
127-
-f https://wxpython.org/Phoenix/release-extras/linux/gtk3/ubuntu-14.04 \
127+
-f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-14.04 \
128128
wxPython &&
129129
python -c 'import wx' &&
130130
echo 'wxPython is available' ||

lib/matplotlib/backends/wx_compat.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,36 @@
139139
StockCursor = wx.StockCursor
140140

141141

142+
# wxPython Classic's DoAddTool has become AddTool in Phoenix. Otherwise
143+
# they are the same, except for early betas and prerelease builds of
144+
# Phoenix. This function provides a shim that does the RightThing based on
145+
# which wxPython is in use.
142146
def _AddTool(parent, wx_ids, text, bmp, tooltip_text):
147+
if text in ['Pan', 'Zoom']:
148+
kind = wx.ITEM_CHECK
149+
else:
150+
kind = wx.ITEM_NORMAL
143151
if is_phoenix:
144-
if text in ['Pan', 'Zoom']:
145-
kind = wx.ITEM_CHECK
146-
else:
147-
kind = wx.ITEM_NORMAL
148-
parent.AddTool(wx_ids[text], label=text,
149-
bitmap=bmp,
150-
bmpDisabled=wx.NullBitmap,
151-
shortHelpString=text,
152-
longHelpString=tooltip_text,
153-
kind=kind)
152+
add_tool = parent.AddTool
153+
else:
154+
add_tool = parent.DoAddTool
155+
156+
if not is_phoenix or LooseVersion(wx.VERSION_STRING) >= "4.0.0b2":
157+
# NOTE: when support for Phoenix prior to 4.0.0b2 is dropped then
158+
# all that is needed is this clause, and the if and else clause can
159+
# be removed.
160+
kwargs = dict(label=text,
161+
bitmap=bmp,
162+
bmpDisabled=wx.NullBitmap,
163+
shortHelp=text,
164+
longHelp=tooltip_text,
165+
kind=kind)
154166
else:
155-
if text in ['Pan', 'Zoom']:
156-
parent.AddCheckTool(
157-
wx_ids[text],
158-
bmp,
159-
shortHelp=text,
160-
longHelp=tooltip_text)
161-
else:
162-
parent.AddSimpleTool(wx_ids[text], bmp, text, tooltip_text)
167+
kwargs = dict(label=text,
168+
bitmap=bmp,
169+
bmpDisabled=wx.NullBitmap,
170+
shortHelpString=text,
171+
longHelpString=tooltip_text,
172+
kind=kind)
173+
174+
return add_tool(wx_ids[text], **kwargs)

0 commit comments

Comments
 (0)