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

Skip to content

Fix wx_compat code for wxPython >= 4.0.0b2 #9187

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

Merged
merged 5 commits into from
Sep 22, 2017

Conversation

RobinD42
Copy link
Contributor

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.

See: wxWidgets/Phoenix#527

PR Checklist

  • Has Pytest style unit tests
  • 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

longHelpString=tooltip_text,
kind=kind)

if LooseVersion(wx.VERSION_STRING) >= LooseVersion("4.0.0b2"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would all of these work for the old wx as well? In other words, could we just drop the code in the else clause if we decide not to support the beta versions of phoenix (once the actual release of phoenix comes)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. At that point I think there could also be a bit more simplification for Classic wxPython support as well, since the new AddTool signature matches the signature for DoAddTool in Classic. So it would then boil down to just a difference in method names.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the PR accordingly?

Changes to use DoAddTool in Classic, which is the same as AddTool in Phoenix. Includes a note about even more possible simplification when support for all pre-release builds of Phoenix is dropped.
@RobinD42
Copy link
Contributor Author

Additional refactoring implemented, along with a note about what can be removed in the future.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the very clear PR.

@anntzer
Copy link
Contributor

anntzer commented Sep 20, 2017

@RobinD42 Actually you need to fix a minor style nitpick (https://travis-ci.org/matplotlib/matplotlib/jobs/275984202#L3031). You can just drop the second call to LooseVersion, as the first one will implicitly coerce the second one to LooseVersion as well when doing the comparison.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Sep 20, 2017
@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Sep 20, 2017
@tacaswell
Copy link
Member

@RobinD42 Do you mind if I push commits to your branch?

@krlsmnk
Copy link

krlsmnk commented Sep 21, 2017

Hello everyone! I am a CS grad student who is very new to Python and to Github (crazy, I know). I am using wxPython and matplotlib for a research project, and seem to be getting the error described above.

Currently, I have:
Copied entire file contents of "wx_compat.py" into a blank document.
Saved this document, named "wx_compat.py" as a .py file
Moved this file to directory: /matplotlib/backends/wx_compat.py

I am still receiving the error. What am I doing wrong?

@RobinD42
Copy link
Contributor Author

@tacaswell,

Do you mind if I push commits to your branch?

Feel free to do so.

@RobinD42
Copy link
Contributor Author

@krlsmnk,

When you say,

Copied entire file contents of "wx_compat.py" into a blank document.

Where did you get it from? Does it include the changes from this PR?

@krlsmnk
Copy link

krlsmnk commented Sep 21, 2017

From:
https://github.com/RobinD42/matplotlib/blob/f85a6c16fe03025682ab8223ef350443c973451f/lib/matplotlib/backends/wx_compat.py

Says it was updated 21 hours ago; I assume that's the most recent.

@RobinD42
Copy link
Contributor Author

@krischer, I guess the next step would be to ensure that the file you moved into place is actually the one being imported, and not some other one that may be elsewhere on your system. There are various things that can be checked, for example you can import the module in your code and then check its __file__ attribute.

from matplotlib.backends import wx_compat
print(wx_compat.__file__)

@krischer
Copy link
Contributor

@RobinD42 I think you pinged the wrong person ;)

@RobinD42
Copy link
Contributor Author

Oops, that should have been @krlsmnk of course. Too many kr's here I guess. 😉

tacaswell and others added 2 commits September 21, 2017 21:59
The old url only points to sdists now, which caused travis to try
building wxpython itself, with no success.  Wheels are now at the new
url.
@tacaswell
Copy link
Member

Fixed the style issue and moved @anntzer 's commit from #9208 to this PR so it gets test coverage.

@tacaswell tacaswell merged commit 80ffe40 into matplotlib:master Sep 22, 2017
@tacaswell
Copy link
Member

Thanks @RobinD42 !

@tacaswell
Copy link
Member

@meeseeksdev backport to v2.1.x

@lumberbot-app lumberbot-app bot mentioned this pull request Sep 22, 2017
6 tasks
lumberbot-app bot pushed a commit that referenced this pull request Sep 22, 2017
<!--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.-->
tacaswell added a commit that referenced this pull request Sep 22, 2017
@ewan1983
Copy link

File "C:\Anaconda2\lib\site-packages\matplotlib\pyplot.py", line 535, in figure
**kwargs)
File "C:\Anaconda2\lib\site-packages\matplotlib\backends\backend_wxagg.py", line 116, in new_figure_manager
return new_figure_manager_given_figure(num, fig)
File "C:\Anaconda2\lib\site-packages\matplotlib\backends\backend_wxagg.py", line 123, in new_figure_manager_given_figure
frame = FigureFrameWxAgg(num, figure)
File "C:\Anaconda2\lib\site-packages\matplotlib\backends\backend_wx.py", line 1275, in init
self.toolbar = self._get_toolbar(statbar)
File "C:\Anaconda2\lib\site-packages\matplotlib\backends\backend_wxagg.py", line 28, in _get_toolbar
toolbar = NavigationToolbar2WxAgg(self.canvas)
File "C:\Anaconda2\lib\site-packages\matplotlib\backends\backend_wx.py", line 1582, in init
NavigationToolbar2.init(self, canvas)
File "C:\Anaconda2\lib\site-packages\matplotlib\backend_bases.py", line 2760, in init
self._init_toolbar()
File "C:\Anaconda2\lib\site-packages\matplotlib\backends\backend_wx.py", line 1609, in _init_toolbar
tooltip_text)
File "C:\Anaconda2\lib\site-packages\matplotlib\backends\wx_compat.py", line 154, in _AddTool
if not is_phoenix or LooseVersion(wx.VERSION_STRING) >= "4.0.0b2":
File "C:\Anaconda2\lib\distutils\version.py", line 296, in cmp
return cmp(self.version, other.version)
AttributeError: 'unicode' object has no attribute 'version'

Removing LooseVersion solved my problem. Not sure what had happened to my anaconda.

@anntzer
Copy link
Contributor

anntzer commented Sep 25, 2017

Ah the joys of Py2.
str("4.0.0b2") should work.

@krlsmnk
Copy link

krlsmnk commented Sep 25, 2017

So do I import wx_compat in addition to both Matplotlib and wx, or as a replacement for one of them?

I currently commented out my wx import, and imported:
from matplotlib.backends import wx_compat as wx

and app = wx.App(False)
tells me the wx_compat module doesn't have that attribute

J21TK pushed a commit to shopoon/pystat that referenced this pull request Dec 21, 2017
…にしたがってwx_compat.pyを修正してみたが上手くいかず。しかしバグの可能性が高い。
@RobinD42 RobinD42 deleted the fix-AddTool-for-wxPy4.0.0b2 branch January 22, 2018 23:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants