adjustable ip address at runtime

This commit is contained in:
Brendan Haines 2025-01-16 23:39:19 -07:00
parent 926a6abf1f
commit fa80af8447

View File

@ -1,5 +1,6 @@
# %% imports
import json
import re
import sys
from pathlib import Path
from typing import List
@ -13,6 +14,7 @@ from PySide6.QtWidgets import (
QApplication,
QFileDialog,
QInputDialog,
QLineEdit,
QMainWindow,
QMenu,
QProgressBar,
@ -34,7 +36,7 @@ class MainWindow(QMainWindow):
plots: List[PlotWidget]
def __init__(self):
def __init__(self, uri: str | None = None):
super().__init__()
self.config_path = DEFAULT_CONFIG
@ -42,7 +44,12 @@ class MainWindow(QMainWindow):
config = json.load(f)
self._frequency = config["frequency"]
self.vna = Charon("ip:192.168.3.1", frequency=self._frequency)
vna_kwargs = dict(
frequency=self._frequency,
)
if uri is not None:
vna_kwargs["uri"] = uri
self.vna = Charon(**vna_kwargs)
mpl.use("QtAgg")
@ -194,7 +201,20 @@ class MainWindow(QMainWindow):
def main() -> None:
app = QApplication(sys.argv)
window = MainWindow()
try:
window = MainWindow()
except Exception as e:
if e.args[0] == "No device found":
dialog = QInputDialog()
text, ok = dialog.getText(None, "Pluto IP Address", "IP Address", QLineEdit.Normal, "")
match = re.match(r"(\d{1,3}\.){3}\d{1,3}", text)
if not match:
raise ValueError(f"Invalid IP address: {text}")
uri = f"ip:{text}"
window = MainWindow(uri=uri)
else:
raise e
window.show()
app.exec()