Skip to content

MNT: Clean up macosx backend set_message #21755

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 2 commits into from
May 26, 2022

Conversation

greglucas
Copy link
Contributor

@greglucas greglucas commented Nov 25, 2021

PR Summary

Remove some unnecessary calculations and add some comments. Switch
to string passing since we are guaranteed UTF-8 with Python 3 now.

Set text alignment to the right, which matches the qt5agg backend.

Closes #20797

PR Checklist

Tests and Styling

  • [N/A] Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • [N/A] New features are documented, with examples if plot related.
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • [N/A] Documentation is sphinx and numpydoc compliant (the docs should build without error).

@greglucas greglucas added this to the v3.6.0 milestone Nov 25, 2021
rect.size.width = rectWindow.size.width - rect.origin.x;
[messagebox setFrame: rect];
Copy link
Member

Choose a reason for hiding this comment

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

The text will wrap depending on width, which is why this width must be set before asking for the height. That is, unless text wrapping is off? But then I guess we would not care about setting the height, so it seems that removing this line will break things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, updated. This is needed if we want to center the text vertically properly based on window resizes.

@greglucas
Copy link
Contributor Author

OK, I was able to dig into the cursor updates, and I think the root of the issue is that there is a cursor update event being fired from within the objc code, but we really want to keep control of the cursor changes on the MPL side. So, if we disable the cursorRect that removes the event and fixes the cursor issues we were seeing in #20797, see the final commit: 70a8e32

Remove some unnecessary calculations and add some comments. Switch
to string passing since we are guaranteed UTF-8 with Python 3 now.
@greglucas greglucas force-pushed the macosx-message-box branch from 70a8e32 to 662642c Compare May 15, 2022 13:43
@greglucas
Copy link
Contributor Author

@dstansby, pinging you for a review since you mentioned you had a mac to test this out with. Anyone else with a mac is welcome to test this too!

  • When hovering over the image and the contour you should see the message text centered vertically and right-aligned. It should adjust to one/two lines seamlessly.
  • When pressing the zoom or pan button. The image should now update the cursor properly when hovering over the image (contour / imshow should behave the same now). Previously, the imshow cursor did not update to the open/closed hand on pan.
import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(ncols=2)

ax1.imshow([[0, 1], [2, 3]])
ax2.contourf([[0, 1], [2, 3]])

plt.show()

@dstansby dstansby self-requested a review May 15, 2022 16:08
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

This works as advertised. I didn't dig too deeply into the code as I'm not versant in ObjectiveC.

We want to keep control of the cursor updates from within MPL, so
don't allow the App to push a new cursor update when the window
gets updated. This would happen when a TextView would get resized
and update the frame.
@greglucas greglucas force-pushed the macosx-message-box branch from 662642c to 5dcdcb8 Compare May 18, 2022 17:48
@jklymak jklymak merged commit bcef5d6 into matplotlib:main May 26, 2022
@greglucas greglucas deleted the macosx-message-box branch May 26, 2022 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

macosx cursors break with images
3 participants