From 4532c2c8485cffd6247d103105dd0217cc75e334 Mon Sep 17 00:00:00 2001 From: jupfi Date: Sat, 2 Mar 2024 20:58:46 +0100 Subject: [PATCH] Added string setting. --- .../base_spectrometer_view.py | 4 ++-- src/nqrduck_spectrometer/settings.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/nqrduck_spectrometer/base_spectrometer_view.py b/src/nqrduck_spectrometer/base_spectrometer_view.py index 5834565..7e955cc 100644 --- a/src/nqrduck_spectrometer/base_spectrometer_view.py +++ b/src/nqrduck_spectrometer/base_spectrometer_view.py @@ -5,7 +5,7 @@ from PyQt6.QtGui import QIcon from PyQt6.QtCore import Qt, pyqtSlot from nqrduck.module.module_view import ModuleView from nqrduck.assets.icons import Logos -from .settings import FloatSetting, IntSetting, BooleanSetting, SelectionSetting +from .settings import FloatSetting, IntSetting, BooleanSetting, SelectionSetting, StringSetting logger = logging.getLogger(__name__) @@ -53,7 +53,7 @@ class BaseSpectrometerView(ModuleView): setting_label.setMinimumWidth(200) # Depending on the setting type we add different widgets to the view - if isinstance(setting, FloatSetting) or isinstance(setting, IntSetting): + if isinstance(setting, FloatSetting) or isinstance(setting, IntSetting) or isinstance(setting, StringSetting): edit_widget = QLineEdit(str(setting.value)) edit_widget.setMinimumWidth(100) # Connect the editingFinished signal to the on_value_changed slot of the setting diff --git a/src/nqrduck_spectrometer/settings.py b/src/nqrduck_spectrometer/settings.py index 706d311..36a3e07 100644 --- a/src/nqrduck_spectrometer/settings.py +++ b/src/nqrduck_spectrometer/settings.py @@ -119,4 +119,23 @@ class IPSetting(Setting): self._value = value except ValueError: raise ValueError("Value must be a valid IP address") + self.settings_changed.emit() + +class StringSetting(Setting): + """ A setting that is a string.""" + def __init__(self, name : str, default : str, description : str) -> None: + super().__init__(name, description) + self.value = default + + @property + def value(self): + return self._value + + @value.setter + def value(self, value): + try: + self._value = str(value) + except ValueError: + raise ValueError("Value must be a string") + self.settings_changed.emit() \ No newline at end of file