mirror of
https://github.com/nqrduck/nqrduck-pulseprogrammer.git
synced 2024-11-18 15:31:03 +00:00
Table view generation.
This commit is contained in:
parent
d5f48d6785
commit
43b49998a3
1 changed files with 84 additions and 42 deletions
|
@ -26,12 +26,14 @@ from quackseq.pulseparameters import (
|
||||||
BooleanOption,
|
BooleanOption,
|
||||||
NumericOption,
|
NumericOption,
|
||||||
FunctionOption,
|
FunctionOption,
|
||||||
|
TableOption,
|
||||||
)
|
)
|
||||||
from nqrduck.helpers.formbuilder import (
|
from nqrduck.helpers.formbuilder import (
|
||||||
DuckFormBuilder,
|
DuckFormBuilder,
|
||||||
DuckFormFunctionSelectionField,
|
DuckFormFunctionSelectionField,
|
||||||
DuckFormCheckboxField,
|
DuckFormCheckboxField,
|
||||||
DuckFormFloatField,
|
DuckFormFloatField,
|
||||||
|
DuckTableField,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .visual_parameter import VisualParameter
|
from .visual_parameter import VisualParameter
|
||||||
|
@ -271,6 +273,9 @@ class PulseProgrammerView(ModuleView):
|
||||||
parameter (str): The name of the parameter for which the options should be set.
|
parameter (str): The name of the parameter for which the options should be set.
|
||||||
"""
|
"""
|
||||||
logger.debug("Button for event %s and parameter %s clicked", event, parameter)
|
logger.debug("Button for event %s and parameter %s clicked", event, parameter)
|
||||||
|
# We assume the pulse sequence was updated
|
||||||
|
self.module.model.pulse_sequence.update_options()
|
||||||
|
|
||||||
# Create a QDialog to set the options for the parameter.
|
# Create a QDialog to set the options for the parameter.
|
||||||
description = f"Set options for {parameter}"
|
description = f"Set options for {parameter}"
|
||||||
dialog = DuckFormBuilder(parameter, description=description, parent=self)
|
dialog = DuckFormBuilder(parameter, description=description, parent=self)
|
||||||
|
@ -278,53 +283,33 @@ class PulseProgrammerView(ModuleView):
|
||||||
# Adding fields for the options
|
# Adding fields for the options
|
||||||
form_options = []
|
form_options = []
|
||||||
for option in event.parameters[parameter].options:
|
for option in event.parameters[parameter].options:
|
||||||
if isinstance(option, BooleanOption):
|
logger.debug(f"Option value is {option.value}")
|
||||||
boolean_form = DuckFormCheckboxField(
|
if isinstance(option, TableOption):
|
||||||
option.name, tooltip=None, default=option.value
|
# Every option is it's own column. Every column has a dedicated number of rows.
|
||||||
)
|
# Get the option name:
|
||||||
dialog.add_field(boolean_form)
|
name = option.name
|
||||||
form_options.append(option)
|
table = DuckTableField(name, tooltip=None)
|
||||||
elif isinstance(option, NumericOption):
|
|
||||||
# We only show the slider if both min and max values are set
|
|
||||||
if option.min_value is not None and option.max_value is not None:
|
|
||||||
slider = True
|
|
||||||
else:
|
|
||||||
slider = False
|
|
||||||
|
|
||||||
if slider:
|
columns = option.columns
|
||||||
slider = option.slider
|
|
||||||
|
|
||||||
numeric_field = DuckFormFloatField(
|
for column in columns:
|
||||||
option.name,
|
# Every table option has a number of rows
|
||||||
tooltip=None,
|
fields = []
|
||||||
default=option.value,
|
for row in column.options:
|
||||||
min_value=option.min_value,
|
fields.append(self.get_field_for_option(row, event))
|
||||||
max_value=option.max_value,
|
|
||||||
slider=slider,
|
|
||||||
)
|
|
||||||
|
|
||||||
dialog.add_field(numeric_field)
|
name = column.name
|
||||||
form_options.append(option)
|
|
||||||
elif isinstance(option, FunctionOption):
|
|
||||||
logger.debug(f"Functions: {option.functions}")
|
|
||||||
|
|
||||||
# When loading a pulse sequence, the instance of the objects will be different
|
logger.debug(f"Adding column {name} with fields {fields}")
|
||||||
# Therefore we need to operate on the classes
|
table.add_column(option=column, fields=fields)
|
||||||
for function in option.functions:
|
|
||||||
if function.__class__.__name__ == option.value.__class__.__name__:
|
|
||||||
default_function = function
|
|
||||||
|
|
||||||
index = option.functions.index(default_function)
|
form_options.append(table)
|
||||||
|
dialog.add_field(table)
|
||||||
|
|
||||||
function_field = DuckFormFunctionSelectionField(
|
else:
|
||||||
option.name,
|
field = self.get_field_for_option(option, event)
|
||||||
tooltip=None,
|
form_options.append(field)
|
||||||
functions=option.functions,
|
dialog.add_field(field)
|
||||||
duration=event.duration,
|
|
||||||
default_function=index,
|
|
||||||
)
|
|
||||||
dialog.add_field(function_field)
|
|
||||||
form_options.append(option)
|
|
||||||
|
|
||||||
result = dialog.exec()
|
result = dialog.exec()
|
||||||
|
|
||||||
|
@ -333,10 +318,67 @@ class PulseProgrammerView(ModuleView):
|
||||||
if result:
|
if result:
|
||||||
values = dialog.get_values()
|
values = dialog.get_values()
|
||||||
for i, value in enumerate(values):
|
for i, value in enumerate(values):
|
||||||
options[i].value = value
|
logger.debug(f"Setting value {value} for option {options[i]}")
|
||||||
|
options[i].set_value(value)
|
||||||
|
|
||||||
self.set_parameter_icons()
|
self.set_parameter_icons()
|
||||||
|
|
||||||
|
def get_field_for_option(self, option, event):
|
||||||
|
"""Returns the field for the given option.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
option (Option): The option for which the field should be created.
|
||||||
|
event (PulseSequence.Event): The event for which the option should be created.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
DuckFormField: The field for the option
|
||||||
|
"""
|
||||||
|
logger.debug(f"Creating field with value {option.value}")
|
||||||
|
if isinstance(option, BooleanOption):
|
||||||
|
field = DuckFormCheckboxField(
|
||||||
|
option.name, tooltip=None, default=option.value
|
||||||
|
)
|
||||||
|
elif isinstance(option, NumericOption):
|
||||||
|
# We only show the slider if both min and max values are set
|
||||||
|
if option.min_value is not None and option.max_value is not None:
|
||||||
|
slider = True
|
||||||
|
else:
|
||||||
|
slider = False
|
||||||
|
|
||||||
|
if slider:
|
||||||
|
slider = option.slider
|
||||||
|
|
||||||
|
field = DuckFormFloatField(
|
||||||
|
option.name,
|
||||||
|
tooltip=None,
|
||||||
|
default=option.value,
|
||||||
|
min_value=option.min_value,
|
||||||
|
max_value=option.max_value,
|
||||||
|
slider=slider,
|
||||||
|
)
|
||||||
|
|
||||||
|
elif isinstance(option, FunctionOption):
|
||||||
|
logger.debug(f"Functions: {option.functions}")
|
||||||
|
|
||||||
|
# When loading a pulse sequence, the instance of the objects will be different
|
||||||
|
# Therefore we need to operate on the classes
|
||||||
|
for function in option.functions:
|
||||||
|
if function.__class__.__name__ == option.value.__class__.__name__:
|
||||||
|
default_function = function
|
||||||
|
|
||||||
|
index = option.functions.index(default_function)
|
||||||
|
|
||||||
|
field = DuckFormFunctionSelectionField(
|
||||||
|
option.name,
|
||||||
|
tooltip=None,
|
||||||
|
functions=option.functions,
|
||||||
|
duration=event.duration,
|
||||||
|
default_function=index,
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.debug(f"Returning Field: {field}")
|
||||||
|
return field
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def on_save_button_clicked(self) -> None:
|
def on_save_button_clicked(self) -> None:
|
||||||
"""This method is called whenever the save button is clicked. It opens a dialog to select a file to save the pulse sequence to."""
|
"""This method is called whenever the save button is clicked. It opens a dialog to select a file to save the pulse sequence to."""
|
||||||
|
|
Loading…
Reference in a new issue