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

Skip to content

FIX : first pass at fixing nbagg close issue #4456

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 6 commits into from
Aug 17, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
FIX : first pass at fixing nbagg close issue
Add callback to destroy figure when the user hits the red x
in the notebook.

This is not the correct solution, but it (might) work for now.
  • Loading branch information
tacaswell committed Aug 17, 2015
commit bd0a3f8de6e40bf595bf5fd2be7712d24df65f8c
10 changes: 10 additions & 0 deletions lib/matplotlib/backends/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,22 @@ def new_figure_manager_given_figure(num, figure):
"""
Create a new figure manager instance for the given figure.
"""
from .._pylab_helpers import Gcf

def closer(event):
Gcf.destroy(num)

canvas = FigureCanvasNbAgg(figure)
if rcParams['nbagg.transparent']:
figure.patch.set_alpha(0)
manager = FigureManagerNbAgg(canvas, num)

if is_interactive():
manager.show()
figure.canvas.draw_idle()

canvas.mpl_connect('close_event', closer)

return manager


Expand Down Expand Up @@ -298,6 +307,7 @@ def on_message(self, message):
message = json.loads(message['content']['data'])
if message['type'] == 'closing':
self.on_close()
self.manager.canvas.close_event()
Copy link
Member

Choose a reason for hiding this comment

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

Just curious: why is this down here instead of inside the on_close() method?

Copy link
Member Author

Choose a reason for hiding this comment

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

moved

elif message['type'] == 'supports_binary':
self.supports_binary = message['value']
else:
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/backends/backend_webagg_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ def handle_event(self, event):
self.send_event('figure_label', label=figure_label)
self._force_full = True
self.draw_idle()

else:
handler = getattr(self, 'handle_{0}'.format(e_type), None)
if handler is None:
Expand Down