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

Skip to content

Set the canvas cursor when using a SpanSelector #20743

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
Jul 27, 2021

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jul 27, 2021

PR Summary

This sets either a horizontal or vertcal resize cursor when initiating a selection, moving the span, or when hovering over an end handle.

This is half of #20724.

I said I was going to move things to ToolLineHandles, but there are two reasons why I didn't:

  • It doesn't have grab_range, which is needed for determining when we're hovering.
  • It doesn't have access to the parent widget, so can't know when it's inactive, or a handle is already active.

I could propagate the information over, but seemed like more work than just handling the cursor entirely in the SpanSelector widget. I could finish moving it if we think that makes a better design.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@QuLogic QuLogic added this to the v3.5.0 milestone Jul 27, 2021
@anntzer
Copy link
Contributor

anntzer commented Jul 27, 2021

more work than just handling the cursor entirely in the SpanSelector widget

Agreed, I don't think it's worth the pain.

return

if self._active_handle is not None:
# Do nothing if button is pressed and a handle is active.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not really sure what this case is supposed to handle?

Copy link
Member Author

@QuLogic QuLogic Jul 27, 2021

Choose a reason for hiding this comment

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

When you're dragging, the cursor stays as the resizer. If you're dragging and move close enough to an edge before the selector moves, then it could trigger the hover effect and disable the resize cursor even though the selector is still active. I think this may only apply if you are dragging from the centre.

A simple check for if you remove this bit: start dragging within an existing span, but just a little outside the grab range, the cursor will be a resize. If you move towards the handle and back again (might need to do this quick-ish), it will revert back to a pointer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see, perhaps just add a comment to note that this is to handle draw_from_anywhere=True? (which I had missed)
I can't repro it locally but I guess that depends on mouse latency.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I'm using X forwarding (though still on the local network), so there may be some delay between events.

Copy link
Member

@ericpre ericpre left a comment

Choose a reason for hiding this comment

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

It raises an error when it is used with interactive=False:

  File "/home/eric/Dev/others/matplotlib/lib/matplotlib/widgets.py", line 2298, in _hover
    _, e_dist = self._edge_handles.closest(event.x, event.y)
AttributeError: 'SpanSelector' object has no attribute '_edge_handles'

Would it be possible/make sense to add it to the base class (_SelectorWidget), so it can be used by the RectangleSelector?
It seems that there is no REZISE_DIAGONALE in the Cursors class, so it may not work very well. In any case, it may not be necessary neither because, the RectangleSelector has marker as handle and it is clear visual indicator that it can be use to resize the selector!

This sets either a horizontal or vertcal resize cursor when initiating a
selection, moving the span, or when hovering over an end handle.
@QuLogic
Copy link
Member Author

QuLogic commented Jul 27, 2021

The RectangleSelector would need a different implementation, as it would have to pick the right directional cursors depending on anchor point. Also, when #19864 is done, it would be even more complex.

I've fixed the other two issues.

@ericpre
Copy link
Member

ericpre commented Jul 27, 2021

The RectangleSelector would need a different implementation, as it would have to pick the right directional cursors depending on anchor point. Also, when #19864 is done, it would be even more complex.

Yes, indeed!

@anntzer anntzer merged commit 27ab013 into matplotlib:master Jul 27, 2021
@ericpre
Copy link
Member

ericpre commented Jul 27, 2021

This is half of #20724.

@QuLogic, by saying, "this is half of #20724", are you referring to the Toolhandles? If so, it seems that this will not happen? I am wondering if #20724 should be closed.

@QuLogic QuLogic deleted the span-cursor branch July 27, 2021 21:56
@QuLogic
Copy link
Member Author

QuLogic commented Jul 27, 2021

Yes, I may still do that one, but need to experiment a bit to see how easy it is.

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.

3 participants