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.pulse_parameter_options = OrderedDict()
def add_setting(self, name, value, description) -> None:
self.settings[name] = self.Setting(name, value, description)
def add_setting(self, name, value, description, category) -> None:
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:
self.pulse_parameter_options[name] = pulse_parameter_class

View file

@ -1,5 +1,5 @@
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
logger = logging.getLogger(__name__)
@ -27,11 +27,18 @@ class BaseSpectrometerView(ModuleView):
self._ui_form.verticalLayout.setSpacing(5)
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 settings for category: %s", category)
category_label = QLabel("%s:" % category)
category_label.setStyleSheet("font-weight: underline;")
self._ui_form.verticalLayout.addWidget(category_label)
for setting in self.module.model.settings[category]:
logger.debug("Adding setting to settings view: %s", setting.name)
spacer = QSpacerItem(20, 20)
# Create a label for the setting
label = QLabel(setting.name)
label.setMinimumWidth(120)
setting_label = QLabel(setting.name)
setting_label.setMinimumWidth(200)
# Add an QLineEdit for the setting
line_edit = QLineEdit(str(setting.value))
line_edit.setMinimumWidth(100)
@ -40,7 +47,8 @@ class BaseSpectrometerView(ModuleView):
# 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.addWidget(label)
layout.addItem(spacer)
layout.addWidget(setting_label)
layout.addWidget(line_edit)
layout.addStretch(1)
# Add the layout to the vertical layout of the widget