Implemented default_settings.

This commit is contained in:
jupfi 2024-05-26 16:21:28 +02:00
parent 3af5b8603a
commit f94ff08411
4 changed files with 34 additions and 0 deletions

View file

@ -1,8 +1,10 @@
"""Base class for all spectrometer controllers."""
import logging
import ast
from nqrduck.module.module_controller import ModuleController
logger = logging.getLogger(__name__)
class BaseSpectrometerController(ModuleController):
"""The base class for all spectrometer controllers."""
@ -11,6 +13,11 @@ class BaseSpectrometerController(ModuleController):
"""Initializes the spectrometer controller."""
super().__init__(module)
def on_loading(self):
"""Called when the module is loading."""
logger.debug("Loading spectrometer controller")
self.module.model.load_default_settings()
def save_settings(self, path: str) -> None:
"""Saves the settings of the spectrometer."""
# We get the different settings objects from the model

View file

@ -2,6 +2,7 @@
import logging
from collections import OrderedDict
from PyQt6.QtCore import QSettings
from PyQt6.QtGui import QPixmap
from nqrduck.module.module_model import ModuleModel
from .settings import Setting
@ -101,6 +102,25 @@ class BaseSpectrometerModel(ModuleModel):
super().__init__(module)
self.settings = OrderedDict()
self.pulse_parameter_options = OrderedDict()
self.default_settings = QSettings("nqrduck-spectrometer", "nqrduck")
def set_default_settings(self) -> None:
"""Sets the default settings of the spectrometer."""
self.default_settings.clear()
for category in self.settings.keys():
for setting in self.settings[category]:
setting_string = f"{self.module.model.name},{setting.name}"
self.default_settings.setValue(setting_string, setting.value)
logger.debug(f"Setting default value for {setting_string} to {setting.value}")
def load_default_settings(self) -> None:
"""Load the default settings of the spectrometer."""
for category in self.settings.keys():
for setting in self.settings[category]:
setting_string = f"{self.module.model.name},{setting.name}"
if self.default_settings.contains(setting_string):
logger.debug(f"Loading default value for {setting_string}")
setting.value = self.default_settings.value(setting_string)
def add_setting(self, setting: Setting, category: str) -> None:
"""Adds a setting to the spectrometer.

View file

@ -96,6 +96,11 @@ class BaseSpectrometerView(ModuleView):
# Now we add a save and load button to the widget
self.button_layout = QHBoxLayout()
# Default Settings Button
self.default_button = QPushButton("Default Settings")
self.default_button.clicked.connect(self.module.model.set_default_settings)
self.button_layout.addWidget(self.default_button)
# Save Button
self.save_button = QPushButton("Save Settings")
self.save_button.setIcon(Logos.Save16x16())

View file

@ -43,6 +43,8 @@ class SpectrometerController(ModuleController):
logger.debug("Adding spectrometer to spectrometer model: %s", module_name)
self._module.model.add_spectrometers(module_name, module)
module.controller.on_loading()
self._module.view.create_menu_entry()
def process_signals(self, key: str, value: object) -> None: