Skip to content
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

Remove visibility changes in draw for *Cursor widgets #19763

Merged
merged 2 commits into from Dec 16, 2022

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Mar 24, 2021

PR Summary

This can be all handled in the mouse move event handler instead, and prevents triggering extra draws in nbAgg.

Fixes #19633.

Additionally, mark access to said event handlers as deprecated.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [n/a] 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).
  • [n/a] 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).

if self.ignore(event):
return
if event.inaxes not in self.axes:
return
if not self.canvas.widgetlock.available(self):
return
self.needclear = True
if not self.visible:
Copy link
Member

Choose a reason for hiding this comment

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

Why drop this?

Copy link
Member

Choose a reason for hiding this comment

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

I think we want to keep this short-circuit to avoid going to _update which avoids a draw_idle down the line.

Copy link
Member

Choose a reason for hiding this comment

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

If that's the case, we might want to clarify that for our future selves with a comment.

Copy link
Member Author

@QuLogic QuLogic Mar 26, 2021

Choose a reason for hiding this comment

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

Well, we want to remove it from here so that the later .set_visible is effective. I'll see if we can still skip the _update at least. Alternatively, we should turn the visibility attributes into property setters.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see now. We used to always make the lines not visible so if not self.visible we could safely bail.

Do we need some more careful logic on this like to call self._update() if visible or just made invisible? I suspect there is now also some path where we can set self.vertOn or self.horizOn to False and then they never get removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

I re-added a condition on the _update calls, which is hopefully sufficient.

@jklymak
Copy link
Member

jklymak commented May 11, 2021

ping @ianhi or @anntzer for a second review here?

def onmove(self, event):
onmove = _api.deprecate_privatize_attribute('3.5')

def _onmove(self, event):
if self.ignore(event):
return
if event.inaxes not in self.axes:
return
if not self.canvas.widgetlock.available(self):
return
self.needclear = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Sidenote but as far as I can tell self.needclear is never actually used in MultiCursor

Copy link
Contributor

@ianhi ianhi left a comment

Choose a reason for hiding this comment

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

I think this has introduced some incorrect behavior where the cursor is not removed when the mouse leaves the axes. Also @tacaswell noted:

Do we need some more careful logic on this like to call self._update() if visible or just made invisible? I suspect there is now also some path where we can set self.vertOn or self.horizOn to False and then they never get removed

I found that moving the cursor around and then setting multi.horizOn = False leaves an artifact:

horizOn

@QuLogic
Copy link
Member Author

QuLogic commented May 12, 2021

Hmm, I tested changing those settings, but it may have been only while the mouse was already over the window.

@jklymak jklymak marked this pull request as draft May 13, 2021 14:17
@QuLogic QuLogic modified the milestones: v3.5.0, v3.6.0 Aug 23, 2021
@QuLogic QuLogic modified the milestones: v3.6.0, v3.7.0 Jul 5, 2022
This can be all handled in the mouse move event handler instead, and
prevents triggering extra draws in nbAgg.

Fixes matplotlib#19633.
@tacaswell
Copy link
Member

Pro: rebased
Con: can still reproduce the issues @ianhi reported with disabling the horizontal line

I'm half inclined to merge this even with that issue as this is still a big step forward.

@ianhi
Copy link
Contributor

ianhi commented Dec 16, 2022

I'm half inclined to merge this even with that issue as this is still a big step forward.

🚀 🚀 🚀 🚀 🚀 - the power to blit in notebooks awaits!

@tacaswell tacaswell marked this pull request as ready for review December 16, 2022 16:24
@tacaswell
Copy link
Member

Given Ian's comment I marked this non-draft and approved. I'm holding off on merging at @timhoffm 's review is very old now so this should get another set of eyes.

@tacaswell tacaswell merged commit c1588e6 into matplotlib:main Dec 16, 2022
@QuLogic QuLogic deleted the widget-events branch December 17, 2022 00:44
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Dec 17, 2022
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Dec 30, 2022
By implementing `_onmove` in a similar manner to `Cursor`.

Followup to matplotlib#19763.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Dec 30, 2022
By implementing `_onmove` in a similar manner to `Cursor`. Also,
deprecate the related `needclear` attribute in both widgets.

Followup to matplotlib#19763.
@QuLogic
Copy link
Member Author

QuLogic commented Dec 30, 2022

I followed up on both @ianhi's issues in #24845.

raphaelquast pushed a commit to raphaelquast/matplotlib that referenced this pull request Mar 16, 2023
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.

Multicursor disappears when not moving on nbagg with useblit=False + burns CPU
5 participants