From 2285bb78c1b743ab59fcaec84392b535f0e949a4 Mon Sep 17 00:00:00 2001 From: Brendan Haines Date: Thu, 16 Jan 2025 23:17:40 -0700 Subject: [PATCH] minor config stuf --- charon_vna/gui.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/charon_vna/gui.py b/charon_vna/gui.py index 8d94bea..893e0b8 100644 --- a/charon_vna/gui.py +++ b/charon_vna/gui.py @@ -154,8 +154,8 @@ class MainWindow(QMainWindow): def __init__(self): super().__init__() - self.config_path = None - with open(DEFAULT_CONFIG, "r") as f: + self.config_path = DEFAULT_CONFIG + with open(self.config_path, "r") as f: config = json.load(f) self._frequency = config["frequency"] @@ -234,11 +234,12 @@ class MainWindow(QMainWindow): dialog.setAcceptMode(QFileDialog.AcceptMode.AcceptSave) if dialog.exec(): config_path = Path(dialog.selectedFiles()[0]) - print(config_path) if config_path.suffix != CONFIG_SUFFIX: raise ValueError( f"{config_path.name} is not a valid configuration file. Must have extension {CONFIG_SUFFIX}" ) + if config_path == DEFAULT_CONFIG: + raise ValueError(f"Cannot overwrite default configuration file at {DEFAULT_CONFIG}") self.config_path = config_path print(f"Config path is now {self.config_path.resolve()}") @@ -262,7 +263,7 @@ class MainWindow(QMainWindow): self.load_config(self.config_path) def save_config(self) -> None: - if self.config_path is None: + if self.config_path == DEFAULT_CONFIG: self.saveas_config() else: print(f"Saving config to {self.config_path.resolve()}")