mirror of
https://github.com/nqrduck/nqrduck-spectrometer.git
synced 2024-12-22 08:17:49 +00:00
Added visualization w. scientific notification. Fixed some bugs w. loading of settings.
This commit is contained in:
parent
1e82d9030a
commit
2637db3320
2 changed files with 34 additions and 9 deletions
|
@ -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()
|
||||||
|
|
||||||
|
|
|
@ -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,6 +119,13 @@ 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:
|
||||||
|
if setting.scientific_notation:
|
||||||
|
self.widget = DuckIntEdit(
|
||||||
|
min_value=setting.min_value,
|
||||||
|
max_value=setting.max_value,
|
||||||
|
)
|
||||||
|
self.widget.setText(str(setting.default))
|
||||||
|
else:
|
||||||
self.widget = DuckSpinBox(
|
self.widget = DuckSpinBox(
|
||||||
min_value=setting.min_value,
|
min_value=setting.min_value,
|
||||||
max_value=setting.max_value,
|
max_value=setting.max_value,
|
||||||
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue