From 20ae68347c66eaa75117754c2c02ff14bc603b13 Mon Sep 17 00:00:00 2001 From: CPD Date: Mon, 10 Mar 2025 14:02:12 +0100 Subject: [PATCH] Add Device info widget --- cpdctrl_gui/ui/main_window.py | 43 ++++++++++--------- .../ui/widgets/measurement_settings.py | 38 +++++++++++++--- 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/cpdctrl_gui/ui/main_window.py b/cpdctrl_gui/ui/main_window.py index 6292383..849a937 100644 --- a/cpdctrl_gui/ui/main_window.py +++ b/cpdctrl_gui/ui/main_window.py @@ -48,6 +48,16 @@ class MainWindow(QMainWindow): central_widget = QWidget(self) 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.setMenuBar(MenuBar(self)) # must come after toolbars self.setStatusBar(QStatusBar(self)) @@ -71,7 +81,8 @@ class MainWindow(QMainWindow): # Right: Tabs: Script, Plot self.w_right_tab = QTabWidget() 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") # LED SCRIPT @@ -96,22 +107,9 @@ class MainWindow(QMainWindow): self.set_status("Ready") - # 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(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_about) self.menuBar().m_file.addAction(self.a_open_help) - # self.a_open_help.setShortcut(QKeySequence("F1")) - def set_status(self, 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_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("app_about", "About", get_resource_path("icons/icon.svg"), self.app_open_about) 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.addToolBar(Qt.ToolBarArea.TopToolBarArea, self.topbar) @@ -157,6 +156,12 @@ class MainWindow(QMainWindow): 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.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): if AppConfig.MAIN_CFG.get_or("led_device_auto_reconnect", False): try: @@ -185,6 +190,8 @@ class MainWindow(QMainWindow): 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.name", vmdev_name) + # Update the settings widget value + self.w_measurement_settings.set_value("device_voltage_measurement", str(self.vmdev)) def vmdev_autoconnect(self): 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["name"] = measurement_name 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}") diff --git a/cpdctrl_gui/ui/widgets/measurement_settings.py b/cpdctrl_gui/ui/widgets/measurement_settings.py index ce26eaa..540b6da 100644 --- a/cpdctrl_gui/ui/widgets/measurement_settings.py +++ b/cpdctrl_gui/ui/widgets/measurement_settings.py @@ -6,6 +6,32 @@ from os import path 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): script_changed = pyqtSignal() def __init__(self, parent=None): @@ -93,12 +119,14 @@ class MeasurementSettings(QWidget): # self.label = QLabel("Measurement Settings") # self.layout.addWidget(self.label) self.setLayout(self.l_vbox) - self.l_form = QFormLayout() - + # devices + self.w_device_selection = DeviceSelection() + self.l_vbox.addWidget(self.w_device_selection) # - script self.w_led_script = ScriptSelection() self.l_vbox.addWidget(self.w_led_script) # key-value stuff in a form + self.l_form = QFormLayout() self.l_vbox.addLayout(self.l_form) self.ws_form = {} w_box_interval = QDoubleSpinBox(self) @@ -146,6 +174,8 @@ class MeasurementSettings(QWidget): self.ws_form[key].setChecked(value) else: raise ValueError(f"Unknown widget type: {type(self.ws_form[key])}") + elif key.startswith("device_"): + self.w_device_selection.set_value(key, value) else: raise ValueError(f"Unknown key: {key}") @@ -161,6 +191,4 @@ class MeasurementSettings(QWidget): elif key == "led_script": return self.w_led_script.get_script() else: - raise ValueError(f"Unknown key: {key}") - - + raise ValueError(f"Unknown key: {key}") \ No newline at end of file