-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement FigureManager.resize for macosx backend #16992
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
Instead of manually adding tracking rectangles and updating for resize (older API), use a "newer" API (added OSX 10.5) for tracking areas. With the right flags, these areas are automatically updated for resize.
Just set some resizing flags on the view. This allows us to avoid manually resizing the view.
We can just request these events from the tracking area rather than manually enabling/disabling mouse move/checking inside.
Rename _device_scale to _dpi_ratio, as expected by Figure.set_size_inches(). Also, make sure the value of _dpi_ratio on instances of FigureCanvasMac are updated *before* setting figure DPI so that the proper value is available for downstream code. This is part of the fix needed to make set_size_inches work on macosx.
This allows Figure.set_size_inches to work.
Tagging 3.3 since the underlying issue is tagged 3.3. Would be nice to get the issue closed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works and the code seems fine.
I have no idea what the OK< sorry this was in the commit message.Rect
stuff is supposed to be doing, and seems unrelated. OTOH I couldn't see that it broke anything. Some explanation would be helpful....
Just given this a spin and it seems to work well. The only thing I've noticed is if I resize the window to have zero height, I get a bunch of messages like: File "/Users/dstansby/github/matplotlib/lib/matplotlib/figure.py", line 879, in set_size_inches
raise ValueError(f'figure size must be positive finite not {size}')
ValueError: figure size must be positive finite not [ 5.65 -0.34]
Traceback (most recent call last):
File "/Users/dstansby/github/matplotlib/lib/matplotlib/backends/backend_macosx.py", line 84, in resize
forward=False)
File "/Users/dstansby/github/matplotlib/lib/matplotlib/figure.py", line 879, in set_size_inches
raise ValueError(f'figure size must be positive finite not {size}')
ValueError: figure size must be positive finite not [ 5.6 -0.19] |
@dstansby We currently expect figures to have a finite height and width. However that may change, see #17093 (comment). |
In other backends (WebAgg, specifically), there are minimum sizes on the window so you can't do that. |
Yeah, I'm guessing the backend should enforce >0 figure height and width. |
So is that a requested change on this PR? |
I think it would be good to enforce a finite size for this PR, so that we can get it still into 3.3. There are considerations elsewhere to drop that limitations, but that needs additional changes in the code. |
@tacaswell Should be no interaction between this and either of those other two. @timhoffm To be clear, this PR does not make the
(just grab the upper right corner and drag down and to the left past the lower left corner.) I can do it if strictly necessary, but it's not a new issue introduced by this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't judge the Objective C changes, but in a simple test, the code works for me and solves the original problem of the mismatch between window size and figure size.
I'm going to merge then; finite size requirements can be a separate new PR. |
PR Summary
PR Checklist
Fixes #15131. In addition to implementing the missing method there are also a few clean-ups here for the macosx backend. This also depends on fixing handling of
Figure.dpi
changes in #16971 or #16972.