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

Skip to content

Dedupe window-title setting by moving it to FigureManagerBase. #15212

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
Dec 25, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Sep 7, 2019

PR Summary

Probably someone on macOS should check that this works on the macos backend.

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

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'm feeling slightly uncomforable that FigureManagerBase.__init__ now relies on subclasses having set the window attribute already. In fact, wouldn't that break external figure managers?

Probably the better and more explicit way would be to have a FigureManagerBase.post_init() that set's the window title and let all backends call that.

Alternatively, we could pass the window to FigureManagerBase.__init__ and set the attribute there.

@anntzer
Copy link
Contributor Author

anntzer commented Sep 7, 2019

I'm feeling slightly uncomforable that FigureManagerBase.init now relies on subclasses having set the window attribute already. In fact, wouldn't that break external figure managers?

Technically this only requires that set_window_title works by the time the base class init is called, but sure. We could wrap the call to set_window_title in the base class into a try... except and emit a deprecation warning if an exception is raised, to handle the case of third-party managers. A quick look shows that this would not affect either ipython's inline backend or pycharm's interagg backend, though, as they don't touch any of these.

Probably the better and more explicit way would be to have a FigureManagerBase.post_init() that set's the window title and let all backends call that.

That seems to make the coupling even worse, IMO.

Alternatively, we could pass the window to FigureManagerBase.init and set the attribute there.

I think that also breaks backcompat, and actually also break third-party backends as soon as they pass parameters up to the super class, regardless of whether this mattered to them? Also note that noninteractive backends have no notion of "window".

@timhoffm
Copy link
Member

timhoffm commented Sep 7, 2019

Try except + documenting that set_window_title() must/should* work for the base class init would technically be ok (*well it's ok, to not work because of try-except but then you loose the window title). Then again, this is such a strange documentation/requirement, that it hints at some design problem:

Either the base class should take full ownership and API responsibility for the window or none at all; i.e. either both define self.window and apply self.set_window_title() or do nothing at all.

Is there any reason not to do FigrureManagerBase:

def __init__(self, canvas, num, *, window=None):
    ...
    self.window = window
    if hasattr(self, 'set_window_title'):
        self.set_window_title(...)

if you really don't want self.window in the base class, we should introduce an intermediate WindowFigureManager class.

@anntzer
Copy link
Contributor Author

anntzer commented Sep 7, 2019

well it's ok, to not work because of try-except but then you loose the window title

No, because if you're on an old-style class that doesn't allow this pattern, then that class was in charge of calling set_window_title itself anyways. (The point is to later get rid of the try except and error out if a subclass doesn't allow this.)

Is there any reason not to do FigrureManagerBase: (elided)

Because set_window_title is defined in the base class, so that doesn't work anyways. Actually '.window' is not an attribute we document to be present and indeed for example FigureManagerMac has no such attribute.

@tacaswell tacaswell added this to the v3.4.0 milestone Jun 26, 2020
@jklymak jklymak marked this pull request as draft August 24, 2020 14:59
@anntzer
Copy link
Contributor Author

anntzer commented Oct 7, 2020

rebased

@anntzer anntzer marked this pull request as ready for review October 31, 2020 11:35
@efiring
Copy link
Member

efiring commented Dec 25, 2020

I have verified that this works on the MacOSX backend on my machine, Catalina, 10.15.7. I can change the window title with, for example, fig.canvas.manager.set_window_title('testing 1234').

@jklymak jklymak merged commit fef9502 into matplotlib:master Dec 25, 2020
@anntzer anntzer deleted the set_window_title branch December 25, 2020 21:15
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.

6 participants