Added string setting.

This commit is contained in:
jupfi 2024-03-02 20:58:46 +01:00
parent 235cd153d5
commit 4532c2c848
2 changed files with 21 additions and 2 deletions

View file

@ -5,7 +5,7 @@ from PyQt6.QtGui import QIcon
from PyQt6.QtCore import Qt, pyqtSlot from PyQt6.QtCore import Qt, pyqtSlot
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
from .settings import FloatSetting, IntSetting, BooleanSetting, SelectionSetting from .settings import FloatSetting, IntSetting, BooleanSetting, SelectionSetting, StringSetting
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -53,7 +53,7 @@ class BaseSpectrometerView(ModuleView):
setting_label.setMinimumWidth(200) setting_label.setMinimumWidth(200)
# Depending on the setting type we add different widgets to the view # 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 = QLineEdit(str(setting.value))
edit_widget.setMinimumWidth(100) edit_widget.setMinimumWidth(100)
# Connect the editingFinished signal to the on_value_changed slot of the setting # Connect the editingFinished signal to the on_value_changed slot of the setting

View file

@ -119,4 +119,23 @@ class IPSetting(Setting):
self._value = value self._value = value
except ValueError: except ValueError:
raise ValueError("Value must be a valid IP address") 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() self.settings_changed.emit()