Skip to content
Snippets Groups Projects
Commit db24ee83 authored by Conor Finn's avatar Conor Finn
Browse files

RE #27187 Load default if values from file invalid

parent 37d0dbff
No related branches found
No related tags found
No related merge requests found
...@@ -44,13 +44,21 @@ class EngineeringDiffractionGui(QtWidgets.QMainWindow, Ui_main_window): ...@@ -44,13 +44,21 @@ class EngineeringDiffractionGui(QtWidgets.QMainWindow, Ui_main_window):
self.set_on_settings_clicked(self.open_settings) self.set_on_settings_clicked(self.open_settings)
self.btn_settings.setIcon(get_icon("mdi.settings", "black", 1.2)) self.btn_settings.setIcon(get_icon("mdi.settings", "black", 1.2))
# Setup Tabs
# Setup Elements
self.setup_settings()
self.setup_calibration() self.setup_calibration()
self.setup_focus() self.setup_focus()
# Setup notifiers # Setup notifiers
self.setup_calibration_notifier() self.setup_calibration_notifier()
def setup_settings(self):
model = SettingsModel()
view = SettingsView(self)
self.settings_presenter = SettingsPresenter(model, view)
self.settings_presenter.load_settings_from_file_or_default()
def setup_calibration(self): def setup_calibration(self):
cal_model = CalibrationModel() cal_model = CalibrationModel()
cal_view = CalibrationView(parent=self.tabs) cal_view = CalibrationView(parent=self.tabs)
...@@ -87,10 +95,8 @@ class EngineeringDiffractionGui(QtWidgets.QMainWindow, Ui_main_window): ...@@ -87,10 +95,8 @@ class EngineeringDiffractionGui(QtWidgets.QMainWindow, Ui_main_window):
InterfaceManager().showCustomInterfaceHelp(self.doc) InterfaceManager().showCustomInterfaceHelp(self.doc)
def open_settings(self): def open_settings(self):
settings_view = SettingsView(self) self.settings_presenter.load_existing_settings()
settings_model = SettingsModel() self.settings_presenter.show()
self.settings_presenter = SettingsPresenter(settings_model, settings_view)
settings_view.show()
def get_rb_no(self): def get_rb_no(self):
return self.lineEdit_RBNumber.text() return self.lineEdit_RBNumber.text()
...@@ -22,15 +22,18 @@ class SettingsPresenter(object): ...@@ -22,15 +22,18 @@ class SettingsPresenter(object):
def __init__(self, model, view): def __init__(self, model, view):
self.model = model self.model = model
self.view = view self.view = view
self.load_existing_settings() self.settings = {}
# Connect view signals # Connect view signals
self.view.set_on_apply_clicked(self.save_new_settings) self.view.set_on_apply_clicked(self.save_new_settings)
self.view.set_on_ok_clicked(self.save_and_close_dialog) self.view.set_on_ok_clicked(self.save_and_close_dialog)
self.view.set_on_cancel_clicked(self.close_dialog) self.view.set_on_cancel_clicked(self.close_dialog)
def show(self):
self.view.show()
def load_existing_settings(self): def load_existing_settings(self):
self._load_settings_from_file() self.load_settings_from_file_or_default()
self._show_settings_in_view() self._show_settings_in_view()
def close_dialog(self): def close_dialog(self):
...@@ -59,7 +62,7 @@ class SettingsPresenter(object): ...@@ -59,7 +62,7 @@ class SettingsPresenter(object):
if self._validate_settings(self.settings): if self._validate_settings(self.settings):
self.model.set_settings_dict(self.settings) self.model.set_settings_dict(self.settings)
def _load_settings_from_file(self): def load_settings_from_file_or_default(self):
self.settings = self.model.get_settings_dict(SETTINGS_LIST) self.settings = self.model.get_settings_dict(SETTINGS_LIST)
if not self._validate_settings(self.settings): if not self._validate_settings(self.settings):
self.settings = DEFAULT_SETTINGS.copy() self.settings = DEFAULT_SETTINGS.copy()
...@@ -67,4 +70,8 @@ class SettingsPresenter(object): ...@@ -67,4 +70,8 @@ class SettingsPresenter(object):
@staticmethod @staticmethod
def _validate_settings(settings): def _validate_settings(settings):
return settings.keys() == SETTINGS_LIST all_keys = settings.keys() == SETTINGS_LIST
save_location = str(settings["save_location"])
save_valid = save_location is not "" and save_location is not None
recalc_valid = settings["recalc_vanadium"] is not None
return all_keys and save_valid and recalc_valid
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment