Added visualization w. scientific notification. Fixed some bugs w. loading of settings.

This commit is contained in:
jupfi 2024-06-05 09:41:21 +02:00
parent 1e82d9030a
commit 2637db3320
2 changed files with 34 additions and 9 deletions

View file

@ -34,6 +34,10 @@ class BaseSpectrometerController(ModuleController):
def load_settings(self, path: str) -> None: def load_settings(self, path: str) -> None:
"""Loads the settings of the spectrometer.""" """Loads the settings of the spectrometer."""
if path is None:
logger.error("No settings file selected")
return
with open(path) as f: with open(path) as f:
json = f.read() json = f.read()

View file

@ -92,7 +92,6 @@ class VisualFloatSetting(VisualSetting):
def value(self, value): def value(self, value):
logger.debug(f"Setting {self.setting.name} to {value}") logger.debug(f"Setting {self.setting.name} to {value}")
self.setting.value = value self.setting.value = value
self.settings_changed.emit()
if self.widget: if self.widget:
if self.spin_box: if self.spin_box:
@ -120,14 +119,21 @@ class VisualIntSetting(VisualSetting):
super().__init__(setting) super().__init__(setting)
if setting.min_value is not None and setting.max_value is not None: if setting.min_value is not None and setting.max_value is not None:
self.widget = DuckSpinBox( if setting.scientific_notation:
min_value=setting.min_value, self.widget = DuckIntEdit(
max_value=setting.max_value, min_value=setting.min_value,
slider=setting.slider, max_value=setting.max_value,
double_box=False, )
) self.widget.setText(str(setting.default))
self.spin_box = True else:
self.widget.spin_box.setValue(setting.default) self.widget = DuckSpinBox(
min_value=setting.min_value,
max_value=setting.max_value,
slider=setting.slider,
double_box=False,
)
self.spin_box = True
self.widget.spin_box.setValue(setting.default)
else: else:
self.widget = DuckIntEdit( self.widget = DuckIntEdit(
@ -156,12 +162,18 @@ class VisualIntSetting(VisualSetting):
@value.setter @value.setter
def value(self, value): def value(self, value):
logger.debug(f"Setting {self.setting.name} to {value}") logger.debug(f"Setting {self.setting.name} to {value}")
# If the value is a str we save it
str_value = None
if isinstance(value, str):
str_value = value
value = int(float(value)) value = int(float(value))
self.setting.value = value self.setting.value = value
self.settings_changed.emit() self.settings_changed.emit()
if self.widget: if self.widget:
if self.spin_box: if self.spin_box:
self.widget.spin_box.setValue(value) self.widget.spin_box.setValue(value)
elif str_value is not None:
self.widget.setText(str_value)
else: else:
self.widget.setText(str(value)) self.widget.setText(str(value))
@ -324,3 +336,12 @@ class VisualStringSetting(VisualSetting):
lambda x=widget, s=self: s.on_value_changed(x.text()) lambda x=widget, s=self: s.on_value_changed(x.text())
) )
return widget return widget
def on_value_changed(self, value):
"""Update the value of the setting.
Args:
value (str): The new value of the setting.
"""
self.value = value
self.settings_changed.emit()