mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
refactor: yaml_dialog.py save/load logic changed
This commit is contained in:
@ -9,7 +9,8 @@ def load_yaml(instance) -> dict:
|
||||
instance, "Load Settings", "", "YAML Files (*.yaml *.yml);;All Files (*)", options=options
|
||||
)
|
||||
|
||||
if file_path:
|
||||
if not file_path:
|
||||
return None
|
||||
try:
|
||||
with open(file_path, "r") as file:
|
||||
config = yaml.safe_load(file)
|
||||
@ -21,9 +22,6 @@ def load_yaml(instance) -> dict:
|
||||
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
|
||||
|
||||
|
||||
def save_yaml(instance, config: dict) -> None:
|
||||
options = QFileDialog.Options()
|
||||
@ -32,7 +30,8 @@ def save_yaml(instance, config: dict) -> None:
|
||||
instance, "Save Settings", "", "YAML Files (*.yaml *.yml);;All Files (*)", options=options
|
||||
)
|
||||
|
||||
if file_path:
|
||||
if not file_path:
|
||||
return None
|
||||
try:
|
||||
if not (file_path.endswith(".yaml") or file_path.endswith(".yml")):
|
||||
file_path += ".yaml"
|
||||
@ -42,6 +41,3 @@ def save_yaml(instance, config: dict) -> None:
|
||||
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
|
||||
|
Reference in New Issue
Block a user