menu stuff
All checks were successful
Publish Python 🐍 distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Successful in -41s
Publish Python 🐍 distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Has been skipped

This commit is contained in:
Brendan Haines 2024-12-18 22:35:16 -07:00
parent 5a7bc985b4
commit 98f40179e1

View File

@ -1,20 +1,31 @@
import sys
from pathlib import Path
import matplotlib as mpl
import numpy as np
from gui_helpers import FlowLayout
from matplotlib import pyplot as plt
from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg
from matplotlib.ticker import EngFormatter
from PySide6.QtCore import QSize, Qt
from PySide6.QtGui import QAction, QKeySequence, QShortcut
from PySide6.QtWidgets import (
QApplication,
QMainWindow,
QMenu,
QMenuBar,
QPushButton,
QToolBar,
QVBoxLayout,
QWidget,
)
from skrf import plotting as rf_plt
DEFAULT_CONFIG = dict(
frequency=np.arange(1e9, 2e9, 11), # Hz
power=-5, # dB
)
class PlotWidget(QWidget):
def __init__(self):
@ -31,6 +42,10 @@ class PlotWidget(QWidget):
canvas = FigureCanvasQTAgg(self.fig)
layout.addWidget(canvas)
# toolbar = QToolBar("Toolbar")
# toolbar.addAction("blah")
# self.addToolBar(toolbar)
def setup_rect(self):
self.ax.grid(True)
self.ax.xaxis.set_major_formatter(EngFormatter())
@ -54,38 +69,71 @@ class PlotWidget(QWidget):
# Subclass QMainWindow to customize your application's main window
class MainWindow(QMainWindow):
config_path: Path | None
def __init__(self):
super().__init__()
self.config_path = None
mpl.use("QtAgg")
self.setWindowTitle("Charon VNA")
config_column = QVBoxLayout()
# Menu
menubar = self.menuBar()
# save/restore device settings
btn_load_config = QPushButton("Load Configuration")
btn_save_config = QPushButton("Save Configuration")
# TODO: implement load/save config
btn_load_config.setEnabled(False)
btn_save_config.setEnabled(False)
config_column.addWidget(btn_load_config)
config_column.addWidget(btn_save_config)
menu_file = QMenu("&File")
menubar.addMenu(menu_file)
action_load_config = QAction("&Open Configuration", self)
menu_file.addAction(action_load_config)
action_load_config.triggered.connect(self.load_config)
QShortcut(QKeySequence("Ctrl+O"), self).activated.connect(self.load_config)
action_save_config = QAction("&Save Configuration", self)
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
for i in range(10):
for i in range(1):
plot0 = PlotWidget()
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.
widget = QWidget()
widget.setLayout(config_column)
widget.setLayout(plot_layout)
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)