Changed implementation of puse options.

This commit is contained in:
jupfi 2023-07-11 17:51:21 +02:00
parent ab670c38c7
commit 1b0e57d3cd

View file

@ -5,6 +5,7 @@ from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QTableWidget, QVBoxLayout, QPushButton, QHBoxLayout, QLabel, QDialog, QLineEdit, QDialogButtonBox, QTableWidgetItem, QCheckBox from PyQt6.QtWidgets import QTableWidget, QVBoxLayout, QPushButton, QHBoxLayout, QLabel, QDialog, QLineEdit, QDialogButtonBox, QTableWidgetItem, QCheckBox
from PyQt6.QtCore import pyqtSlot from PyQt6.QtCore import pyqtSlot
from nqrduck.module.module_view import ModuleView from nqrduck.module.module_view import ModuleView
from nqrduck_spectrometer.pulseparameters import BooleanOption, NumericOption
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -110,7 +111,7 @@ class PulseProgrammerView(ModuleView):
def set_parameter_icons(self): def set_parameter_icons(self):
for column_idx, event in enumerate(self.module.model.pulse_sequence.events): for column_idx, event in enumerate(self.module.model.pulse_sequence.events):
for row_idx, parameter in enumerate(self.module.model.pulse_parameter_options.keys()): for row_idx, parameter in enumerate(self.module.model.pulse_parameter_options.keys()):
logger.debug("Adding button for event %s and parameter %s with state %s", event, parameter, self.module.model.pulse_sequence.events[event].parameters[parameter].state) logger.debug("Adding button for event %s and parameter %s", event, parameter)
logger.debug("Parameter object id: %s", id(self.module.model.pulse_sequence.events[event].parameters[parameter])) logger.debug("Parameter object id: %s", id(self.module.model.pulse_sequence.events[event].parameters[parameter]))
button = QPushButton() button = QPushButton()
icon = QIcon(self.module.model.pulse_sequence.events[event].parameters[parameter].get_pixmap()) icon = QIcon(self.module.model.pulse_sequence.events[event].parameters[parameter].get_pixmap())
@ -135,9 +136,10 @@ class PulseProgrammerView(ModuleView):
result = dialog.exec() result = dialog.exec()
if result: if result:
selection = dialog.return_func() for option, function in dialog.return_functions.items():
logger.debug("Setting parameter %s of event %s to %s", parameter, event, selection) logger.debug("Setting option %s of parameter %s in event %s to %s", option, parameter, event, function())
self.module.model.pulse_sequence.events[event].parameters[parameter].set_options(selection) option.set_value(function())
self.set_parameter_icons() self.set_parameter_icons()
class OptionsDialog(QDialog): class OptionsDialog(QDialog):
@ -155,27 +157,41 @@ class OptionsDialog(QDialog):
options = parameter.get_options() options = parameter.get_options()
# Based on these options we will now create our selection widget # Based on these options we will now create our selection widget
self.return_functions = OrderedDict()
# If the options are a list , we will create a QComboBox # If the options are a list , we will create a QComboBox
if options[0] == list: for key, option in options.items():
if option == list:
pass pass
# If the options are boolean, we will create a QCheckBox # If the options are boolean, we will create a QCheckBox
elif options[0] == bool: elif isinstance(option, BooleanOption):
check_box = QCheckBox() check_box = QCheckBox()
def checkbox_result(): def checkbox_result():
return check_box.isChecked() return check_box.isChecked()
check_box.setChecked(options[1]) check_box.setChecked(option.state)
self.layout.addWidget(check_box) self.layout.addWidget(check_box)
self.return_func = checkbox_result self.return_functions[option] = checkbox_result
# If the options are a float/int we will create a QSpinBox # If the options are a float/int we will create a QSpinBox
elif options[0] == float or options[0] == int: elif isinstance(option, NumericOption):
pass numeric_layout = QHBoxLayout()
numeric_label = QLabel(key)
numeric_lineedit = QLineEdit(str(option.value))
numeric_layout.addWidget(numeric_label)
numeric_layout.addWidget(numeric_lineedit)
numeric_layout.addStretch(1)
self.layout.addLayout(numeric_layout)
self.return_functions[option] = numeric_lineedit.text
# If the options are a string we will create a QLineEdit # If the options are a string we will create a QLineEdit
elif options[0] == str: elif option == str:
pass pass
logger.debug("Return functions are: %s" % self.return_functions.items())
self.buttons = QDialogButtonBox( self.buttons = QDialogButtonBox(
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel, QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel,
self, self,
@ -185,9 +201,6 @@ class OptionsDialog(QDialog):
self.layout.addWidget(self.buttons) self.layout.addWidget(self.buttons)
def return_func(self):
return self.return_func
class AddEventDialog(QDialog): class AddEventDialog(QDialog):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent) super().__init__(parent)