diff --git a/artiq/gui/applets.py b/artiq/gui/applets.py index ddc801726..2a8732f5a 100644 --- a/artiq/gui/applets.py +++ b/artiq/gui/applets.py @@ -8,6 +8,7 @@ from quamash import QtCore, QtGui, QtWidgets from artiq.protocols.pipe_ipc import AsyncioParentComm from artiq.protocols import pyon +from artiq.gui.tools import QDockWidgetCloseDetect logger = logging.getLogger(__name__) @@ -84,11 +85,9 @@ class AppletIPCServer(AsyncioParentComm): await asyncio.wait([self.server_task]) -class AppletDock(QtWidgets.QDockWidget): - sigClosed = QtCore.pyqtSignal() - +class AppletDock(QDockWidgetCloseDetect): def __init__(self, datasets_sub, uid, name, command): - QtWidgets.QDockWidget.__init__(self, "Applet: " + name) + QDockWidgetCloseDetect.__init__(self, "Applet: " + name) self.setObjectName("applet" + str(uid)) self.datasets_sub = datasets_sub @@ -164,10 +163,6 @@ class AppletDock(QtWidgets.QDockWidget): await self.terminate() await self.start() - def closeEvent(self, event): - QtWidgets.QDockWidget.closeEvent(self, event) - self.sigClosed.emit() - _templates = [ ("Big number", "{python} -m artiq.applets.big_number " diff --git a/artiq/gui/experiments.py b/artiq/gui/experiments.py index 8b81edc92..5536c30d3 100644 --- a/artiq/gui/experiments.py +++ b/artiq/gui/experiments.py @@ -7,7 +7,7 @@ from quamash import QtGui, QtCore, QtWidgets from pyqtgraph import LayoutWidget -from artiq.gui.tools import log_level_to_name +from artiq.gui.tools import log_level_to_name, QDockWidgetCloseDetect from artiq.gui.entries import argty_to_entry @@ -133,12 +133,10 @@ class _ArgumentEditor(QtGui.QTreeWidget): pass -class _ExperimentDock(QtWidgets.QDockWidget): - sigClosed = QtCore.pyqtSignal() - +class _ExperimentDock(QDockWidgetCloseDetect): def __init__(self, manager, expurl): name = "Exp: " + expurl - QtWidgets.QDockWidget.__init__(self, name) + QDockWidgetCloseDetect.__init__(self, name) self.setObjectName(name) self.layout = QtWidgets.QGridLayout() @@ -297,10 +295,6 @@ class _ExperimentDock(QtWidgets.QDockWidget): self.argeditor = _ArgumentEditor(self.manager, self, self.expurl) self.layout.addWidget(self.argeditor, 0, 0, 1, 5) - def closeEvent(self, event): - QtWidgets.QDockWidget.closeEvent(self, event) - self.sigClosed.emit() - def save_state(self): return self.argeditor.save_state() diff --git a/artiq/gui/log.py b/artiq/gui/log.py index d853e0f1b..005fe626d 100644 --- a/artiq/gui/log.py +++ b/artiq/gui/log.py @@ -7,7 +7,7 @@ from functools import partial from quamash import QtGui, QtCore, QtWidgets from pyqtgraph import LayoutWidget -from artiq.gui.tools import log_level_to_name +from artiq.gui.tools import log_level_to_name, QDockWidgetCloseDetect def _make_wrappable(row, width=30): @@ -140,11 +140,9 @@ class _LogFilterProxyModel(QtCore.QSortFilterProxyModel): self.invalidateFilter() -class _LogDock(QtWidgets.QDockWidget): - sigClosed = QtCore.pyqtSignal() - +class _LogDock(QDockWidgetCloseDetect): def __init__(self, manager, name, log_sub): - QtWidgets.QDockWidget.__init__(self, "Log") + QDockWidgetCloseDetect.__init__(self, "Log") self.setObjectName(name) grid = LayoutWidget() @@ -254,10 +252,6 @@ class _LogDock(QtWidgets.QDockWidget): self.table_model_filter.rowsInserted.connect(self.rows_inserted_after) self.table_model_filter.rowsRemoved.connect(self.rows_removed) - def closeEvent(self, event): - QtWidgets.QDockWidget.closeEvent(self, event) - self.sigClosed.emit() - def save_state(self): return { "min_level_idx": self.filter_level.currentIndex(), diff --git a/artiq/gui/tools.py b/artiq/gui/tools.py index 5fa701d81..5de02c3a9 100644 --- a/artiq/gui/tools.py +++ b/artiq/gui/tools.py @@ -1,6 +1,6 @@ import logging -from quamash import QtCore +from PyQt5 import QtCore, QtWidgets, QtGui def log_level_to_name(level): @@ -27,3 +27,12 @@ class _WheelFilter(QtCore.QObject): def disable_scroll_wheel(widget): widget.setFocusPolicy(QtCore.Qt.StrongFocus) widget.installEventFilter(_WheelFilter(widget)) + + +class QDockWidgetCloseDetect(QtWidgets.QDockWidget): + sigClosed = QtCore.pyqtSignal() + + def event(self, event): + if isinstance(event, QtGui.QCloseEvent): + self.sigClosed.emit() + return QtWidgets.QDockWidget.event(self, event)