Exemplo n.º 1
0
    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)
        self._ads_observer = None
        # disconnect window events before calling GlobalFigureManager.destroy. window.close is not guaranteed to
        # delete the object and do this for us. On macOS it was observed that closing the figure window
        # would produce an extraneous activated event that would add a new figure to the plots list
        # right after deleted the old one.
        self.window.disconnect()
        self._fig_interaction.disconnect()
        self.window.close()
        if self.superplot:
            self.superplot.close()

        try:
            GlobalFigureManager.destroy(self.num)
        except AttributeError:
            pass
Exemplo n.º 2
0
 def test_destroy_doesnt_have_fig(self):
     with patch.object(GlobalFigureManager,
                       'has_fignum',
                       return_value=False) as mock_has_fignum:
         num = 123123
         GlobalFigureManager.destroy(num)
         mock_has_fignum.assert_called_once_with(num)
Exemplo n.º 3
0
 def test_destroy(self, mock_gc_collect):
     num = 0
     mock_manager = MockFigureManager(num)
     GlobalFigureManager.set_active(mock_manager)
     self.assertEqual(1, len(GlobalFigureManager._activeQue))
     self.assertEqual(1, len(GlobalFigureManager.figs))
     with patch.object(GlobalFigureManager, 'notify_observers') as mock_notify_observers:
         GlobalFigureManager.destroy(num)
         self.assertEqual(0, len(GlobalFigureManager._activeQue))
         self.assertEqual(0, len(GlobalFigureManager.figs))
         mock_gc_collect.assert_called_once_with(1)
         mock_notify_observers.assert_has_calls(
             [call(FigureAction.Closed, num), call(FigureAction.OrderChanged, -1)])
 def test_destroy(self, mock_gc_collect):
     num = 0
     mock_manager = MockFigureManager(num)
     GlobalFigureManager.set_active(mock_manager)
     self.assertEqual(1, len(GlobalFigureManager._activeQue))
     self.assertEqual(1, len(GlobalFigureManager.figs))
     with patch.object(GlobalFigureManager, 'notify_observers') as mock_notify_observers:
         GlobalFigureManager.destroy(num)
         self.assertEqual(0, len(GlobalFigureManager._activeQue))
         self.assertEqual(0, len(GlobalFigureManager.figs))
         mock_gc_collect.assert_called_once_with(1)
         mock_notify_observers.assert_has_calls(
             [call(FigureAction.Closed, num), call(FigureAction.OrderChanged, -1)])
 def test_destroy_doesnt_have_fig(self):
     with patch.object(GlobalFigureManager, 'has_fignum', return_value=False) as mock_has_fignum:
         num = 123123
         GlobalFigureManager.destroy(num)
         mock_has_fignum.assert_called_once_with(num)