Skip to content

Fix double picks. #19611

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 1 commit into from
Mar 5, 2021
Merged

Fix double picks. #19611

merged 1 commit into from
Mar 5, 2021

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Mar 1, 2021

pick_events were previously incorrectly emitted twice due to the
combination of two recent(ish) chnages: Figures now always start with a
FigureCanvasBase attached -- eventually switching to a concrete subclass
of FigureCanvasBase for display or saving --, and callbacks are now
actually stored at the Figure level rather than the Canvas level.
Hence, the button_pick_id callback (in charge of emitting picks) would
previously be both registered both through the FigureCanvasBase and the
concrete subclass. The fix is to also move that callback to the Figure
level, so that each Figure only has one such callback.

PR Summary

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).

@anntzer anntzer added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Mar 1, 2021
@anntzer anntzer added this to the v3.4.0 milestone Mar 1, 2021
@larsoner
Copy link
Contributor

larsoner commented Mar 1, 2021

This fixes things locally for me both in my "minimal" (though from the test here it clearly wasn't as minimal as it could have been!) and in my real-world usecase subclassing Figure, thanks for the quick fix @anntzer

@@ -2109,6 +2109,10 @@ def __init__(self,
# a proxy property), but that actually need to be on the figure for
# pickling.
self._canvas_callbacks = cbook.CallbackRegistry()
self._button_pick_id = self._canvas_callbacks.connect(
Copy link
Member

Choose a reason for hiding this comment

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

I'm not particularly up on how the callback system works, but this seems intrusive in figure.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The point of #16220 was to move callback handling from the canvas to the figure (for reasons explained in that PR).

@jklymak
Copy link
Member

jklymak commented Mar 1, 2021

Ok, I still think this needs some thought. I think of a figure as a logical container for the axes and figure artists. If we change the semantics to also be the thing that handles mouse interactions that is a pretty big change and just doing it because of pickling, of all features, is irksome 😀

@jklymak
Copy link
Member

jklymak commented Mar 4, 2021

.. I mean I guess it has to pass CI...

pick_events were previously incorrectly emitted twice due to the
combination of two recent(ish) chnages: Figures now always start with a
FigureCanvasBase attached -- eventually switching to a concrete subclass
of FigureCanvasBase for display or saving --, and callbacks are now
actually stored at the Figure level rather than the Canvas level.
Hence, the button_pick_id callback (in charge of emitting picks) would
previously be both registered both through the FigureCanvasBase and the
concrete subclass.  The fix is to also move that callback to the Figure
level, so that each Figure only has one such callback.
@QuLogic QuLogic merged commit d195747 into matplotlib:master Mar 5, 2021
@QuLogic
Copy link
Member

QuLogic commented Mar 5, 2021

Not sure why this didn't backport.

@meeseeksdev backport to v3.4.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants