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

Skip to content

Remove custom backend_nbagg.show(), putting logic in manager show. #23100

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
Jun 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 9 additions & 24 deletions lib/matplotlib/backends/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ def show(self):
else:
self.canvas.draw_idle()
self._shown = True
# plt.figure adds an event which makes the figure in focus the active
# one. Disable this behaviour, as it results in figures being put as
# the active figure after they have been shown, even in non-interactive
# mode.
if hasattr(self, '_cidgcf'):
Copy link
Member

Choose a reason for hiding this comment

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

Is there any way to add tests to argue that this is working as expected?

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, there was previously no test coverage for the corresponding old code paths (as can be checked e.g. via pytest --cov --pyargs matplotlib.tests.test_backend_nbagg && coverage html: the entire show() function was untested), so I'll ask for an out there and just point out that I simply moved some code around (also, my understanding of nbagg is on the weaker side...).

Copy link
Member

Choose a reason for hiding this comment

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

fair.

self.canvas.mpl_disconnect(self._cidgcf)
if not is_interactive():
from matplotlib._pylab_helpers import Gcf
Gcf.figs.pop(self.num, None)

def reshow(self):
"""
Expand Down Expand Up @@ -232,27 +241,3 @@ def on_message(self, message):
class _BackendNbAgg(_Backend):
FigureCanvas = FigureCanvasNbAgg
FigureManager = FigureManagerNbAgg

@staticmethod
def show(block=None):
## TODO: something to do when keyword block==False ?
from matplotlib._pylab_helpers import Gcf

managers = Gcf.get_all_fig_managers()
if not managers:
return

interactive = is_interactive()

for manager in managers:
manager.show()

# plt.figure adds an event which makes the figure in focus the
# active one. Disable this behaviour, as it results in
# figures being put as the active figure after they have been
# shown, even in non-interactive mode.
if hasattr(manager, '_cidgcf'):
manager.canvas.mpl_disconnect(manager._cidgcf)

if not interactive:
Gcf.figs.pop(manager.num, None)