forked from M-Labs/artiq
1
0
Fork 0

gui: fix layout and scan disable bugs with argument recomputation

This commit is contained in:
Sebastien Bourdeauducq 2016-09-02 10:50:25 +08:00
parent e0cdda2760
commit bb12f563f6
2 changed files with 53 additions and 32 deletions

View File

@ -48,7 +48,7 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
self.viewport().installEventFilter(_WheelFilter(self.viewport())) self.viewport().installEventFilter(_WheelFilter(self.viewport()))
self._groups = dict() self._groups = dict()
self._arg_to_entry_widgetitem = dict() self._arg_to_widgets = dict()
self._dock = dock self._dock = dock
if not self._dock.arguments: if not self._dock.arguments:
@ -59,12 +59,13 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
gradient.setColorAt(1, self.palette().midlight().color()) gradient.setColorAt(1, self.palette().midlight().color())
for name, argument in self._dock.arguments.items(): for name, argument in self._dock.arguments.items():
try: widgets = dict()
entry = argty_to_entry[argument["desc"]["ty"]](argument) self._arg_to_widgets[name] = widgets
except:
print(name, argument) entry = argty_to_entry[argument["desc"]["ty"]](argument)
widget_item = QtWidgets.QTreeWidgetItem([name]) widget_item = QtWidgets.QTreeWidgetItem([name])
self._arg_to_entry_widgetitem[name] = entry, widget_item widgets["entry"] = entry
widgets["widget_item"] = widget_item
for col in range(3): for col in range(3):
widget_item.setBackground(col, gradient) widget_item.setBackground(col, gradient)
@ -77,6 +78,7 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
else: else:
self._get_group(argument["group"]).addChild(widget_item) self._get_group(argument["group"]).addChild(widget_item)
fix_layout = LayoutWidget() fix_layout = LayoutWidget()
widgets["fix_layout"] = fix_layout
fix_layout.addWidget(entry) fix_layout.addWidget(entry)
self.setItemWidget(widget_item, 1, fix_layout) self.setItemWidget(widget_item, 1, fix_layout)
@ -150,12 +152,14 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
argument["desc"] = procdesc argument["desc"] = procdesc
argument["state"] = state argument["state"] = state
old_entry, widget_item = self._arg_to_entry_widgetitem[name] widgets = self._arg_to_widgets[name]
old_entry.deleteLater()
entry = argty_to_entry[procdesc["ty"]](argument) widgets["entry"].deleteLater()
self._arg_to_entry_widgetitem[name] = entry, widget_item widgets["entry"] = argty_to_entry[procdesc["ty"]](argument)
self.setItemWidget(widget_item, 1, entry) widgets["fix_layout"] = LayoutWidget()
widgets["fix_layout"].addWidget(widgets["entry"])
self.setItemWidget(widgets["widget_item"], 1, widgets["fix_layout"])
self.updateGeometries()
def save_state(self): def save_state(self):
expanded = [] expanded = []

View File

@ -56,7 +56,7 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
self.viewport().installEventFilter(_WheelFilter(self.viewport())) self.viewport().installEventFilter(_WheelFilter(self.viewport()))
self._groups = dict() self._groups = dict()
self._arg_to_entry_widgetitem = dict() self._arg_to_widgets = dict()
arguments = self.manager.get_submission_arguments(self.expurl) arguments = self.manager.get_submission_arguments(self.expurl)
@ -68,9 +68,13 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
gradient.setColorAt(0, self.palette().base().color()) gradient.setColorAt(0, self.palette().base().color())
gradient.setColorAt(1, self.palette().midlight().color()) gradient.setColorAt(1, self.palette().midlight().color())
for name, argument in arguments.items(): for name, argument in arguments.items():
widgets = dict()
self._arg_to_widgets[name] = widgets
entry = argty_to_entry[argument["desc"]["ty"]](argument) entry = argty_to_entry[argument["desc"]["ty"]](argument)
widget_item = QtWidgets.QTreeWidgetItem([name]) widget_item = QtWidgets.QTreeWidgetItem([name])
self._arg_to_entry_widgetitem[name] = entry, widget_item widgets["entry"] = entry
widgets["widget_item"] = widget_item
for col in range(3): for col in range(3):
widget_item.setBackground(col, gradient) widget_item.setBackground(col, gradient)
@ -83,6 +87,7 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
else: else:
self._get_group(argument["group"]).addChild(widget_item) self._get_group(argument["group"]).addChild(widget_item)
fix_layout = LayoutWidget() fix_layout = LayoutWidget()
widgets["fix_layout"] = fix_layout
fix_layout.addWidget(entry) fix_layout.addWidget(entry)
self.setItemWidget(widget_item, 1, fix_layout) self.setItemWidget(widget_item, 1, fix_layout)
recompute_argument = QtWidgets.QToolButton() recompute_argument = QtWidgets.QToolButton()
@ -97,18 +102,20 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
tool_buttons = LayoutWidget() tool_buttons = LayoutWidget()
tool_buttons.addWidget(recompute_argument, 1) tool_buttons.addWidget(recompute_argument, 1)
if isinstance(entry, ScanEntry): disable_other_scans = QtWidgets.QToolButton()
disable_other_scans = QtWidgets.QToolButton() widgets["disable_other_scans"] = disable_other_scans
disable_other_scans.setIcon( disable_other_scans.setIcon(
QtWidgets.QApplication.style().standardIcon( QtWidgets.QApplication.style().standardIcon(
QtWidgets.QStyle.SP_DialogResetButton)) QtWidgets.QStyle.SP_DialogResetButton))
disable_other_scans.setToolTip("Disable all other scans in " disable_other_scans.setToolTip("Disable all other scans in "
"this experiment") "this experiment")
disable_other_scans.clicked.connect( disable_other_scans.clicked.connect(
partial(self._disable_other_scans, name)) partial(self._disable_other_scans, name))
tool_buttons.layout.setRowStretch(0, 1) tool_buttons.layout.setRowStretch(0, 1)
tool_buttons.layout.setRowStretch(3, 1) tool_buttons.layout.setRowStretch(3, 1)
tool_buttons.addWidget(disable_other_scans, 2) tool_buttons.addWidget(disable_other_scans, 2)
if not isinstance(entry, ScanEntry):
disable_other_scans.setVisible(False)
self.setItemWidget(widget_item, 2, tool_buttons) self.setItemWidget(widget_item, 2, tool_buttons)
@ -165,16 +172,26 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
argument["desc"] = procdesc argument["desc"] = procdesc
argument["state"] = state argument["state"] = state
old_entry, widget_item = self._arg_to_entry_widgetitem[name] # Qt needs a setItemWidget() to handle layout correctly,
old_entry.deleteLater() # simply replacing the entry inside the LayoutWidget
# results in a bug.
entry = argty_to_entry[procdesc["ty"]](argument) widgets = self._arg_to_widgets[name]
self._arg_to_entry_widgetitem[name] = entry, widget_item
self.setItemWidget(widget_item, 1, entry) widgets["entry"].deleteLater()
widgets["entry"] = argty_to_entry[procdesc["ty"]](argument)
widgets["disable_other_scans"].setVisible(
isinstance(widgets["entry"], ScanEntry))
widgets["fix_layout"].deleteLater()
widgets["fix_layout"] = LayoutWidget()
widgets["fix_layout"].addWidget(widgets["entry"])
self.setItemWidget(widgets["widget_item"], 1, widgets["fix_layout"])
self.updateGeometries()
def _disable_other_scans(self, current_name): def _disable_other_scans(self, current_name):
for name, (entry, _) in self._arg_to_entry_widgetitem.items(): for name, widgets in self._arg_to_widgets.items():
if name != current_name and isinstance(entry, ScanEntry): if (name != current_name
and isinstance(widgets["entry"], ScanEntry)):
entry.disable() entry.disable()
def save_state(self): def save_state(self):