mirror of
https://github.com/nqrduck/nqrduck-spectrometer.git
synced 2025-01-05 07:08:07 +00:00
Fixed loading and saving of settings.
This commit is contained in:
parent
c1208103ca
commit
5100ee203c
3 changed files with 32 additions and 25 deletions
|
@ -16,19 +16,18 @@ class BaseSpectrometerController(ModuleController):
|
||||||
def on_loading(self):
|
def on_loading(self):
|
||||||
"""Called when the module is loading."""
|
"""Called when the module is loading."""
|
||||||
logger.debug("Loading spectrometer controller")
|
logger.debug("Loading spectrometer controller")
|
||||||
#self.module.model.load_default_settings()
|
self.module.model.load_default_settings()
|
||||||
|
|
||||||
def save_settings(self, path: str) -> None:
|
def save_settings(self, path: str) -> None:
|
||||||
"""Saves the settings of the spectrometer."""
|
"""Saves the settings of the spectrometer."""
|
||||||
# We get the different settings objects from the model
|
# We get the different settings objects from the model
|
||||||
settings = self.module.model.settings
|
settings = self.module.model.quackseq_model.settings
|
||||||
|
|
||||||
json = {}
|
json = {}
|
||||||
json["name"] = self.module.model.name
|
json["name"] = self.module.model.name
|
||||||
|
|
||||||
for category in settings.keys():
|
for setting in settings.values():
|
||||||
for setting in settings[category]:
|
json[setting.name] = setting.value
|
||||||
json[setting.name] = setting.value
|
|
||||||
|
|
||||||
with open(path, "w") as f:
|
with open(path, "w") as f:
|
||||||
f.write(str(json))
|
f.write(str(json))
|
||||||
|
@ -50,14 +49,13 @@ class BaseSpectrometerController(ModuleController):
|
||||||
self.module.nqrduck_signal.emit("notification", ["Error", message])
|
self.module.nqrduck_signal.emit("notification", ["Error", message])
|
||||||
return
|
return
|
||||||
|
|
||||||
settings = self.module.model.settings
|
visual_settings = self.module.model.quackseq_visuals
|
||||||
for category in settings.keys():
|
for visual_setting in visual_settings.values():
|
||||||
for setting in settings[category]:
|
if visual_setting.setting.name in json:
|
||||||
if setting.name in json:
|
visual_setting.value = json[visual_setting.setting.name]
|
||||||
setting.value = json[setting.name]
|
else:
|
||||||
else:
|
message = f"Setting {visual_setting.setting.name} not found in settings file. A change in settings might have broken compatibility."
|
||||||
message = f"Setting {setting.name} not found in settings file. A change in settings might have broken compatibility."
|
self.module.nqrduck_signal.emit("notification", ["Error", message])
|
||||||
self.module.nqrduck_signal.emit("notification", ["Error", message])
|
|
||||||
|
|
||||||
def start_measurement(self):
|
def start_measurement(self):
|
||||||
"""Starts the measurement.
|
"""Starts the measurement.
|
||||||
|
|
|
@ -18,8 +18,10 @@ class BaseSpectrometerModel(ModuleModel):
|
||||||
module (Module) : The module that the spectrometer is connected to
|
module (Module) : The module that the spectrometer is connected to
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
settings (OrderedDict) : The settings of the spectrometer
|
SETTING_FILE_EXTENSION (str) : The file extension for the settings file
|
||||||
pulse_parameter_options (OrderedDict) : The pulse parameter options of the spectrometer
|
default_settings (QSettings) : The default settings of the spectrometer
|
||||||
|
quackseq_model (QuackseqModel) : The quackseq model of the spectrometer
|
||||||
|
quackseq_visuals (dict) : The visual settings of the spectrometer
|
||||||
"""
|
"""
|
||||||
|
|
||||||
SETTING_FILE_EXTENSION = "setduck"
|
SETTING_FILE_EXTENSION = "setduck"
|
||||||
|
@ -62,18 +64,24 @@ class BaseSpectrometerModel(ModuleModel):
|
||||||
def set_default_settings(self) -> None:
|
def set_default_settings(self) -> None:
|
||||||
"""Sets the default settings of the spectrometer."""
|
"""Sets the default settings of the spectrometer."""
|
||||||
self.default_settings.clear()
|
self.default_settings.clear()
|
||||||
for category in self.settings.keys():
|
settings = self.quackseq_model.settings
|
||||||
for setting in self.settings[category]:
|
|
||||||
setting_string = f"{self.module.model.name},{setting.name}"
|
for setting in settings.values():
|
||||||
self.default_settings.setValue(setting_string, setting.value)
|
setting_string = f"{self.module.model.name},{setting.name}"
|
||||||
logger.debug(f"Setting default value for {setting_string} to {setting.value}")
|
self.default_settings.setValue(setting_string, setting.value)
|
||||||
|
logger.debug(f"Setting default value for {setting_string} to {setting.value}")
|
||||||
|
|
||||||
def load_default_settings(self) -> None:
|
def load_default_settings(self) -> None:
|
||||||
"""Load the default settings of the spectrometer."""
|
"""Load the default settings of the spectrometer."""
|
||||||
for setting in self.quackseq_model.settings.values():
|
visual_settings = self.quackseq_visuals
|
||||||
setting_string = f"{self.module.model.name},{setting.name}"
|
|
||||||
setting.value = self.default_settings.value(setting_string)
|
for visual_setting in visual_settings.values():
|
||||||
logger.debug(f"Setting {setting_string} to {setting.value}")
|
setting_string = f"{self.module.model.name},{visual_setting.setting.name}"
|
||||||
|
value = self.default_settings.value(setting_string)
|
||||||
|
if value is None:
|
||||||
|
logger.debug(f"Setting {setting_string} not found in default settings")
|
||||||
|
continue
|
||||||
|
visual_setting.value = value
|
||||||
|
|
||||||
def clear_default_settings(self) -> None:
|
def clear_default_settings(self) -> None:
|
||||||
"""Clear the default settings of the spectrometer."""
|
"""Clear the default settings of the spectrometer."""
|
||||||
|
|
|
@ -97,7 +97,8 @@ class VisualFloatSetting(VisualSetting):
|
||||||
if self.spin_box:
|
if self.spin_box:
|
||||||
self.widget.spin_box.setValue(self.setting.value)
|
self.widget.spin_box.setValue(self.setting.value)
|
||||||
else:
|
else:
|
||||||
self.widget.setText(str(self.setting.value))
|
value = float(value)
|
||||||
|
self.widget.set_value(value)
|
||||||
|
|
||||||
|
|
||||||
class VisualIntSetting(VisualSetting):
|
class VisualIntSetting(VisualSetting):
|
||||||
|
|
Loading…
Reference in a new issue