From 5fd92a617506dd6d572a8e63ceb6fb01f6898c66 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sun, 10 Mar 2019 20:44:14 +0000 Subject: [PATCH] gui: Fix crash when quickly opening/closing applets Quickly closing/reopening applets (e.g. quickly clicking the checkbox on an entire folder of applets) would previously lead to an occasional KeyError on the self.dock_to_item access in on_dock_closed, as close() would be invoked more than once. The geometry/checked state handling can potentially be cleaned up further, but at least this avoid the crash. --- artiq/gui/applets.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/artiq/gui/applets.py b/artiq/gui/applets.py index d440120fa..ebf735595 100644 --- a/artiq/gui/applets.py +++ b/artiq/gui/applets.py @@ -321,7 +321,6 @@ class AppletsDock(QtWidgets.QDockWidget): self.main_window = main_window self.datasets_sub = datasets_sub - self.dock_to_item = dict() self.applet_uids = set() self.table = QtWidgets.QTreeWidget() @@ -414,12 +413,12 @@ class AppletsDock(QtWidgets.QDockWidget): finally: self.table.itemChanged.connect(self.item_changed) - def create(self, uid, name, spec): - dock = _AppletDock(self.datasets_sub, uid, name, spec) + def create(self, item, name, spec): + dock = _AppletDock(self.datasets_sub, item.applet_uid, name, spec) self.main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock) dock.setFloating(True) asyncio.ensure_future(dock.start()) - dock.sigClosed.connect(partial(self.on_dock_closed, dock)) + dock.sigClosed.connect(partial(self.on_dock_closed, item, dock)) return dock def item_changed(self, item, column): @@ -437,15 +436,15 @@ class AppletsDock(QtWidgets.QDockWidget): if item.applet_dock is None: name = item.text(0) spec = self.get_spec(item) - dock = self.create(item.applet_uid, name, spec) + dock = self.create(item, name, spec) item.applet_dock = dock if item.applet_geometry is not None: dock.restoreGeometry(item.applet_geometry) # geometry is now handled by main window state item.applet_geometry = None - self.dock_to_item[dock] = item else: dock = item.applet_dock + item.applet_dock = None if dock is not None: # This calls self.on_dock_closed dock.close() @@ -455,12 +454,9 @@ class AppletsDock(QtWidgets.QDockWidget): else: raise ValueError - def on_dock_closed(self, dock): - item = self.dock_to_item[dock] - item.applet_dock = None + def on_dock_closed(self, item, dock): item.applet_geometry = dock.saveGeometry() asyncio.ensure_future(dock.terminate()) - del self.dock_to_item[dock] item.setCheckState(0, QtCore.Qt.Unchecked) def get_untitled(self):