Add Device info widget

This commit is contained in:
CPD 2025-03-10 14:02:12 +01:00
parent 74745ad28f
commit 20ae68347c
2 changed files with 56 additions and 25 deletions

View File

@ -48,6 +48,16 @@ class MainWindow(QMainWindow):
central_widget = QWidget(self) central_widget = QWidget(self)
self.setCentralWidget(central_widget) self.setCentralWidget(central_widget)
# add qt actions that open help and about dialog
self.a_open_help = QAction(text="Help", parent=self)
self.a_open_help.setIcon(QIcon.fromTheme(QIcon.ThemeIcon.HelpFaq))
self.a_open_help.setShortcut(QKeySequence("F1"))
self.a_open_help.triggered.connect(lambda: self.app_open_help())
self.a_open_about = QAction(text="About", parent=self)
self.a_open_about.setIcon(QIcon.fromTheme(get_resource_path("icons/icon.svg")))
self.a_open_about.triggered.connect(lambda: self.app_open_about())
self.create_toolbars() self.create_toolbars()
self.setMenuBar(MenuBar(self)) # must come after toolbars self.setMenuBar(MenuBar(self)) # must come after toolbars
self.setStatusBar(QStatusBar(self)) self.setStatusBar(QStatusBar(self))
@ -71,7 +81,8 @@ class MainWindow(QMainWindow):
# Right: Tabs: Script, Plot # Right: Tabs: Script, Plot
self.w_right_tab = QTabWidget() self.w_right_tab = QTabWidget()
layout.addWidget(self.w_right_tab) layout.addWidget(self.w_right_tab)
self.w_plot = Plot() max_data_points = AppConfig.MAIN_CFG.get_or("plot_max_data_points", 3000)
self.w_plot = Plot(max_data_points=max_data_points)
self.w_right_tab.addTab(self.w_plot, "Plot") self.w_right_tab.addTab(self.w_plot, "Plot")
# LED SCRIPT # LED SCRIPT
@ -96,22 +107,9 @@ class MainWindow(QMainWindow):
self.set_status("Ready") self.set_status("Ready")
# add qt actions that open help and about dialog self.menuBar().m_file.addAction(self.a_open_about)
self.a_open_help = QAction(text="Help", parent=self)
self.a_open_help.setIcon(QIcon.fromTheme(QIcon.ThemeIcon.HelpFaq))
self.a_open_help.setShortcut(QKeySequence("F1"))
self.a_open_help.triggered.connect(lambda: self.app_open_help())
self.a_open_about = QAction(text="About", parent=self)
self.a_open_about.setIcon(QIcon.fromTheme(QIcon.ThemeIcon.HelpAbout))
self.a_open_about.triggered.connect(lambda: self.app_open_about())
self.topbar.addAction(self.a_open_help)
self.topbar.addAction(self.a_open_about)
self.menuBar().m_file.addAction(self.a_open_help) self.menuBar().m_file.addAction(self.a_open_help)
# self.a_open_help.setShortcut(QKeySequence("F1"))
def set_status(self, msg): def set_status(self, msg):
self.statusBar().showMessage(msg) self.statusBar().showMessage(msg)
@ -130,8 +128,9 @@ class MainWindow(QMainWindow):
self.topbar.add_button("meas_start", "Start", QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart), self.measure_start) self.topbar.add_button("meas_start", "Start", QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStart), self.measure_start)
self.topbar.add_button("meas_stop", "Stop", QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStop), self.measure_stop) self.topbar.add_button("meas_stop", "Stop", QIcon.fromTheme(QIcon.ThemeIcon.MediaPlaybackStop), self.measure_stop)
self.topbar.add_button("meas_save", "Save", QIcon.fromTheme(QIcon.ThemeIcon.DocumentSaveAs), self.measurement_save) self.topbar.add_button("meas_save", "Save", QIcon.fromTheme(QIcon.ThemeIcon.DocumentSaveAs), self.measurement_save)
self.topbar.add_button("app_about", "About", get_resource_path("icons/icon.svg"), self.app_open_about)
self.topbar.add_separator() self.topbar.add_separator()
self.topbar.addAction(self.a_open_help)
self.topbar.addAction(self.a_open_about)
self.topbar.add_button("app_exit", "Exit", QIcon.fromTheme(QIcon.ThemeIcon.ApplicationExit), self.app_exit) self.topbar.add_button("app_exit", "Exit", QIcon.fromTheme(QIcon.ThemeIcon.ApplicationExit), self.app_exit)
self.addToolBar(Qt.ToolBarArea.TopToolBarArea, self.topbar) self.addToolBar(Qt.ToolBarArea.TopToolBarArea, self.topbar)
@ -157,6 +156,12 @@ class MainWindow(QMainWindow):
self.leddev = ledd.connect_device(leddev_type, leddev_name) self.leddev = ledd.connect_device(leddev_type, leddev_name)
AppConfig.MAIN_CFG.set("led_device_last.type", leddev_type) AppConfig.MAIN_CFG.set("led_device_last.type", leddev_type)
AppConfig.MAIN_CFG.set("led_device_last.name", leddev_name) AppConfig.MAIN_CFG.set("led_device_last.name", leddev_name)
# Update the settings widget value
self.w_measurement_settings.set_value("device_led_controller", str(self.leddev))
led_name = self.leddev.get_led_name()
if not led_name: led_name = "Unknown"
self.w_measurement_settings.set_value("device_led", led_name)
def leddev_autoconnect(self): def leddev_autoconnect(self):
if AppConfig.MAIN_CFG.get_or("led_device_auto_reconnect", False): if AppConfig.MAIN_CFG.get_or("led_device_auto_reconnect", False):
try: try:
@ -185,6 +190,8 @@ class MainWindow(QMainWindow):
self.vmdev = vmd.connect_device(vmdev_type, vmdev_name) self.vmdev = vmd.connect_device(vmdev_type, vmdev_name)
AppConfig.MAIN_CFG.set("voltage_measurement_device_last.type", vmdev_type) AppConfig.MAIN_CFG.set("voltage_measurement_device_last.type", vmdev_type)
AppConfig.MAIN_CFG.set("voltage_measurement_device_last.name", vmdev_name) AppConfig.MAIN_CFG.set("voltage_measurement_device_last.name", vmdev_name)
# Update the settings widget value
self.w_measurement_settings.set_value("device_voltage_measurement", str(self.vmdev))
def vmdev_autoconnect(self): def vmdev_autoconnect(self):
if AppConfig.MAIN_CFG.get_or("voltage_measurement_device_auto_reconnect", False): if AppConfig.MAIN_CFG.get_or("voltage_measurement_device_auto_reconnect", False):
@ -239,10 +246,6 @@ class MainWindow(QMainWindow):
metadata = self.w_metadata.get_dict() metadata = self.w_metadata.get_dict()
metadata["name"] = measurement_name metadata["name"] = measurement_name
metadata["led_script"] = str(script) metadata["led_script"] = str(script)
self.w_metadata.update_from_dict({
"interval": str(interval),
"led_script": str(script)
})
log.info(f"Starting measurement with:\n\tinterval = {interval}\n\tflush_after = {flush_after}\n\tuse_buffer = {use_buffer}\n\tmax_measurements = {max_measurements}\n\tstop_on_script_end = {stop_on_script_end}") log.info(f"Starting measurement with:\n\tinterval = {interval}\n\tflush_after = {flush_after}\n\tuse_buffer = {use_buffer}\n\tmax_measurements = {max_measurements}\n\tstop_on_script_end = {stop_on_script_end}")

View File

@ -6,6 +6,32 @@ from os import path
from ...utility.config import AppConfig from ...utility.config import AppConfig
class DeviceSelection(QGroupBox):
def __init__(self, parent=None):
super().__init__(parent=parent, title="Devices")
self.layout = QFormLayout()
self.setLayout(self.layout)
self.devices_widgets = {}
self._add_device("voltage_measurement", "Voltage Measurement", "N.C.")
self._add_device("led_controller", "Led Controller", "N.C.")
self._add_device("led", "Led Lamp", "Unknown")
# self.layout.addStretch(1)
def _add_device(self, key, label, name):
self.devices_widgets[key] = QLabel(name)
self.layout.addRow(QLabel(label), self.devices_widgets[key])
def set_value(self, key, value):
key = key.replace("device_", "")
if key in self.devices_widgets:
self.devices_widgets[key].setText(value)
else:
raise KeyError(f"Unknown device '{key}'")
class ScriptSelection(QGroupBox): class ScriptSelection(QGroupBox):
script_changed = pyqtSignal() script_changed = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
@ -93,12 +119,14 @@ class MeasurementSettings(QWidget):
# self.label = QLabel("Measurement Settings") # self.label = QLabel("Measurement Settings")
# self.layout.addWidget(self.label) # self.layout.addWidget(self.label)
self.setLayout(self.l_vbox) self.setLayout(self.l_vbox)
self.l_form = QFormLayout() # devices
self.w_device_selection = DeviceSelection()
self.l_vbox.addWidget(self.w_device_selection)
# - script # - script
self.w_led_script = ScriptSelection() self.w_led_script = ScriptSelection()
self.l_vbox.addWidget(self.w_led_script) self.l_vbox.addWidget(self.w_led_script)
# key-value stuff in a form # key-value stuff in a form
self.l_form = QFormLayout()
self.l_vbox.addLayout(self.l_form) self.l_vbox.addLayout(self.l_form)
self.ws_form = {} self.ws_form = {}
w_box_interval = QDoubleSpinBox(self) w_box_interval = QDoubleSpinBox(self)
@ -146,6 +174,8 @@ class MeasurementSettings(QWidget):
self.ws_form[key].setChecked(value) self.ws_form[key].setChecked(value)
else: else:
raise ValueError(f"Unknown widget type: {type(self.ws_form[key])}") raise ValueError(f"Unknown widget type: {type(self.ws_form[key])}")
elif key.startswith("device_"):
self.w_device_selection.set_value(key, value)
else: else:
raise ValueError(f"Unknown key: {key}") raise ValueError(f"Unknown key: {key}")
@ -161,6 +191,4 @@ class MeasurementSettings(QWidget):
elif key == "led_script": elif key == "led_script":
return self.w_led_script.get_script() return self.w_led_script.get_script()
else: else:
raise ValueError(f"Unknown key: {key}") raise ValueError(f"Unknown key: {key}")