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

Skip to content

Commit 5d0d3f5

Browse files
tacaswellMeeseeksDev[bot]
authored and
MeeseeksDev[bot]
committed
Backport PR #9187: Fix wx_compat code for wxPython >= 4.0.0b2
<!--Thank you so much for your PR! To help us review, fill out the form to the best of your ability. Please make use of the development guide at https://matplotlib.org/devdocs/devel/index.html--> <!--Provide a general summary of your changes in the title above, for example "Raises ValueError on Non-Numeric Input to set_xlim". Please avoid non-descriptive titles such as "Addresses issue 8576".--> <!--If you are able to do so, please do not create the PR out of master, but out of a separate branch. See https://matplotlib.org/devel/gitwash/development_workflow.html for instructions.--> PR Summary Some arg names in `wx.ToolBar.AddTool` are being changed in order to be more consistent with other tool methods, and also for better compatibility with Classic. This change trips up the code in `wx_compat` since it is using keyword args when calling `AddTool`. This PR is one possible fix. Another would be to not use the keyword args and just use positional args since the order and types have not changed. <!--If it fixes an open issue, please link to the issue here.--> See: wxWidgets/Phoenix#527 PR Checklist - [ ] Has Pytest style unit tests - [x] Code is PEP 8 compliant - [ ] New features are documented, with examples if plot related - [ ] Documentation is sphinx and numpydoc compliant - [ ] Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there) - [ ] Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way <!--We understand that PRs can sometimes be overwhelming, especially as the reviews start coming in. Please let us know if the reviews are unclear or the recommended next step seems overly demanding , or if you would like help in addressing a reviewer's comments. And please ping us if you've been waiting too long to hear back on your PR.-->
1 parent cb9ddbc commit 5d0d3f5

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)