def _widgetclosed( self ): if self.window._destroying: return self.window._destroying = True try: Gcf.destroy(self.num) except AttributeError: pass
def _widgetclosed(self): if self.window._destroying: return self.window._destroying = True map(self.canvas.mpl_disconnect, self._cids) try: Gcf.destroy(self.num) except AttributeError: pass
def __init__(self, canvas, num): self.window = Gtk.Window() super().__init__(canvas, num) self.window.set_wmclass("matplotlib", "Matplotlib") try: self.window.set_icon_from_file(window_icon) except Exception: # Some versions of gtk throw a glib.GError but not all, so I am not # sure how to catch it. I am unhappy doing a blanket catch here, # but am not sure what a better way is - JDH _log.info('Could not load matplotlib icon: %s', sys.exc_info()[1]) self.vbox = Gtk.Box() self.vbox.set_property("orientation", Gtk.Orientation.VERTICAL) self.window.add(self.vbox) self.vbox.show() self.canvas.show() self.vbox.pack_start(self.canvas, True, True, 0) # calculate size for window w = int(self.canvas.figure.bbox.width) h = int(self.canvas.figure.bbox.height) self.toolbar = self._get_toolbar() if self.toolmanager: backend_tools.add_tools_to_manager(self.toolmanager) if self.toolbar: backend_tools.add_tools_to_container(self.toolbar) if self.toolbar is not None: self.toolbar.show() self.vbox.pack_end(self.toolbar, False, False, 0) min_size, nat_size = self.toolbar.get_preferred_size() h += nat_size.height self.window.set_default_size(w, h) self._destroying = False self.window.connect("destroy", lambda *args: Gcf.destroy(self)) self.window.connect("delete_event", lambda *args: Gcf.destroy(self)) if mpl.is_interactive(): self.window.show() self.canvas.draw_idle() self.canvas.grab_focus()
def __init__(self, canvas, num): app = _create_application() self.window = Gtk.Window() app.add_window(self.window) super().__init__(canvas, num) self.window.set_wmclass("matplotlib", "Matplotlib") icon_ext = "png" if sys.platform == "win32" else "svg" self.window.set_icon_from_file( str(cbook._get_data_path(f"images/matplotlib.{icon_ext}"))) self.vbox = Gtk.Box() self.vbox.set_property("orientation", Gtk.Orientation.VERTICAL) self.window.add(self.vbox) self.vbox.show() self.canvas.show() self.vbox.pack_start(self.canvas, True, True, 0) # calculate size for window w = int(self.canvas.figure.bbox.width) h = int(self.canvas.figure.bbox.height) self.toolbar = self._get_toolbar() if self.toolmanager: backend_tools.add_tools_to_manager(self.toolmanager) if self.toolbar: backend_tools.add_tools_to_container(self.toolbar) if self.toolbar is not None: self.toolbar.show() self.vbox.pack_end(self.toolbar, False, False, 0) min_size, nat_size = self.toolbar.get_preferred_size() h += nat_size.height self.window.set_default_size(w, h) self._destroying = False self.window.connect("destroy", lambda *args: Gcf.destroy(self)) self.window.connect("delete_event", lambda *args: Gcf.destroy(self)) if mpl.is_interactive(): self.window.show() self.canvas.draw_idle() self.canvas.grab_focus()
def new_figure_manager_given_figure(num, figure): canvas = FigureCanvasNbAgg(figure) manager = FigureManagerNbAgg(canvas, num) if is_interactive(): manager.show() figure.canvas.draw_idle() canvas.mpl_connect('close_event', lambda event: Gcf.destroy(num)) return manager
def new_figure_manager_given_figure(num, figure): 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', lambda event: Gcf.destroy(num)) return manager
def destroy(self, *args): # check for qApp first, as PySide deletes it in its atexit handler if QApplication.instance() is None: return if self.window._destroying: return self.window._destroying = True if self.toolbar: self.toolbar.destroy() self._ads_observer.observeAll(False) del self._ads_observer self._fig_interaction.disconnect() self.window.close() try: Gcf.destroy(self.num) except AttributeError: pass
def destroy(self, *args): # check for qApp first, as PySide deletes it in its atexit handler if QApplication.instance() is None: return if self.window._destroying: return self.window._destroying = True if self.toolbar: self.toolbar.destroy() self._ads_observer.observeAll(False) del self._ads_observer self._fig_interation.disconnect() self.window.close() try: Gcf.destroy(self.num) except AttributeError: pass
def __init__(self, canvas, num): app = _create_application() self.window = Gtk.Window() app.add_window(self.window) super().__init__(canvas, num) self.vbox = Gtk.Box() self.vbox.set_property("orientation", Gtk.Orientation.VERTICAL) self.window.set_child(self.vbox) self.vbox.prepend(self.canvas) # calculate size for window w = int(self.canvas.figure.bbox.width) h = int(self.canvas.figure.bbox.height) self.toolbar = self._get_toolbar() if self.toolmanager: backend_tools.add_tools_to_manager(self.toolmanager) if self.toolbar: backend_tools.add_tools_to_container(self.toolbar) if self.toolbar is not None: sw = Gtk.ScrolledWindow(vscrollbar_policy=Gtk.PolicyType.NEVER) sw.set_child(self.toolbar) self.vbox.append(sw) min_size, nat_size = self.toolbar.get_preferred_size() h += nat_size.height self.window.set_default_size(w, h) self._destroying = False self.window.connect("destroy", lambda *args: Gcf.destroy(self)) self.window.connect("close-request", lambda *args: Gcf.destroy(self)) if mpl.is_interactive(): self.window.show() self.canvas.draw_idle() self.canvas.grab_focus()
def _close_figure(figure): """ Workaround for matplotlib regression relating to closing figures in Agg See https://github.com/matplotlib/matplotlib/pull/18184/ """ # TODO It would be better to switch the approach based on matplotlib # versions known to have this problem, rather than blindly trying. Update # this once a fixed has been released and we know the earliest version of # matplotlib that does not have this bug. try: figure.canvas.close() except AttributeError: from matplotlib._pylab_helpers import Gcf num = next( (manager.num for manager in Gcf.figs.values() if manager.canvas.figure == figure), None, ) if num is not None: Gcf.destroy(num)
def custom_show_func(*args, **kwargs): managers = Gcf.get_all_fig_managers() for m in managers: self.__all_figures.append(m.canvas.figure) self.__new_figures.append(m.canvas.figure) Gcf.destroy(m.num)
def close(self): Gcf.destroy(self.figman._num)
def destroy(*args): Gcf.destroy(num) self.window.connect("destroy", destroy)
def destroy(*args): Gcf.destroy(self)
def _widgetclosed( self ): if self.window._destroying: return self.window._destroying = True Gcf.destroy(self.num)
def show(self, **kwargs): self.canvas.show() Gcf.destroy(self._num)
def destroy(self): self.window.hide() Fltk.Fl.wait(0) # This is needed to make the last figure vanish. Gcf.destroy(self._num)
def destroy_figure(self, *args): # This is the callback from the gui destroy For this specific figure Gcf.destroy(self.num)
def show(): for manager in Gcf.get_all_fig_managers(): manager.show() Gcf.destroy(manager.num)
def destroy_figure(ptr, figman): figman.window.hide() Fltk.Fl.wait(0) # This is needed to make the last figure vanish. Gcf.destroy(figman._num)
def show(block=None): for manager in Gcf.get_all_fig_managers(): manager.show() # Do not re-display what is already shown. Gcf.destroy(manager.num)
def show(): for manager in Gcf.get_all_fig_managers(): manager.show() Gcf.destroy( manager.num ) # Else every call to figure() will add an extra image produced by every future show()
def destroy(*args): Gcf.destroy(num)
def close_foo(self): try: Gcf.destroy(self) except AttributeError: pass
def destroy(*args): self.window = None Gcf.destroy(self._num)
def _widgetclosed(self): if self.window._destroying: return self.window._destroying = True Gcf.destroy(self.num)
def Destroy(self, *args, **kwargs): self.isdestory = True self.canvas.close_event() self.canvas.stop_event_loop() Gcf.destroy(self.num) return super(MatplotPanel, self).Destroy(*args, **kwargs)
def destroy_figure(ptr, figman): figman.window.hide() Gcf.destroy(figman._num)
def _onClose(self, evt): self.canvas.close_event() self.canvas.stop_event_loop() Gcf.destroy(self.num)
def closer(event): Gcf.destroy(num)
def _trigger_manager_draw(manager): if manager.canvas.figure.get_axes(): manager.show() Gcf.destroy(manager)
def closer(event): Gcf.destroy(0)
def show(): for manager in Gcf.get_all_fig_managers(): manager.show() # TODO(oleg): Check if it's okay to destroy manager here. Gcf.destroy(manager.num)
def close(self): Gcf.destroy(self.num)
def destroy(event): canvas.mpl_disconnect(cid) Gcf.destroy(manager)
def close(self): Gcf.destroy(self) self.canvas.flush_events()