Implemented categories for settings.

This commit is contained in:
jupfi 2023-07-13 10:47:17 +02:00
parent 6f538215ba
commit 5c57bf2a96
2 changed files with 31 additions and 21 deletions

View file

@ -11,8 +11,10 @@ class BaseSpectrometerModel(ModuleModel):
self.settings = OrderedDict() self.settings = OrderedDict()
self.pulse_parameter_options = OrderedDict() self.pulse_parameter_options = OrderedDict()
def add_setting(self, name, value, description) -> None: def add_setting(self, name, value, description, category) -> None:
self.settings[name] = self.Setting(name, value, description) if category not in self.settings.keys():
self.settings[category] = []
self.settings[category].append(self.Setting(name, value, description))
def add_pulse_parameter_option(self, name, pulse_parameter_class) -> None: def add_pulse_parameter_option(self, name, pulse_parameter_class) -> None:
self.pulse_parameter_options[name] = pulse_parameter_class self.pulse_parameter_options[name] = pulse_parameter_class

View file

@ -1,5 +1,5 @@
import logging import logging
from PyQt6.QtWidgets import QWidget, QLabel, QLineEdit, QHBoxLayout, QSizePolicy from PyQt6.QtWidgets import QWidget, QLabel, QLineEdit, QHBoxLayout, QSizePolicy, QSpacerItem
from nqrduck.module.module_view import ModuleView from nqrduck.module.module_view import ModuleView
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -27,24 +27,32 @@ class BaseSpectrometerView(ModuleView):
self._ui_form.verticalLayout.setSpacing(5) self._ui_form.verticalLayout.setSpacing(5)
self._ui_form.verticalLayout.addWidget(label) self._ui_form.verticalLayout.addWidget(label)
for setting in self.module.model.settings.values(): for category in self.module.model.settings.keys():
logger.debug("Adding setting to settings view: %s", setting.name) logger.debug("Adding settings for category: %s", category)
# Create a label for the setting category_label = QLabel("%s:" % category)
label = QLabel(setting.name) category_label.setStyleSheet("font-weight: underline;")
label.setMinimumWidth(120) self._ui_form.verticalLayout.addWidget(category_label)
# Add an QLineEdit for the setting for setting in self.module.model.settings[category]:
line_edit = QLineEdit(str(setting.value)) logger.debug("Adding setting to settings view: %s", setting.name)
line_edit.setMinimumWidth(100)
# Add a horizontal layout for the setting spacer = QSpacerItem(20, 20)
layout = QHBoxLayout() # Create a label for the setting
# Connect the editingFinished signal to the on_value_changed slot of the setting setting_label = QLabel(setting.name)
line_edit.editingFinished.connect(lambda: setting.on_value_changed(line_edit.text())) setting_label.setMinimumWidth(200)
# Add the label and the line edit to the layout # Add an QLineEdit for the setting
layout.addWidget(label) line_edit = QLineEdit(str(setting.value))
layout.addWidget(line_edit) line_edit.setMinimumWidth(100)
layout.addStretch(1) # Add a horizontal layout for the setting
# Add the layout to the vertical layout of the widget layout = QHBoxLayout()
self._ui_form.verticalLayout.addLayout(layout) # Connect the editingFinished signal to the on_value_changed slot of the setting
line_edit.editingFinished.connect(lambda: setting.on_value_changed(line_edit.text()))
# Add the label and the line edit to the layout
layout.addItem(spacer)
layout.addWidget(setting_label)
layout.addWidget(line_edit)
layout.addStretch(1)
# Add the layout to the vertical layout of the widget
self._ui_form.verticalLayout.addLayout(layout)
# Push all the settings to the top of the widget # Push all the settings to the top of the widget
self._ui_form.verticalLayout.addStretch(1) self._ui_form.verticalLayout.addStretch(1)