Skip to content
Permalink
Browse files

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.
  • Loading branch information...
dnadlinger authored and sbourdeauducq committed Mar 10, 2019
1 parent 73ebebf commit 56c5637230bad56429bfba6fd363b8046bf513f7
Showing with 6 additions and 10 deletions.
  1. +6 −10 artiq/gui/applets.py
@@ -321,7 +321,6 @@ def __init__(self, main_window, datasets_sub):

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 @@ def set_spec(self, item, spec):
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 @@ def item_changed(self, item, column):
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 @@ def item_changed(self, item, column):
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):

0 comments on commit 56c5637

Please sign in to comment.
You can’t perform that action at this time.