Skip to content

BUG: Use manager to set title #958

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
Sep 17, 2020
Merged

BUG: Use manager to set title #958

merged 1 commit into from
Sep 17, 2020

Conversation

larsoner
Copy link
Contributor

Deal with mpl deprecation:

  File "/home/larsoner/python/nibabel/nibabel/viewers.py", line 122, in __init__
    fig.canvas.set_window_title(str(title))
  File "/home/larsoner/python/matplotlib/lib/matplotlib/cbook/deprecation.py", line 233, in wrapper
    _warn_external(warning)
  File "/home/larsoner/python/matplotlib/lib/matplotlib/cbook/__init__.py", line 2120, in _warn_external
    warnings.warn(message, category, stacklevel)
matplotlib.cbook.deprecation.MatplotlibDeprecationWarning: 
The set_window_title function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use manager.set_window_title or GUI-specific methods instead.

@codecov
Copy link

codecov bot commented Sep 16, 2020

Codecov Report

Merging #958 into master will not change coverage.
The diff coverage is 0.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #958   +/-   ##
=======================================
  Coverage   91.87%   91.87%           
=======================================
  Files          98       98           
  Lines       12451    12451           
  Branches     2193     2193           
=======================================
  Hits        11439    11439           
  Misses        678      678           
  Partials      334      334           
Impacted Files Coverage Δ
nibabel/viewers.py 96.14% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f918b1...c74aaca. Read the comment docs.

@@ -118,8 +118,8 @@ def __init__(self, data, affine=None, axes=None, title=None):
if self.n_volumes <= 1:
fig.delaxes(self._axes[3])
self._axes.pop(-1)
if self._title is not None:
fig.canvas.set_window_title(str(title))
if self._title is not None and fig.canvas.manager is not None:
Copy link
Member

@effigies effigies Sep 16, 2020

Choose a reason for hiding this comment

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

Is there a case where fig.canvas.manager can be None?

I've installed the minimum matplotlib (1.5.3) in a dev environment, and matplotlib.pyplot.gcf().canvas.manager resolved fine. If this was being conservative to support older versions, then we can probably drop it. If there are configurations where it can actually be None, then we should keep it.

Copy link
Contributor Author

@larsoner larsoner Sep 16, 2020

Choose a reason for hiding this comment

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

I think if you instantiate the figure instance yourself (e.g., to embed in a Qt application of your own) instead of going through pyplot it's probably None. I haven't checked but there is probably some condition like this that causes it to be None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Verified that indeed fig.canvas.manager is None if you embed on your own. But then I noticed that this code is in a block where we directly create fig using pyplot, so indeed we should be good to remove the conditional (I hope/presume)!

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@effigies effigies merged commit 7c7962b into nipy:master Sep 17, 2020
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.

2 participants