applets: rename params

This commit is contained in:
Simon Renblad 2024-02-27 13:09:22 +08:00 committed by Sébastien Bourdeauducq
parent 92eb3947a4
commit 002325be17
2 changed files with 42 additions and 42 deletions

View File

@ -42,13 +42,13 @@ class _AppletRequestInterface:
""" """
raise NotImplementedError raise NotImplementedError
def set_argument_value(self, expurl, name, value): def set_argument_value(self, expurl, key, value):
""" """
Temporarily set the value of an argument in a experiment in the dashboard. Temporarily set the value of an argument in a experiment in the dashboard.
The value resets to default value when recomputing the argument. The value resets to default value when recomputing the argument.
:param expurl: Experiment URL identifying the experiment in the dashboard. Example: 'repo:ArgumentsDemo'. :param expurl: Experiment URL identifying the experiment in the dashboard. Example: 'repo:ArgumentsDemo'.
:param name: Name of the argument in the experiment. :param key: Name of the argument in the experiment.
:param value: Object representing the new temporary value of the argument. For ``Scannable`` arguments, this parameter :param value: Object representing the new temporary value of the argument. For ``Scannable`` arguments, this parameter
should be a ``ScanObject``. The type of the ``ScanObject`` will be set as the selected type when this function is called. should be a ``ScanObject``. The type of the ``ScanObject`` will be set as the selected type when this function is called.
""" """
@ -77,10 +77,10 @@ class AppletRequestIPC(_AppletRequestInterface):
mod = {"action": "append", "path": [key, 1], "x": value} mod = {"action": "append", "path": [key, 1], "x": value}
self.ipc.update_dataset(mod) self.ipc.update_dataset(mod)
def set_argument_value(self, expurl, name, value): def set_argument_value(self, expurl, key, value):
if isinstance(value, ScanObject): if isinstance(value, ScanObject):
value = value.describe() value = value.describe()
self.ipc.set_argument_value(expurl, name, value) self.ipc.set_argument_value(expurl, key, value)
class AppletRequestRPC(_AppletRequestInterface): class AppletRequestRPC(_AppletRequestInterface):
@ -182,10 +182,10 @@ class AppletIPCClient(AsyncioChildComm):
self.write_pyon({"action": "update_dataset", self.write_pyon({"action": "update_dataset",
"mod": mod}) "mod": mod})
def set_argument_value(self, expurl, name, value): def set_argument_value(self, expurl, key, value):
self.write_pyon({"action": "set_argument_value", self.write_pyon({"action": "set_argument_value",
"expurl": expurl, "expurl": expurl,
"name": name, "key": key,
"value": value}) "value": value})

View File

@ -67,19 +67,19 @@ class EntryArea(QtWidgets.QTreeWidget):
self.setItemWidget(self.bottom_item, 1, buttons) self.setItemWidget(self.bottom_item, 1, buttons)
self.bottom_item.setHidden(True) self.bottom_item.setHidden(True)
def setattr_argument(self, name, proc, group=None, tooltip=None): def setattr_argument(self, key, processor, group=None, tooltip=None):
argument = dict() argument = dict()
desc = proc.describe() desc = processor.describe()
argument["desc"] = desc argument["desc"] = desc
argument["group"] = group argument["group"] = group
argument["tooltip"] = tooltip argument["tooltip"] = tooltip
self._arguments[name] = argument self._arguments[key] = argument
widgets = dict() widgets = dict()
self._arg_to_widgets[name] = widgets self._arg_to_widgets[key] = widgets
entry_class = procdesc_to_entry(argument["desc"]) entry_class = procdesc_to_entry(argument["desc"])
argument["state"] = entry_class.default_state(argument["desc"]) argument["state"] = entry_class.default_state(argument["desc"])
entry = entry_class(argument) entry = entry_class(argument)
widget_item = QtWidgets.QTreeWidgetItem([name]) widget_item = QtWidgets.QTreeWidgetItem([key])
if argument["tooltip"]: if argument["tooltip"]:
widget_item.setToolTip(0, argument["tooltip"]) widget_item.setToolTip(0, argument["tooltip"])
widgets["entry"] = entry widgets["entry"] = entry
@ -109,16 +109,16 @@ class EntryArea(QtWidgets.QTreeWidget):
reset_value.setIcon( reset_value.setIcon(
QtWidgets.QApplication.style().standardIcon( QtWidgets.QApplication.style().standardIcon(
QtWidgets.QStyle.SP_BrowserReload)) QtWidgets.QStyle.SP_BrowserReload))
reset_value.clicked.connect(partial(self.reset_value, name)) reset_value.clicked.connect(partial(self.reset_value, key))
tool_buttons = LayoutWidget() tool_buttons = LayoutWidget()
tool_buttons.addWidget(reset_value, 0) tool_buttons.addWidget(reset_value, 0)
self.setItemWidget(widget_item, 2, tool_buttons) self.setItemWidget(widget_item, 2, tool_buttons)
def _get_group(self, name): def _get_group(self, key):
if name in self._groups: if key in self._groups:
return self._groups[name] return self._groups[key]
group = QtWidgets.QTreeWidgetItem([name]) group = QtWidgets.QTreeWidgetItem([key])
for col in range(3): for col in range(3):
group.setBackground(col, self.palette().mid()) group.setBackground(col, self.palette().mid())
group.setForeground(col, self.palette().brightText()) group.setForeground(col, self.palette().brightText())
@ -126,40 +126,40 @@ class EntryArea(QtWidgets.QTreeWidget):
font.setBold(True) font.setBold(True)
group.setFont(col, font) group.setFont(col, font)
self.insertTopLevelItem(self.indexFromItem(self.bottom_item).row(), group) self.insertTopLevelItem(self.indexFromItem(self.bottom_item).row(), group)
self._groups[name] = group self._groups[key] = group
return group return group
def __getattr__(self, name): def __getattr__(self, key):
return self.get_value(name) return self.get_value(key)
def get_value(self, name): def get_value(self, key):
entry = self._arg_to_widgets[name]["entry"] entry = self._arg_to_widgets[key]["entry"]
argument = self._arguments[name] argument = self._arguments[key]
return entry.state_to_value(argument["state"]) return entry.state_to_value(argument["state"])
def set_value(self, name, value): def set_value(self, key, value):
ty = self._arguments[name]["desc"]["ty"] ty = self._arguments[key]["desc"]["ty"]
if ty == "Scannable": if ty == "Scannable":
desc = value.describe() desc = value.describe()
self._arguments[name]["state"][desc["ty"]] = desc self._arguments[key]["state"][desc["ty"]] = desc
self._arguments[name]["state"]["selected"] = desc["ty"] self._arguments[key]["state"]["selected"] = desc["ty"]
else: else:
self._arguments[name]["state"] = value self._arguments[key]["state"] = value
self.update_value(name) self.update_value(key)
def get_values(self): def get_values(self):
d = dict() d = dict()
for name in self._arguments.keys(): for key in self._arguments.keys():
d[name] = self.get_value(name) d[key] = self.get_value(key)
return d return d
def set_values(self, values): def set_values(self, values):
for name, value in values.items(): for key, value in values.items():
self.set_value(name, value) self.set_value(key, value)
def update_value(self, name): def update_value(self, key):
widgets = self._arg_to_widgets[name] widgets = self._arg_to_widgets[key]
argument = self._arguments[name] argument = self._arguments[key]
# Qt needs a setItemWidget() to handle layout correctly, # Qt needs a setItemWidget() to handle layout correctly,
# simply replacing the entry inside the LayoutWidget # simply replacing the entry inside the LayoutWidget
@ -173,14 +173,14 @@ class EntryArea(QtWidgets.QTreeWidget):
self.setItemWidget(widgets["widget_item"], 1, widgets["fix_layout"]) self.setItemWidget(widgets["widget_item"], 1, widgets["fix_layout"])
self.updateGeometries() self.updateGeometries()
def reset_value(self, name): def reset_value(self, key):
procdesc = self._arguments[name]["desc"] procdesc = self._arguments[key]["desc"]
self._arguments[name]["state"] = procdesc_to_entry(procdesc).default_state(procdesc) self._arguments[key]["state"] = procdesc_to_entry(procdesc).default_state(procdesc)
self.update_value(name) self.update_value(key)
def reset_all(self): def reset_all(self):
for name in self._arguments.keys(): for key in self._arguments.keys():
self.reset_value(name) self.reset_value(key)
class AppletIPCServer(AsyncioParentComm): class AppletIPCServer(AsyncioParentComm):
@ -255,7 +255,7 @@ class AppletIPCServer(AsyncioParentComm):
elif action == "update_dataset": elif action == "update_dataset":
await self.dataset_ctl.update(obj["mod"]) await self.dataset_ctl.update(obj["mod"])
elif action == "set_argument_value": elif action == "set_argument_value":
self.expmgr.set_argument_value(obj["expurl"], obj["name"], obj["value"]) self.expmgr.set_argument_value(obj["expurl"], obj["key"], obj["value"])
else: else:
raise ValueError("unknown action in applet message") raise ValueError("unknown action in applet message")
except: except: