From 76dbdafacc788444fc9d6687eb482a357d862330 Mon Sep 17 00:00:00 2001 From: dlidstrom Date: Sat, 14 Mar 2015 22:55:16 -0600 Subject: [PATCH] Dock to emit closed signal when closed. Temporary DockArea windows call close method of all docks when they are closed. --- pyqtgraph/dockarea/Dock.py | 2 ++ pyqtgraph/dockarea/DockArea.py | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pyqtgraph/dockarea/Dock.py b/pyqtgraph/dockarea/Dock.py index 5d48b130..77903e69 100644 --- a/pyqtgraph/dockarea/Dock.py +++ b/pyqtgraph/dockarea/Dock.py @@ -7,6 +7,7 @@ from ..python2_3 import asUnicode class Dock(QtGui.QWidget, DockDrop): sigStretchChanged = QtCore.Signal() + sigClosed = QtCore.Signal(object) def __init__(self, name, area=None, size=(10, 10), widget=None, hideTitle=False, autoOrientation=True, closable=False): QtGui.QWidget.__init__(self) @@ -224,6 +225,7 @@ class Dock(QtGui.QWidget, DockDrop): self.label.setParent(None) self._container.apoptose() self._container = None + self.sigClosed.emit(self) def __repr__(self): return "" % (self.name(), self.stretch()) diff --git a/pyqtgraph/dockarea/DockArea.py b/pyqtgraph/dockarea/DockArea.py index a92ab263..d6bd989c 100644 --- a/pyqtgraph/dockarea/DockArea.py +++ b/pyqtgraph/dockarea/DockArea.py @@ -172,8 +172,7 @@ class DockArea(Container, QtGui.QWidget, DockDrop): if self.home is None: area = DockArea(temporary=True, home=self) self.tempAreas.append(area) - win = QtGui.QMainWindow() - win.setCentralWidget(area) + win = TempAreaWindow(area) area.win = win win.show() else: @@ -302,6 +301,11 @@ class DockArea(Container, QtGui.QWidget, DockDrop): if self.temporary: self.home.removeTempArea(self) #self.close() + + def clear(self): + docks = self.findAll()[1] + for dock in docks.values(): + dock.close() ## PySide bug: We need to explicitly redefine these methods ## or else drag/drop events will not be delivered. @@ -317,5 +321,12 @@ class DockArea(Container, QtGui.QWidget, DockDrop): def dropEvent(self, *args): DockDrop.dropEvent(self, *args) - - + +class TempAreaWindow(QtGui.QMainWindow): + def __init__(self, area, **kwargs): + super().__init__(**kwargs) + self.setCentralWidget(area) + + def closeEvent(self, *args, **kwargs): + self.centralWidget().clear() + super().closeEvent(*args, **kwargs)