rename config path

This commit is contained in:
Brendan Haines 2025-04-12 22:35:04 -06:00
parent 505b374e8f
commit d8b1a56c99
3 changed files with 14 additions and 10 deletions

View File

@ -1,4 +1,8 @@
# Charon VNA
<!-- ![PyPi Downloads](https://img.shields.io/pypi/dm/charon-vna) -->
<!-- ![Last Commit](https://img.shields.io/gitea/last-commit/brendanhaines/charon-vna?gitea_url=https%3A%2F%2Fgit.brendanhaines.com) -->
<!-- ![Workflow Status](https://git.brendanhaines.com/brendanhaines/charon-vna/actions/workflows/python_publish.yml/badge.svg) -->
Named after [Pluto's moon](https://en.wikipedia.org/wiki/Charon_(moon)), Charon uses the [ADI Pluto SDR](https://www.analog.com/en/resources/evaluation-hardware-and-software/evaluation-boards-kits/adalm-pluto.html) as a vector network analyzer. The basic usage is as a 1 port VNA but this can be extended to arbitrarily many ports with the addition of a couple RF switches.

View File

@ -3,14 +3,14 @@ import subprocess
import numpy as np
from charon_vna.gui import DEFAULT_CONFIG
from charon_vna.gui import PATH_CONFIG_DEFAULT
config = dict(
frequency=np.linspace(80e6, 500e6, 500).tolist(),
power=-5,
)
with open(DEFAULT_CONFIG, "w") as f:
with open(PATH_CONFIG_DEFAULT, "w") as f:
json.dump(config, f)
# autoformat
@ -19,7 +19,7 @@ subprocess.run(
"python",
"-m",
"json.tool",
DEFAULT_CONFIG.resolve().as_posix(),
DEFAULT_CONFIG.resolve().as_posix(),
PATH_CONFIG_DEFAULT.resolve().as_posix(),
PATH_CONFIG_DEFAULT.resolve().as_posix(),
]
)

View File

@ -14,7 +14,6 @@ from numpy import typing as npt
from PySide6.QtGui import QAction, QKeySequence
from PySide6.QtWidgets import (
QApplication,
QDialogButtonBox,
QFileDialog,
QInputDialog,
QLineEdit,
@ -31,7 +30,7 @@ from charon_vna.util import net2s, s2net
from charon_vna.vna import Charon
# %%
DEFAULT_CONFIG = Path(__file__).parent / "config_default.json"
PATH_CONFIG_DEFAULT = Path(__file__).parent / "config_default.json"
CONFIG_SUFFIX = ".json"
@ -44,7 +43,7 @@ class MainWindow(QMainWindow):
def __init__(self, ip: str | None = None):
super().__init__()
self.config_path = DEFAULT_CONFIG
self.config_path = PATH_CONFIG_DEFAULT
with open(self.config_path, "r") as f:
config = json.load(f)
self._frequency = config["frequency"]
@ -129,6 +128,7 @@ class MainWindow(QMainWindow):
def saveas_config(self) -> None:
print("Prompting for save path...")
dialog = QFileDialog(self)
dialog.setNameFilter(f"*{CONFIG_SUFFIX}")
dialog.setDefaultSuffix(CONFIG_SUFFIX)
dialog.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
if dialog.exec():
@ -137,8 +137,8 @@ class MainWindow(QMainWindow):
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}")
if config_path == PATH_CONFIG_DEFAULT:
raise ValueError(f"Cannot overwrite default configuration file at {PATH_CONFIG_DEFAULT}")
self.config_path = config_path
print(f"Config path is now {self.config_path.resolve()}")
@ -162,7 +162,7 @@ class MainWindow(QMainWindow):
self.load_config(self.config_path)
def save_config(self) -> None:
if self.config_path == DEFAULT_CONFIG:
if self.config_path == PATH_CONFIG_DEFAULT:
self.saveas_config()
else:
print(f"Saving config to {self.config_path.resolve()}")