Added dialog for default settings.

This commit is contained in:
jupfi 2024-05-26 16:31:52 +02:00
parent f94ff08411
commit c14c047118
2 changed files with 64 additions and 5 deletions

View file

@ -122,6 +122,10 @@ class BaseSpectrometerModel(ModuleModel):
logger.debug(f"Loading default value for {setting_string}") logger.debug(f"Loading default value for {setting_string}")
setting.value = self.default_settings.value(setting_string) setting.value = self.default_settings.value(setting_string)
def clear_default_settings(self) -> None:
"""Clear the default settings of the spectrometer."""
self.default_settings.clear()
def add_setting(self, setting: Setting, category: str) -> None: def add_setting(self, setting: Setting, category: str) -> None:
"""Adds a setting to the spectrometer. """Adds a setting to the spectrometer.

View file

@ -9,6 +9,7 @@ from PyQt6.QtWidgets import (
QSpacerItem, QSpacerItem,
QVBoxLayout, QVBoxLayout,
QPushButton, QPushButton,
QDialog,
) )
from nqrduck.module.module_view import ModuleView from nqrduck.module.module_view import ModuleView
from nqrduck.assets.icons import Logos from nqrduck.assets.icons import Logos
@ -98,7 +99,7 @@ class BaseSpectrometerView(ModuleView):
# Default Settings Button # Default Settings Button
self.default_button = QPushButton("Default Settings") self.default_button = QPushButton("Default Settings")
self.default_button.clicked.connect(self.module.model.set_default_settings) self.default_button.clicked.connect(self.on_default_button_clicked)
self.button_layout.addWidget(self.default_button) self.button_layout.addWidget(self.default_button)
# Save Button # Save Button
@ -141,3 +142,57 @@ class BaseSpectrometerView(ModuleView):
self.module.controller.load_settings(path) self.module.controller.load_settings(path)
if path: if path:
self.module.controller.load_settings(path) self.module.controller.load_settings(path)
def on_default_button_clicked(self):
"""This method is called when the default button is clicked."""
logger.debug("Default button clicked")
dialog = self.DefaultSettingsDialog(self)
dialog.exec()
class DefaultSettingsDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.parent = parent
self.setWindowTitle("Default Settings")
self.layout = QVBoxLayout()
# Either we set the current settings as default
self.set_current_button = QPushButton("Set Current Settings as Default")
self.set_current_button.clicked.connect(
self.on_set_current_button_clicked
)
# Or we clear the default settings
self.clear_button = QPushButton("Clear Default Settings")
self.clear_button.clicked.connect(
self.on_clear_button_clicked
)
self.layout.addWidget(self.set_current_button)
self.layout.addWidget(self.clear_button)
self.setLayout(self.layout)
# Ok Button
self.ok_button = QPushButton("Ok")
self.ok_button.clicked.connect(self.accept)
self.layout.addWidget(self.ok_button)
def on_set_current_button_clicked(self):
"""This method is called when the set current button is clicked."""
logger.debug("Set current button clicked")
self.parent.module.model.set_default_settings()
# Show notification that the settings have been set as default
self.parent.module.nqrduck_signal.emit(
"notification", ["Info", "Settings have been set as default."]
)
def on_clear_button_clicked(self):
"""This method is called when the clear button is clicked."""
logger.debug("Clear button clicked")
self.parent.module.model.clear_default_settings()
# Show notification that the default settings have been cleared
self.parent.module.nqrduck_signal.emit(
"notification", ["Info", "Default settings have been cleared."]
)