diff --git a/bec_widgets/qt_utils/yaml_dialog.py b/bec_widgets/qt_utils/yaml_dialog.py index 800ff50b..492ee4b0 100644 --- a/bec_widgets/qt_utils/yaml_dialog.py +++ b/bec_widgets/qt_utils/yaml_dialog.py @@ -9,20 +9,18 @@ def load_yaml(instance) -> dict: instance, "Load Settings", "", "YAML Files (*.yaml *.yml);;All Files (*)", options=options ) - if file_path: - try: - with open(file_path, "r") as file: - config = yaml.safe_load(file) - return config - - except FileNotFoundError: - print(f"The file {file_path} was not found.") - except Exception as e: - print(f"An error occurred while loading the settings from {file_path}: {e}") - return None # Return None on exception to indicate failure - if not file_path: return None + try: + with open(file_path, "r") as file: + config = yaml.safe_load(file) + return config + + except FileNotFoundError: + print(f"The file {file_path} was not found.") + except Exception as e: + print(f"An error occurred while loading the settings from {file_path}: {e}") + return None # Return None on exception to indicate failure def save_yaml(instance, config: dict) -> None: @@ -32,16 +30,14 @@ def save_yaml(instance, config: dict) -> None: instance, "Save Settings", "", "YAML Files (*.yaml *.yml);;All Files (*)", options=options ) - if file_path: - try: - if not (file_path.endswith(".yaml") or file_path.endswith(".yml")): - file_path += ".yaml" - - with open(file_path, "w") as file: - yaml.dump(config, file) - print(f"Settings saved to {file_path}") - except Exception as e: - print(f"An error occurred while saving the settings to {file_path}: {e}") - if not file_path: return None + try: + if not (file_path.endswith(".yaml") or file_path.endswith(".yml")): + file_path += ".yaml" + + with open(file_path, "w") as file: + yaml.dump(config, file) + print(f"Settings saved to {file_path}") + except Exception as e: + print(f"An error occurred while saving the settings to {file_path}: {e}")