diff --git a/qt/applications/workbench/workbench/plotting/figuremanager.py b/qt/applications/workbench/workbench/plotting/figuremanager.py index 190771401206aefd22fe0a1b4434d879cfdd81b1..de9cee389add85d3f88ee0c14670d2bfc4e06005 100644 --- a/qt/applications/workbench/workbench/plotting/figuremanager.py +++ b/qt/applications/workbench/workbench/plotting/figuremanager.py @@ -150,9 +150,6 @@ class FigureManagerWorkbench(FigureManagerBase, QObject): self.window.addToolBar(self.toolbar) self.toolbar.message.connect(self.statusbar_label.setText) self.toolbar.sig_grid_toggle_triggered.connect(self.grid_toggle) - if hasattr(Gcf, 'set_hold'): - self.toolbar.sig_hold_triggered.connect(functools.partial(Gcf.set_hold, self)) - self.toolbar.sig_active_triggered.connect(functools.partial(Gcf.set_active, self)) tbs_height = self.toolbar.sizeHint().height() else: tbs_height = 0 diff --git a/qt/applications/workbench/workbench/plotting/globalfiguremanager.py b/qt/applications/workbench/workbench/plotting/globalfiguremanager.py index 55b2d133757cd89a34c523bc2f022a02324a2943..496ed33eb41676a68a69f223395b5284d8834bdb 100644 --- a/qt/applications/workbench/workbench/plotting/globalfiguremanager.py +++ b/qt/applications/workbench/workbench/plotting/globalfiguremanager.py @@ -21,30 +21,41 @@ import atexit import gc # 3rdparty imports -from six import itervalues +import six class GlobalFigureManager(object): - """A singleton manager of all figures created through it. Analogous to _pylab_helpers.Gcf. + """ + Singleton to manage a set of integer-numbered figures. It replaces + matplotlib._pylab_helpers.Gcf as the global figure manager. - Attributes: + This class is never instantiated; it consists of two class + attributes (a list and a dictionary), and a set of static + methods that operate on those attributes, accessing them + directly as class attributes. - *_active*: - A reference to the figure that is set as active, can be None + Attributes: *figs*: dictionary of the form {*num*: *manager*, ...} + + *_activeQue*: + list of *managers*, with active one at the end + """ - _active = None + _activeQue = [] figs = {} @classmethod - def get_fig_manager(cls, _): + def get_fig_manager(cls, num): """ - If an active figure manager exists return it; otherwise - return *None*. + If figure manager *num* exists, make it the active + figure and return the manager; otherwise return *None*. """ - return cls.get_active() + manager = cls.figs.get(num, None) + if manager is not None: + cls.set_active(manager) + return manager @classmethod def destroy(cls, num): @@ -59,8 +70,14 @@ class GlobalFigureManager(object): manager = cls.figs[num] manager.canvas.mpl_disconnect(manager._cidgcf) - if cls._active.num == num: - cls._active = None + # There must be a good reason for the following careful + # rebuilding of the activeQue; what is it? + oldQue = cls._activeQue[:] + cls._activeQue = [] + for f in oldQue: + if f != manager: + cls._activeQue.append(f) + del cls.figs[num] manager.destroy() gc.collect(1) @@ -69,7 +86,7 @@ class GlobalFigureManager(object): def destroy_fig(cls, fig): "*fig* is a Figure instance" num = None - for manager in itervalues(cls.figs): + for manager in six.itervalues(cls.figs): if manager.canvas.figure == fig: num = manager.num break @@ -85,7 +102,7 @@ class GlobalFigureManager(object): manager.canvas.mpl_disconnect(manager._cidgcf) manager.destroy() - cls._active = None + cls._activeQue = [] cls.figs.clear() gc.collect(1) @@ -115,23 +132,23 @@ class GlobalFigureManager(object): """ Return the manager of the active figure, or *None*. """ - if cls._active is not None: - cls._active.canvas.figure.clf() - return cls._active + if len(cls._activeQue) == 0: + return None + else: + return cls._activeQue[-1] @classmethod def set_active(cls, manager): """ Make the figure corresponding to *manager* the active one. - - Notifies all other figures to disable their active status. """ - cls._active = manager - active_num = manager.num - cls.figs[active_num] = manager - for manager in itervalues(cls.figs): - if manager.num != active_num: - manager.hold() + oldQue = cls._activeQue[:] + cls._activeQue = [] + for m in oldQue: + if m != manager: + cls._activeQue.append(m) + cls._activeQue.append(manager) + cls.figs[manager.num] = manager @classmethod def draw_all(cls, force=False): @@ -143,13 +160,5 @@ class GlobalFigureManager(object): if force or f_mgr.canvas.figure.stale: f_mgr.canvas.draw_idle() - # ------------------ Our additional interface ----------------- - - @classmethod - def set_hold(cls, manager): - """If this manager is active then set inactive""" - if cls._active == manager: - cls._active = None - atexit.register(GlobalFigureManager.destroy_all) diff --git a/qt/applications/workbench/workbench/plotting/toolbar.py b/qt/applications/workbench/workbench/plotting/toolbar.py index be81d4713253d027f12e7053161505d20f7971f6..9fdf0356d5c2dfbcae60011c8018594e6ae2a17c 100644 --- a/qt/applications/workbench/workbench/plotting/toolbar.py +++ b/qt/applications/workbench/workbench/plotting/toolbar.py @@ -40,10 +40,6 @@ class WorkbenchNavigationToolbar(NavigationToolbar2QT): ('Zoom', 'Zoom to rectangle', 'fa.search-plus', 'zoom', False), (None, None, None, None, None), ('Grid', 'Toggle grid on/off', None, 'toggle_grid', False), - (None, None, None, None, None), - ('Active', 'When enabled future plots will overwrite this figure', None, 'active', True), - ('Hold', 'When enabled this holds this figure open ', None, 'hold', False), - (None, None, None, None, None), ('Save', 'Save the figure', 'fa.save', 'save_figure', None), ('Print','Print the figure', 'fa.print', 'print_figure', None), (None, None, None, None, None), @@ -90,16 +86,6 @@ class WorkbenchNavigationToolbar(NavigationToolbar2QT): def toggle_grid(self): self.sig_grid_toggle_triggered.emit() - def hold(self, *args): - self._actions['hold'].setChecked(True) - self._actions['active'].setChecked(False) - self.sig_hold_triggered.emit() - - def active(self, *args): - self._actions['active'].setChecked(True) - self._actions['hold'].setChecked(False) - self.sig_active_triggered.emit() - def print_figure(self): printer = QtPrintSupport.QPrinter(QtPrintSupport.QPrinter.HighResolution) printer.setOrientation(QtPrintSupport.QPrinter.Landscape)