Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Change cursor when hovering over draggable artists#25412

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
daniilS wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromdaniilS:draggable-cursor

Conversation

daniilS
Copy link
Contributor

PR Summary

Currently, there's no visual indication that an artist is draggable. This sets the cursor toCursors.MOVE when the mouse is hovering over aDraggableBase instance which can be picked.

A possible addition would be to set the widget lock inon_pick() untilon_release(), which would prevent other draggables/widgets/toolbar modes from being active at the same time, but I wasn't sure if there is a reason thatwidgetlock isn't already being used.

draggable.legend.webm

Copy link
Contributor

@greglucasgreglucas left a comment

Choose a reason for hiding this comment

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

This is nice to know that you can interact with the component 👍

@greglucas
Copy link
Contributor

I was using the code from#25428 (comment) to test this.

importmatplotlib.pyplotaspltplt.plot(range(5),label='bob')leg=plt.legend()leg.set_draggable(True,update='bbox')plt.show()

@QuLogic
Copy link
Member

Maybe this should get a.. versionmodified:: annotation inset_draggable?

@daniilS
Copy link
ContributorAuthor

@greglucas , I had a look at the macosx issue, and this is what's going on:

  • NavigationToolbar2._update_cursor() setsNavigationToolbar2._last_cursor only when the mouse moves and the current tool requires a different cursor than the current value of_last_cursor.
  • NavigationToolbar2._wait_cursor_for_draw_cm() resets the cursor to_last_cursor after drawing is finished, thus undoing any changes made throughFigureCanvas.set_cursor().
  • Example scripts (1,2) solve this by callingset_cursor() every time the mouse is moved. However, this doesn't work for the specific case ofCursors.MOVE on the macosx backend: the backend changes the open hand cursor to a closed hand when the mouse is pressed. Callingset_cursor() every mouse move resets it to an open hand, but not doing that resets it to_last_cursor instead.

I think the solution might be for the macosx backend'sFigureCanvas_set_cursor() to mapCursors.MOVE to the closed hand cursor if the mouse is currently pressed. Unless anyone can think of a time when this would be undesired?

On a related note,@QuLogic, should_last_cursor and_wait_cursor_for_draw_cm() be moved fromNavigationToolbar2 toFigureCanvas in line with#20620? Thenset_cursor() could update_last_cursor not just for the toolbar, and only actually change the cursor when necessary, but I'm not sure if widgets updating the cursor constantly even has significant overhead on any backends. Though that would have the issue that if any use case for some reason changes the cursor while a toolbar tool is active, it would need to change the cursor back to the tool's cursor afterwards.

@greglucas
Copy link
Contributor

@daniilS lets keep the macosx issues discussed in the linked PR for that. I think this is a useful addition still and just needs a rebase at this point.

@QuLogic
Copy link
Member

I think you might need to rebase, as there seems to be some extra commits here. We have some instructions for that here:https://matplotlib.org/devdocs/devel/development_workflow.html#rewriting-commit-history

@daniilSdaniilSforce-pushed thedraggable-cursor branch 2 times, most recently from80b0af1 to8ce6c89CompareJuly 7, 2023 14:11
@daniilS
Copy link
ContributorAuthor

Fixed the rebase. However, I found that this PR reveals a different issue withDraggableBase: when a figure or axes is removed,disconnect() never gets called, leaving the callbacks in place, so the mouse cursor keeps changing when hovering over the place where the legend used to be. An example (video shown below):

importmatplotlib.pyplotaspltline=plt.plot(range(3),label="line")[0]leg=plt.legend(draggable=True,loc="upper center",fontsize="xx-large",mode="expand")plt.show(block=False)plt.pause(1)plt.clf()plt.show()# cursor still changes when hovering over the top of the figure

I think a hook should be added somewhere to calldisconnect() when the associated artist is removed, but I'm not sure where would be a good place.

draggable_bug.webm

@anntzer
Copy link
Contributor

Perhaps _Axes._remove_legend? (via _legend._remove_method)

@daniilSdaniilSforce-pushed thedraggable-cursor branch 2 times, most recently fromd76c7d9 to0bcfe16CompareJuly 25, 2023 00:34
@daniilS
Copy link
ContributorAuthor

@anntzer thanks, that pointed me towards what I think is the right place! It looks to me like the best solution is to deparent the legend together with other artists in_AxesBase.__clear() following#24627.@tacaswell, can I just check that I'm not overlooking anything in case the legend deliberately wasn't included in that commit?

Co-Authored-By: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Comment on lines +1515 to +1520
if not (
self._check_still_parented()
and self.canvas.widgetlock.available(self)
and self.ref_artist.pickable()
):
return
Copy link
Member

@timhoffmtimhoffmAug 1, 2023
edited
Loading

Choose a reason for hiding this comment

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

Is the logic correct? Ifself.ref_artist.pickable() is False, we return. That means we never reach the originalif self.got_artist: branch.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timhoffmtimhoffmtimhoffm left review comments

@greglucasgreglucasgreglucas left review comments

@QuLogicQuLogicQuLogic approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@daniilS@greglucas@QuLogic@anntzer@timhoffm@melissawm

[8]ページ先頭

©2009-2025 Movatter.jp