8000 Deduplicate implementation of per-backend Tools. by anntzer · Pull Request #12760 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Deduplicate implementation of per-backend Tools. #12760

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 18, 2019

Conversation

anntzer
Copy link
Contributor
@anntzer anntzer commented Nov 6, 2018

... by reusing the old Toolbar-based implementations.

If toolmanager ever becomes the default we can move the implementations
there and conversely point the old Toolbar-based implementations to use
the Tools.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer added this to the v3.1 milestone Nov 6, 2018
@@ -609,6 +609,8 @@ class NavigationToolbar2Tk(NavigationToolbar2, tk.Frame):
"""
def __init__(self, canvas, window):
self.canvas = canvas
# Avoid using this (prefer self.canvas.manager.window), so that Tool
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Avoid using this (prefer self.canvas.manager.window), so that Tool
# Avoid using self.window (prefer self.canvas.manager.window), so that Tool

Does it make sense to make this a property or are there use-cases where window != self.canvas.manager.window?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I think this attribute should be deprecated (because it is not consistent across backend implementations, so any cross-backend code will need to use self.canvas.manager.window anyways, and that doesn't seem to be so hard to type that you'd also want a property for it (if anything, making the NavigationToolbar APIs consistent across toolkits should be the object of another PR)).

But that's orthogonal to the PR, because the point of the comment is that sometimes, NavigationToolbar methods get called without a true NavigationToolbar as first argument, but a proxy created with _make_classic_style_pseudo_toolbar(), and these won't have a window attribute.

@@ -790,9 +791,6 @@ def hidetip(self):


class RubberbandTk(backend_tools.RubberbandBase):
def __init__(self, *args, **kwargs):
backend_tools.RubberbandBase.__init__(self, *args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

It seems that RubberbandBase does not have an __init__. So technically, this change is possible.

Generally, is it wise not to call super().__init__(). The parent class may later add an __init__() method.

Here in particular, while RubberbandBase does not have __init__(), its parent ToolBase has, which does not get called also with the existing code. That doesn't look right to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will get called even after deleting this code block: when instantiating a RubberbandTk, Python will call RubberbandTk.__init__; because RubberbandTk does not define an __init__, it is inherited by looking up in the base classes; ultimately this resolves to ToolBase.init`.
In other words, the deleted code block does not do anything.

Copy link
Member
@timhoffm timhoffm 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 something should be done about self.window, because having an attribute that should not be used or at least not be used in certain situations is not reasonable. However, changing/deprecating window is beyond the scope of this PR.

With respect to keeping PRs small, I accept the introduced limitation on self.window within this PR. Ideally, we would first have a PR that cares for self.window and merge this PR only after that.

@anntzer
Copy link
Contributor Author
anntzer commented Dec 16, 2018

I have a PR in the works getting rid of the window/parent argument and attribute of the various NavigationToolbar2 subclasses (#12995 is pre-preliminary work for that...). In theory, one could imagine having the toolbar on a different window from the canvas, so it's worth checking what the subclasses do with that information.

  • the wx toolbar is constructed without a window/parent argument (and uses canvas.GetParent() as parent), nothing to fix here.
  • the gtk3 and qt toolbars only uses .parent as parent to the various dialogs it creates (save figure, figure options, etc.) so using the toolbar's parent works just as well.
  • the tk toolbar additionally uses .window to know for which window the cursor should be overridden, but it should just do the same as the other toolkits which is to override the cursor on the window containing the canvas, which is clearly correct anyways.

So overall we can get rid of that argument/attribute without loss of functionality.

... by reusing the old Toolbar-based implementations.

If toolmanager ever becomes the default we can move the implementations
there and conversely point the old Toolbar-based implementations to use
the Tools.
@tacaswell tacaswell merged commit 24524c4 into matplotlib:master Mar 18, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Mar 18, 2019
@anntzer anntzer deleted the deduplicate-tools branch March 18, 2019 20:02
timhoffm added a commit that referenced this pull request Mar 18, 2019
…760-on-v3.1.x

Backport PR #12760 on branch v3.1.x (Deduplicate implementation of per-backend Tools.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0