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

Add tooltips to experiment arguments

This commit is contained in:
Chris Ballance 2017-02-03 00:41:36 +00:00 committed by Sébastien Bourdeauducq
parent f48cf9d9a0
commit 639066c6d8
4 changed files with 21 additions and 12 deletions

View File

@ -64,6 +64,8 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
entry = procdesc_to_entry(argument["desc"])(argument) entry = procdesc_to_entry(argument["desc"])(argument)
widget_item = QtWidgets.QTreeWidgetItem([name]) widget_item = QtWidgets.QTreeWidgetItem([name])
if argument.get("tooltip", None):
widget_item.setToolTip(0, argument["tooltip"])
widgets["entry"] = entry widgets["entry"] = entry
widgets["widget_item"] = widget_item widgets["widget_item"] = widget_item
@ -469,11 +471,12 @@ class ExperimentsArea(QtWidgets.QMdiArea):
def initialize_submission_arguments(self, arginfo): def initialize_submission_arguments(self, arginfo):
arguments = OrderedDict() arguments = OrderedDict()
for name, (procdesc, group) in arginfo.items(): for name, (procdesc, group, tooltip) in arginfo.items():
state = procdesc_to_entry(procdesc).default_state(procdesc) state = procdesc_to_entry(procdesc).default_state(procdesc)
arguments[name] = { arguments[name] = {
"desc": procdesc, "desc": procdesc,
"group": group, "group": group,
"tooltip": tooltip,
"state": state # mutated by entries "state": state # mutated by entries
} }
return arguments return arguments

View File

@ -73,6 +73,8 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
entry = procdesc_to_entry(argument["desc"])(argument) entry = procdesc_to_entry(argument["desc"])(argument)
widget_item = QtWidgets.QTreeWidgetItem([name]) widget_item = QtWidgets.QTreeWidgetItem([name])
if argument["tooltip"]:
widget_item.setToolTip(0, argument["tooltip"])
widgets["entry"] = entry widgets["entry"] = entry
widgets["widget_item"] = widget_item widgets["widget_item"] = widget_item
@ -523,12 +525,13 @@ class ExperimentManager:
def initialize_submission_arguments(self, expurl, arginfo): def initialize_submission_arguments(self, expurl, arginfo):
arguments = OrderedDict() arguments = OrderedDict()
for name, (procdesc, group) in arginfo.items(): for name, (procdesc, group, tooltip) in arginfo.items():
state = procdesc_to_entry(procdesc).default_state(procdesc) state = procdesc_to_entry(procdesc).default_state(procdesc)
arguments[name] = { arguments[name] = {
"desc": procdesc, "desc": procdesc,
"group": group, "group": group,
"state": state # mutated by entries "tooltip": tooltip,
"state": state, # mutated by entries
} }
self.submission_arguments[expurl] = arguments self.submission_arguments[expurl] = arguments
return arguments return arguments

View File

@ -174,8 +174,8 @@ class TraceArgumentManager:
def __init__(self): def __init__(self):
self.requested_args = OrderedDict() self.requested_args = OrderedDict()
def get(self, key, processor, group): def get(self, key, processor, group, tooltip):
self.requested_args[key] = processor, group self.requested_args[key] = processor, group, tooltip
return None return None
@ -183,7 +183,7 @@ class ProcessArgumentManager:
def __init__(self, unprocessed_arguments): def __init__(self, unprocessed_arguments):
self.unprocessed_arguments = unprocessed_arguments self.unprocessed_arguments = unprocessed_arguments
def get(self, key, processor, group): def get(self, key, processor, group, tooltip):
if key in self.unprocessed_arguments: if key in self.unprocessed_arguments:
r = processor.process(self.unprocessed_arguments[key]) r = processor.process(self.unprocessed_arguments[key])
else: else:
@ -233,7 +233,7 @@ class HasEnvironment:
only meant to be executed programmatically (not from the GUI).""" only meant to be executed programmatically (not from the GUI)."""
pass pass
def get_argument(self, key, processor, group=None): def get_argument(self, key, processor, group=None, tooltip=None):
"""Retrieves and returns the value of an argument. """Retrieves and returns the value of an argument.
This function should only be called from ``build``. This function should only be called from ``build``.
@ -243,18 +243,21 @@ class HasEnvironment:
as instances of ``BooleanValue`` and ``NumberValue``. as instances of ``BooleanValue`` and ``NumberValue``.
:param group: An optional string that defines what group the argument :param group: An optional string that defines what group the argument
belongs to, for user interface purposes. belongs to, for user interface purposes.
:param tooltip: An optional string to describe the argument in more
detail, applied as a tooltip to the argument name in the user
interface.
""" """
if not self.__in_build: if not self.__in_build:
raise TypeError("get_argument() should only " raise TypeError("get_argument() should only "
"be called from build()") "be called from build()")
return self.__argument_mgr.get(key, processor, group) return self.__argument_mgr.get(key, processor, group, tooltip)
def setattr_argument(self, key, processor=None, group=None): def setattr_argument(self, key, processor=None, group=None, tooltip=None):
"""Sets an argument as attribute. The names of the argument and of the """Sets an argument as attribute. The names of the argument and of the
attribute are the same. attribute are the same.
The key is added to the instance's kernel invariants.""" The key is added to the instance's kernel invariants."""
setattr(self, key, self.get_argument(key, processor, group)) setattr(self, key, self.get_argument(key, processor, group, tooltip))
kernel_invariants = getattr(self, "kernel_invariants", set()) kernel_invariants = getattr(self, "kernel_invariants", set())
self.kernel_invariants = kernel_invariants | {key} self.kernel_invariants = kernel_invariants | {key}

View File

@ -166,8 +166,8 @@ def examine(device_mgr, dataset_mgr, file):
argument_mgr = TraceArgumentManager() argument_mgr = TraceArgumentManager()
exp_class((device_mgr, dataset_mgr, argument_mgr)) exp_class((device_mgr, dataset_mgr, argument_mgr))
arginfo = OrderedDict( arginfo = OrderedDict(
(k, (proc.describe(), group)) (k, (proc.describe(), group, tooltip))
for k, (proc, group) in argument_mgr.requested_args.items()) for k, (proc, group, tooltip) in argument_mgr.requested_args.items())
register_experiment(class_name, name, arginfo) register_experiment(class_name, name, arginfo)