some config stuff
This commit is contained in:
parent
3369bb290a
commit
22a33c2b84
|
@ -14,6 +14,8 @@ from numpy import typing as npt
|
||||||
from PySide6.QtGui import QAction, QKeySequence
|
from PySide6.QtGui import QAction, QKeySequence
|
||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QApplication,
|
QApplication,
|
||||||
|
QFileDialog,
|
||||||
|
QInputDialog,
|
||||||
QMainWindow,
|
QMainWindow,
|
||||||
QMenu,
|
QMenu,
|
||||||
QProgressBar,
|
QProgressBar,
|
||||||
|
@ -33,6 +35,8 @@ DEFAULT_CONFIG = dict(
|
||||||
power=-5, # dB
|
power=-5, # dB
|
||||||
)
|
)
|
||||||
|
|
||||||
|
CONFIG_SUFFIX = ".json"
|
||||||
|
|
||||||
|
|
||||||
class PlotWidget(QWidget):
|
class PlotWidget(QWidget):
|
||||||
traces: List[Tuple[int | str]]
|
traces: List[Tuple[int | str]]
|
||||||
|
@ -157,6 +161,7 @@ class MainWindow(QMainWindow):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.config_path = None
|
self.config_path = None
|
||||||
|
self._frequency = np.linspace(1e9, 2e9, 101) # TODO: read frequency from config
|
||||||
|
|
||||||
# self.device = Charon("ip:192.168.3.1", frequency=DEFAULT_CONFIG["frequency"])
|
# self.device = Charon("ip:192.168.3.1", frequency=DEFAULT_CONFIG["frequency"])
|
||||||
|
|
||||||
|
@ -169,10 +174,10 @@ class MainWindow(QMainWindow):
|
||||||
|
|
||||||
menu_file = QMenu("&File")
|
menu_file = QMenu("&File")
|
||||||
menubar.addMenu(menu_file)
|
menubar.addMenu(menu_file)
|
||||||
action_load_config = QAction("&Open Configuration", self)
|
action_open_config = QAction("&Open Configuration", self)
|
||||||
menu_file.addAction(action_load_config)
|
menu_file.addAction(action_open_config)
|
||||||
action_load_config.triggered.connect(self.load_config)
|
action_open_config.triggered.connect(self.open_config)
|
||||||
action_load_config.setShortcut(QKeySequence("Ctrl+O"))
|
action_open_config.setShortcut(QKeySequence("Ctrl+O"))
|
||||||
action_save_config = QAction("&Save Configuration", self)
|
action_save_config = QAction("&Save Configuration", self)
|
||||||
menu_file.addAction(action_save_config)
|
menu_file.addAction(action_save_config)
|
||||||
action_save_config.triggered.connect(self.save_config)
|
action_save_config.triggered.connect(self.save_config)
|
||||||
|
@ -186,7 +191,7 @@ class MainWindow(QMainWindow):
|
||||||
menubar.addMenu(menu_stimulus)
|
menubar.addMenu(menu_stimulus)
|
||||||
action_set_frequency = QAction("&Frequency", self)
|
action_set_frequency = QAction("&Frequency", self)
|
||||||
menu_stimulus.addAction(action_set_frequency)
|
menu_stimulus.addAction(action_set_frequency)
|
||||||
# action_set_frequency.triggered.connect(self.set_frequency)
|
action_set_frequency.triggered.connect(self.set_frequency)
|
||||||
action_set_power = QAction("&Power", self)
|
action_set_power = QAction("&Power", self)
|
||||||
menu_stimulus.addAction(action_set_power)
|
menu_stimulus.addAction(action_set_power)
|
||||||
# action_set_power.triggered.connect(self.set_power)
|
# action_set_power.triggered.connect(self.set_power)
|
||||||
|
@ -230,24 +235,51 @@ class MainWindow(QMainWindow):
|
||||||
|
|
||||||
def saveas_config(self) -> None:
|
def saveas_config(self) -> None:
|
||||||
print("Prompting for save path...")
|
print("Prompting for save path...")
|
||||||
# TODO: prompt for config path
|
dialog = QFileDialog(self)
|
||||||
self.config_path = Path(__file__).parent / "config.json"
|
dialog.setDefaultSuffix(CONFIG_SUFFIX)
|
||||||
print(f"Config path is now {self.config_path.resolve()}")
|
dialog.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
|
||||||
self.save_config()
|
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}"
|
||||||
|
)
|
||||||
|
self.config_path = config_path
|
||||||
|
print(f"Config path is now {self.config_path.resolve()}")
|
||||||
|
|
||||||
|
self.save_config()
|
||||||
|
|
||||||
|
def open_config(self) -> None:
|
||||||
|
print("Prompting for load path...")
|
||||||
|
dialog = QFileDialog(self)
|
||||||
|
dialog.setNameFilter(f"*{CONFIG_SUFFIX}")
|
||||||
|
dialog.setAcceptMode(QFileDialog.AcceptMode.AcceptOpen)
|
||||||
|
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}"
|
||||||
|
)
|
||||||
|
self.config_path = config_path
|
||||||
|
print(f"Config path is now {self.config_path.resolve()}")
|
||||||
|
|
||||||
|
self.load_config(self.config_path)
|
||||||
|
|
||||||
def save_config(self) -> None:
|
def save_config(self) -> None:
|
||||||
if self.config_path is None:
|
if self.config_path is None:
|
||||||
self.saveas_config()
|
self.saveas_config()
|
||||||
else:
|
else:
|
||||||
print(f"saving config to {self.config_path.resolve()}")
|
print(f"Saving config to {self.config_path.resolve()}")
|
||||||
# TODO: save config
|
# TODO: save config
|
||||||
|
|
||||||
def load_config(self) -> None:
|
def load_config(self, path: Path) -> None:
|
||||||
print("loading config")
|
print(f"Loading config from {path}...")
|
||||||
# TODO: load config
|
# TODO: load config
|
||||||
|
|
||||||
def generate_sim_data(self) -> None:
|
def generate_sim_data(self) -> None:
|
||||||
coords = {"frequency": np.linspace(1e9, 2e9, 101), "m": [1], "n": [1]}
|
coords = {"frequency": self._frequency, "m": [1], "n": [1]}
|
||||||
shape = tuple(len(v) for v in coords.values())
|
shape = tuple(len(v) for v in coords.values())
|
||||||
data = xr.DataArray(
|
data = xr.DataArray(
|
||||||
((-1 + 2 * np.random.rand(*shape)) + 1j * (-1 + 2 * np.random.rand(*shape))) / np.sqrt(2),
|
((-1 + 2 * np.random.rand(*shape)) + 1j * (-1 + 2 * np.random.rand(*shape))) / np.sqrt(2),
|
||||||
|
@ -258,6 +290,20 @@ class MainWindow(QMainWindow):
|
||||||
for plot in self.plots:
|
for plot in self.plots:
|
||||||
plot.update_plot(data)
|
plot.update_plot(data)
|
||||||
|
|
||||||
|
def set_frequency(self, *, frequency: npt.ArrayLike | None = None):
|
||||||
|
print(frequency)
|
||||||
|
if frequency is None:
|
||||||
|
start, ok = QInputDialog.getDouble(
|
||||||
|
self, "Start Frequency", "Start Frequency", minValue=30e6, maxValue=6e9, value=1e9
|
||||||
|
)
|
||||||
|
stop, ok = QInputDialog.getDouble(
|
||||||
|
self, "Stop Frequency", "Stop Frequency", minValue=30e6, maxValue=6e9, value=2e9
|
||||||
|
)
|
||||||
|
points, ok = QInputDialog.getInt(self, "Points", "Points", minValue=2, value=101)
|
||||||
|
frequency = np.linspace(start, stop, points)
|
||||||
|
# Currently does not support zero span
|
||||||
|
self._frequency = frequency
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user