-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
wx: Fix file extension for toolmanager-style toolbar #28007
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
Conversation
Fixes AppVeyor failure noted in matplotlib#26710 (comment)
Looks like this is still failing in the same way |
Even though the appveyor test is still failing, this PR does fix one bug, so it should be merged. In particular without it, tool icons do not appear when using tool-manager and the wx backend. |
I closed my other PR #28008 (which I made before I saw this one) since the approach here is conceptually better and the other one still has the appveyor error. |
Are we missing a call to FromSVGResource somewhere, perhaps? This seems to be the bridge between an svg and what WX is documented as wanting for most internal tool APIs. (Disclaimer: I've not worked much with wx at all, this is just from a quick reading of the docs) EDIT: I now see we do call FromSVG in the I will note, however, that We may want The File variant does say it is a thin wrapper for |
What is the command to run locally to reproduce the appveyor issue? See my comment in #26710 (comment) |
I am also seeing this upon rectangular selection locally: Traceback (most recent call last):
File "/home/kyle/src/scipy/matplotlib/lib/matplotlib/cbook.py", line 298, in process
func(*args, **kwargs)
File "/home/kyle/src/scipy/matplotlib/lib/matplotlib/backend_tools.py", line 790, in _mouse_move
self.toolmanager.trigger_tool(
File "/home/kyle/src/scipy/matplotlib/lib/matplotlib/backend_managers.py", line 340, in trigger_tool
tool.trigger(sender, canvasevent, data) # Actually trigger Tool.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kyle/src/scipy/matplotlib/lib/matplotlib/backend_tools.py", line 343, in trigger
self.draw_rubberband(*data)
File "/home/kyle/src/scipy/matplotlib/lib/matplotlib/backends/backend_wx.py", line 1266, in draw_rubberband
NavigationToolbar2Wx.draw_rubberband(
File "/home/kyle/src/scipy/matplotlib/lib/matplotlib/backends/backend_wx.py", line 1139, in draw_rubberband
sf = 1 if wx.Platform == '__WXMSW__' else self.GetDPIScaleFactor()
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'types.SimpleNamespace' object has no attribute 'GetDPIScaleFactor' (Only with toolmanager) This traces to the idea of a "pseudo_toolbar" which contains only the canvas, and is ducktyped in to some functions including the rubberbanding. The call style is odd here, but yeah it is something we do... |
(I now also see the manipulation for dark mode to the text of the svg, which explains why File was not used, though the documented signatures are still weird to me) |
I know nothing of this "pseudo_toolbar", but in case it helps, this is the documentation for GetDPIScaleFactor. Perhaps there is another function that we can use that is not wx specific to get the same effect? How is this handled in other backends? |
matplotlib/lib/matplotlib/tests/test_backends_interactive.py Lines 138 to 154 in 1b36177
Aha, the test which is failing is passing a PNG icon in, and there is not any handling of such in |
Nice find! Should we save the file with the extension defined in the |
We don't know what file types might be used in user tool items, so we should correctly handle .png as well. |
Can other backends handle multiple formats? It seems that the current implementation of With respect to fixing the current test, perchaps one possible solution would be not to use PIL to generate the icon, but to use matplotlib itself to generate a figure that we save with the appropriate |
Actually, that's a good question; only GTK defaults to SVG at the moment, though it doesn't fallback to anything with other extensions correctly. It doesn't error out though.
No, this test is specifically about PNG formats; it can't be replicated with SVG, but maybe it should be skipped. On the one hand, people using PNG for their custom tools would be broken here, but on the other this toolbar is experimental. However, it's been that way for many many years, so I think we do need to support it. Fortunately, it seems relatively easy to fall back to the old code if needed. |
This falls back to the previous dark-mode setup for any other formats. It won't be HiDPI compatible, but that's probably not possible for raster formats.
With respect to fixing toolbar-manager, I think the suggestion of falling back to the old code when using non svg images is a good one and FWIW, I am ready to merge this PR. Thank you @QuLogic. |
The separate issue of an exception when using a "pseudo_toolbar" that was mentioned by @ksunden at #28007 (comment) still remains. I do not know about the "pseudo-toolbar" functionality. But based on the stack trace we could try/except the current code and fall back to the display's GetScaleFactor for monitor 0 instead of the display in which the toolbar is being displayed. Or even better the |
PR summary
Fixes AppVeyor failure noted in
#26710 (comment)
This was also broken on non-Windows; it just didn't crash, but instead produced empty buttons.
PR checklist