2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-26 19:58:25 +08:00

gui/experiments: add argument recompute buttons. Closes #171

This commit is contained in:
Sebastien Bourdeauducq 2015-12-05 17:51:12 +08:00
parent 2871b5e078
commit e8bd24d539

View File

@ -5,7 +5,7 @@ from collections import OrderedDict
from quamash import QtGui, QtCore from quamash import QtGui, QtCore
from pyqtgraph import dockarea from pyqtgraph import dockarea, LayoutWidget
from artiq.gui.tools import log_level_to_name, disable_scroll_wheel from artiq.gui.tools import log_level_to_name, disable_scroll_wheel
from artiq.gui.scan import ScanController from artiq.gui.scan import ScanController
@ -121,8 +121,11 @@ _argty_to_entry = {
class _ArgumentEditor(QtGui.QTreeWidget): class _ArgumentEditor(QtGui.QTreeWidget):
def __init__(self, arguments): def __init__(self, arguments):
QtGui.QTreeWidget.__init__(self) QtGui.QTreeWidget.__init__(self)
self.setColumnCount(2) self.setColumnCount(3)
self.header().setResizeMode(QtGui.QHeaderView.ResizeToContents) self.header().setStretchLastSection(False)
self.header().setResizeMode(0, QtGui.QHeaderView.ResizeToContents)
self.header().setResizeMode(1, QtGui.QHeaderView.Stretch)
self.header().setResizeMode(2, QtGui.QHeaderView.ResizeToContents)
self.header().setVisible(False) self.header().setVisible(False)
self.setSelectionMode(QtGui.QAbstractItemView.NoSelection) self.setSelectionMode(QtGui.QAbstractItemView.NoSelection)
self.setHorizontalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel) self.setHorizontalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel)
@ -132,23 +135,33 @@ class _ArgumentEditor(QtGui.QTreeWidget):
self._args_to_entries = dict() self._args_to_entries = dict()
if not arguments: if not arguments:
self.addTopLevelItem(QtGui.QTreeWidgetItem(["No arguments", ""])) self.addTopLevelItem(QtGui.QTreeWidgetItem(["No arguments"]))
for n, (name, argument) in enumerate(arguments.items()): for n, (name, argument) in enumerate(arguments.items()):
entry = _argty_to_entry[argument["desc"]["ty"]](argument) entry = _argty_to_entry[argument["desc"]["ty"]](argument)
self._args_to_entries[name] = entry self._args_to_entries[name] = entry
widget_item = QtGui.QTreeWidgetItem([name, ""]) widget_item = QtGui.QTreeWidgetItem([name])
if argument["group"] is None: if argument["group"] is None:
self.addTopLevelItem(widget_item) self.addTopLevelItem(widget_item)
else: else:
self._get_group(argument["group"]).addChild(widget_item) self._get_group(argument["group"]).addChild(widget_item)
self.setItemWidget(widget_item, 1, entry) self.setItemWidget(widget_item, 1, entry)
recompute_argument = QtGui.QToolButton()
recompute_argument.setToolTip("Re-run the experiment's build "
"method and take the default value")
recompute_argument.setIcon(QtGui.QApplication.style().standardIcon(
QtGui.QStyle.SP_BrowserReload))
recompute_argument.clicked.connect(
partial(self._recompute_argument, name))
fix_layout = LayoutWidget()
fix_layout.addWidget(recompute_argument)
self.setItemWidget(widget_item, 2, fix_layout)
def _get_group(self, name): def _get_group(self, name):
if name in self._groups: if name in self._groups:
return self._groups[name] return self._groups[name]
group = QtGui.QTreeWidgetItem([name, ""]) group = QtGui.QTreeWidgetItem([name])
for c in 0, 1: for c in 0, 1:
group.setBackground(c, QtGui.QBrush(QtGui.QColor(100, 100, 100))) group.setBackground(c, QtGui.QBrush(QtGui.QColor(100, 100, 100)))
group.setForeground(c, QtGui.QBrush(QtGui.QColor(220, 220, 255))) group.setForeground(c, QtGui.QBrush(QtGui.QColor(220, 220, 255)))
@ -159,6 +172,9 @@ class _ArgumentEditor(QtGui.QTreeWidget):
self._groups[name] = group self._groups[name] = group
return group return group
def _recompute_argument(self, argument):
logger.warning("recompute_argument not implemented (%s)", argument)
def save_state(self): def save_state(self):
expanded = [] expanded = []
for k, v in self._groups.items(): for k, v in self._groups.items():