menu stuff
This commit is contained in:
parent
5a7bc985b4
commit
98f40179e1
|
@ -1,20 +1,31 @@
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import matplotlib as mpl
|
import matplotlib as mpl
|
||||||
|
import numpy as np
|
||||||
from gui_helpers import FlowLayout
|
from gui_helpers import FlowLayout
|
||||||
from matplotlib import pyplot as plt
|
from matplotlib import pyplot as plt
|
||||||
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
|
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
|
||||||
from matplotlib.ticker import EngFormatter
|
from matplotlib.ticker import EngFormatter
|
||||||
from PySide6.QtCore import QSize, Qt
|
from PySide6.QtCore import QSize, Qt
|
||||||
|
from PySide6.QtGui import QAction, QKeySequence, QShortcut
|
||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QApplication,
|
QApplication,
|
||||||
QMainWindow,
|
QMainWindow,
|
||||||
|
QMenu,
|
||||||
|
QMenuBar,
|
||||||
QPushButton,
|
QPushButton,
|
||||||
|
QToolBar,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
QWidget,
|
QWidget,
|
||||||
)
|
)
|
||||||
from skrf import plotting as rf_plt
|
from skrf import plotting as rf_plt
|
||||||
|
|
||||||
|
DEFAULT_CONFIG = dict(
|
||||||
|
frequency=np.arange(1e9, 2e9, 11), # Hz
|
||||||
|
power=-5, # dB
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PlotWidget(QWidget):
|
class PlotWidget(QWidget):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -31,6 +42,10 @@ class PlotWidget(QWidget):
|
||||||
canvas = FigureCanvasQTAgg(self.fig)
|
canvas = FigureCanvasQTAgg(self.fig)
|
||||||
layout.addWidget(canvas)
|
layout.addWidget(canvas)
|
||||||
|
|
||||||
|
# toolbar = QToolBar("Toolbar")
|
||||||
|
# toolbar.addAction("blah")
|
||||||
|
# self.addToolBar(toolbar)
|
||||||
|
|
||||||
def setup_rect(self):
|
def setup_rect(self):
|
||||||
self.ax.grid(True)
|
self.ax.grid(True)
|
||||||
self.ax.xaxis.set_major_formatter(EngFormatter())
|
self.ax.xaxis.set_major_formatter(EngFormatter())
|
||||||
|
@ -54,38 +69,71 @@ class PlotWidget(QWidget):
|
||||||
|
|
||||||
# Subclass QMainWindow to customize your application's main window
|
# Subclass QMainWindow to customize your application's main window
|
||||||
class MainWindow(QMainWindow):
|
class MainWindow(QMainWindow):
|
||||||
|
config_path: Path | None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
self.config_path = None
|
||||||
|
|
||||||
mpl.use("QtAgg")
|
mpl.use("QtAgg")
|
||||||
|
|
||||||
self.setWindowTitle("Charon VNA")
|
self.setWindowTitle("Charon VNA")
|
||||||
|
|
||||||
config_column = QVBoxLayout()
|
# Menu
|
||||||
|
menubar = self.menuBar()
|
||||||
|
|
||||||
# save/restore device settings
|
menu_file = QMenu("&File")
|
||||||
btn_load_config = QPushButton("Load Configuration")
|
menubar.addMenu(menu_file)
|
||||||
btn_save_config = QPushButton("Save Configuration")
|
action_load_config = QAction("&Open Configuration", self)
|
||||||
# TODO: implement load/save config
|
menu_file.addAction(action_load_config)
|
||||||
btn_load_config.setEnabled(False)
|
action_load_config.triggered.connect(self.load_config)
|
||||||
btn_save_config.setEnabled(False)
|
QShortcut(QKeySequence("Ctrl+O"), self).activated.connect(self.load_config)
|
||||||
config_column.addWidget(btn_load_config)
|
action_save_config = QAction("&Save Configuration", self)
|
||||||
config_column.addWidget(btn_save_config)
|
menu_file.addAction(action_save_config)
|
||||||
|
action_save_config.triggered.connect(self.save_config)
|
||||||
|
QShortcut(QKeySequence("Ctrl+S"), self).activated.connect(self.save_config)
|
||||||
|
action_saveas_config = QAction("Save Configuration &As", self)
|
||||||
|
menu_file.addAction(action_saveas_config)
|
||||||
|
action_saveas_config.triggered.connect(self.saveas_config)
|
||||||
|
QShortcut(QKeySequence("Ctrl+Shift+S"), self).activated.connect(self.saveas_config)
|
||||||
|
|
||||||
plot_layout = FlowLayout()
|
menu_stimulus = QMenu("&Stimulus")
|
||||||
|
menubar.addMenu(menu_stimulus)
|
||||||
|
|
||||||
|
menu_calibration = QMenu("&Calibration")
|
||||||
|
menubar.addMenu(menu_calibration)
|
||||||
|
|
||||||
|
# Content
|
||||||
|
plot_layout = QVBoxLayout()
|
||||||
# TODO: handle plots properly
|
# TODO: handle plots properly
|
||||||
for i in range(10):
|
for i in range(1):
|
||||||
plot0 = PlotWidget()
|
plot0 = PlotWidget()
|
||||||
plot_layout.addWidget(plot0)
|
plot_layout.addWidget(plot0)
|
||||||
plot_flow_widget = QWidget()
|
|
||||||
plot_flow_widget.setLayout(plot_layout)
|
|
||||||
config_column.addWidget(plot_flow_widget)
|
|
||||||
|
|
||||||
# Set the central widget of the Window.
|
# Set the central widget of the Window.
|
||||||
widget = QWidget()
|
widget = QWidget()
|
||||||
widget.setLayout(config_column)
|
widget.setLayout(plot_layout)
|
||||||
self.setCentralWidget(widget)
|
self.setCentralWidget(widget)
|
||||||
|
|
||||||
|
def saveas_config(self):
|
||||||
|
print("Prompting for save path...")
|
||||||
|
# TODO: prompt for config path
|
||||||
|
self.config_path = Path(__file__).parent / "config.json"
|
||||||
|
print(f"Config path is now {self.config_path.resolve()}")
|
||||||
|
self.save_config()
|
||||||
|
|
||||||
|
def save_config(self):
|
||||||
|
if self.config_path is None:
|
||||||
|
self.saveas_config()
|
||||||
|
else:
|
||||||
|
print(f"saving config to {self.config_path.resolve()}")
|
||||||
|
# TODO: save config
|
||||||
|
|
||||||
|
def load_config(self):
|
||||||
|
print("loading config")
|
||||||
|
# TODO: load config
|
||||||
|
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user