adjustable ip address at runtime
This commit is contained in:
parent
926a6abf1f
commit
fa80af8447
|
@ -1,5 +1,6 @@
|
||||||
# %% imports
|
# %% imports
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import List
|
||||||
|
@ -13,6 +14,7 @@ from PySide6.QtWidgets import (
|
||||||
QApplication,
|
QApplication,
|
||||||
QFileDialog,
|
QFileDialog,
|
||||||
QInputDialog,
|
QInputDialog,
|
||||||
|
QLineEdit,
|
||||||
QMainWindow,
|
QMainWindow,
|
||||||
QMenu,
|
QMenu,
|
||||||
QProgressBar,
|
QProgressBar,
|
||||||
|
@ -34,7 +36,7 @@ class MainWindow(QMainWindow):
|
||||||
|
|
||||||
plots: List[PlotWidget]
|
plots: List[PlotWidget]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, uri: str | None = None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.config_path = DEFAULT_CONFIG
|
self.config_path = DEFAULT_CONFIG
|
||||||
|
@ -42,7 +44,12 @@ class MainWindow(QMainWindow):
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
self._frequency = config["frequency"]
|
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")
|
mpl.use("QtAgg")
|
||||||
|
|
||||||
|
@ -194,7 +201,20 @@ class MainWindow(QMainWindow):
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
app = QApplication(sys.argv)
|
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()
|
window.show()
|
||||||
|
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user