From b2dc94bb2e7c7e57cba202697ed4d58bbb1f01f5 Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Tue, 28 Jul 2026 17:01:38 -0600 Subject: Update CML protocol documentation and improve command handling; adjust motion_capture setting to false --- plugins/enabled.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/enabled.json b/plugins/enabled.json index a33a40a..7d3abd6 100644 --- a/plugins/enabled.json +++ b/plugins/enabled.json @@ -1,3 +1,3 @@ { - "motion_capture": true + "motion_capture": false } \ No newline at end of file -- cgit v1.2.3 From d9ca58e48cf92438087ac24ee261c2c4911316b1 Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Wed, 29 Jul 2026 13:03:24 -0600 Subject: Add editable device display name, persist it across profile save/load DeviceInfo.name existed but was hardcoded per device type and never operator-editable. Adds a Display Name field to Add Device and makes the Info-tab Name field in the device config dialog editable, and threads the name through get_save_config()/ProfileManager.apply() so a custom name survives a .labdaq save/reload instead of reverting to the type default. Name is applied post-construction rather than as a constructor kwarg, since no device factory declares a "name" param. Co-Authored-By: Claude Sonnet 5 --- core/profile.py | 9 ++++++++- devices/analog_input.py | 1 + devices/arduino_device.py | 1 + devices/digital_io.py | 1 + devices/nidaqmx_device.py | 1 + devices/serial_device.py | 1 + plugins/motion_capture/device.py | 1 + ui/add_device_dialog.py | 8 ++++++++ ui/config_dialog.py | 9 ++++++++- ui/windows/devices_window.py | 2 +- 10 files changed, 31 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/core/profile.py b/core/profile.py index d3c7e3a..7ede859 100644 --- a/core/profile.py +++ b/core/profile.py @@ -302,8 +302,15 @@ class ProfileManager: print(f"[Profile] Unknown device type: {dev_type}") continue try: - kwargs = {k: v for k, v in dev_cfg.items() if k != "device_type"} + # "name" is a display label, not a constructor arg — every device + # factory builds its own default name internally, so apply it + # after construction instead of passing it through. + custom_name = dev_cfg.get("name") + kwargs = {k: v for k, v in dev_cfg.items() + if k not in ("device_type", "name")} dev = factory(**kwargs) + if custom_name: + dev.info.name = custom_name registry.add_instance(dev) dev.connect() if engine is not None: diff --git a/devices/analog_input.py b/devices/analog_input.py index c9e5d2a..1a7fefa 100644 --- a/devices/analog_input.py +++ b/devices/analog_input.py @@ -175,6 +175,7 @@ class AnalogInputDevice(BaseDevice): return { "device_type": self.DEVICE_TYPE, "device_id": self.info.device_id, + "name": self.info.name, "num_channels": self._num_channels, "simulate": self.simulate, "backend": self.backend, diff --git a/devices/arduino_device.py b/devices/arduino_device.py index 7c1d21b..e7fb537 100644 --- a/devices/arduino_device.py +++ b/devices/arduino_device.py @@ -203,6 +203,7 @@ class ArduinoDevice(BaseDevice): return { "device_type": self.DEVICE_TYPE, "device_id": self.info.device_id, + "name": self.info.name, "analog_pins": self._analog_pins, "di_pins": self._di_pins, "do_pins": self._do_pins, diff --git a/devices/digital_io.py b/devices/digital_io.py index 53395dc..954a8ac 100644 --- a/devices/digital_io.py +++ b/devices/digital_io.py @@ -258,6 +258,7 @@ class DigitalIODevice(BaseDevice): return { "device_type": self.DEVICE_TYPE, "device_id": self.info.device_id, + "name": self.info.name, "num_inputs": self._num_inputs, "num_outputs": self._num_outputs, "simulate": self.simulate, diff --git a/devices/nidaqmx_device.py b/devices/nidaqmx_device.py index 88bb932..ed19aeb 100644 --- a/devices/nidaqmx_device.py +++ b/devices/nidaqmx_device.py @@ -219,6 +219,7 @@ class NidaqmxDevice(BaseDevice): return { "device_type": self.DEVICE_TYPE, "device_id": self.info.device_id, + "name": self.info.name, "num_analog": self._num_analog, "min_v": self._min_v, "max_v": self._max_v, diff --git a/devices/serial_device.py b/devices/serial_device.py index 067656a..57faee8 100644 --- a/devices/serial_device.py +++ b/devices/serial_device.py @@ -168,6 +168,7 @@ class SerialDevice(BaseDevice): cfg: Dict[str, Any] = { "device_type": self.DEVICE_TYPE, "device_id": self.info.device_id, + "name": self.info.name, "port": self._port, "baud_rate": self._baud, "parse_format": self._fmt, diff --git a/plugins/motion_capture/device.py b/plugins/motion_capture/device.py index 58f89ce..3369962 100644 --- a/plugins/motion_capture/device.py +++ b/plugins/motion_capture/device.py @@ -102,6 +102,7 @@ class CameraDevice(BaseDevice): return { "device_type": self.DEVICE_TYPE, "device_id": self.info.device_id, + "name": self.info.name, "camera_index": self._camera_index, "simulate": self._simulate, "resolution": list(self._resolution) if self._resolution else None, diff --git a/ui/add_device_dialog.py b/ui/add_device_dialog.py index 2956a96..68ec3ad 100644 --- a/ui/add_device_dialog.py +++ b/ui/add_device_dialog.py @@ -299,6 +299,10 @@ class AddDeviceDialog(QDialog): self._id_edit.setPlaceholderText("Leave blank for auto") cfg_form.addRow("Device ID:", self._id_edit) + self._name_edit = QLineEdit() + self._name_edit.setPlaceholderText("Leave blank to use the default type name") + cfg_form.addRow("Display Name:", self._name_edit) + self._fmt_cb = QComboBox() self._fmt_cb.addItems(list(_FORMAT_LABELS.keys())) self._fmt_lbl = QLabel("Protocol / Format:") @@ -449,6 +453,10 @@ class AddDeviceDialog(QDialog): panel.set_simulate(sim) dev = panel.build_device(dev_id) + display_name = self._name_edit.text().strip() + if display_name: + dev.info.name = display_name + self.created_device = dev self.accept() except Exception as e: diff --git a/ui/config_dialog.py b/ui/config_dialog.py index d9bc9df..5a95821 100644 --- a/ui/config_dialog.py +++ b/ui/config_dialog.py @@ -59,7 +59,14 @@ class DeviceConfigDialog(QDialog): e = QLineEdit(str(v)); e.setReadOnly(True); return e form.addRow("Device ID:", _ro(info.device_id)) - form.addRow("Name:", _ro(info.name)) + + def _on_name_edited(): + info.name = name_edit.text().strip() or info.name + self.setWindowTitle(f"Configure — {info.name} [{info.device_id}]") + + name_edit = QLineEdit(info.name) + name_edit.editingFinished.connect(_on_name_edited) + form.addRow("Name:", name_edit) form.addRow("Type:", _ro(info.device_type)) form.addRow("Description:", _ro(info.description)) form.addRow("Manufacturer:", _ro(info.manufacturer)) diff --git a/ui/windows/devices_window.py b/ui/windows/devices_window.py index ac9d13c..2c484e8 100644 --- a/ui/windows/devices_window.py +++ b/ui/windows/devices_window.py @@ -349,7 +349,7 @@ class DevicesWindow(QWidget): dev = self.registry.get_instance(device_id) if dev: DeviceConfigDialog(dev, self).exec() - self._ch_tab.refresh() + self.refresh() # rebuilds device rows (picks up a renamed display name) + Signals tab self.device_reconfigured.emit(device_id) def _on_remove(self, device_id: str): -- cgit v1.2.3 From 45ff7227fabb97273d4645601733f90f5f744eb1 Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Wed, 29 Jul 2026 13:21:05 -0600 Subject: Check plugin dependencies before loading, warn instead of silent console error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit manifest.json already had an unused "requires" field (motion_capture's manifest lists opencv-python>=4.8.0) — PluginManifest never parsed it, so a missing dependency just crashed the import inside _load_plugin(), caught by the broad except and only ever printed to the console. Adds PluginManifest.requires, PluginManager.missing_requirements()/ get_missing_dependencies(), and an early check in _load_plugin() that skips the risky import entirely when a requirement is missing. main_window.plugin_enable() now checks this before calling PluginManager.enable() and shows a QMessageBox with the missing packages and a pip install command instead of failing silently. Checks by distribution name via importlib.metadata (what pip installed it as), not import name — those differ for packages like opencv-python (imports as cv2) or pyserial (imports as serial), so importlib.util. find_spec() would give false negatives. Also fixes a button-state bug this surfaces: SettingsWindow's plugin toggle optimistically flipped to "Disable" the instant Enable was clicked, before knowing whether enabling actually succeeds — pre-existing, but now trivially reproducible (any plugin missing a dependency). Enable no longer flips the button immediately; main_window calls the new sync_plugin_button() once the real outcome is known. Co-Authored-By: Claude Sonnet 5 --- plugins/plugin_manager.py | 40 +++++++++++++++++++++++++++++++++++++++- ui/main_window.py | 20 ++++++++++++++++---- ui/windows/settings_window.py | 12 +++++++++++- 3 files changed, 66 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/plugins/plugin_manager.py b/plugins/plugin_manager.py index 36ae71a..5cefc2e 100644 --- a/plugins/plugin_manager.py +++ b/plugins/plugin_manager.py @@ -10,12 +10,14 @@ per-plugin state separately via get_save_state / apply_save_state. from __future__ import annotations +import importlib.metadata import importlib.util import json import os +import re import sys import traceback -from dataclasses import dataclass +from dataclasses import dataclass, field from typing import Dict, List, Optional from plugins.base_plugin import LabPlugin, PluginContext @@ -35,9 +37,35 @@ class PluginManifest: description: str = "" author: str = "" entry_point: str = "plugin.Plugin" # "module.ClassName" relative to plugin dir + requires: List[str] = field(default_factory=list) # pip-style reqs, e.g. "opencv-python>=4.8.0" plugin_dir: str = "" +def _dist_name(requirement: str) -> str: + """Extract the distribution name from a requirement string, e.g. + "opencv-python>=4.8.0" -> "opencv-python".""" + return re.split(r"[<>=!~\[; ]", requirement.strip(), maxsplit=1)[0] + + +def missing_requirements(requires: List[str]) -> List[str]: + """Return the subset of `requires` whose distribution isn't installed. + + Checked by distribution name via importlib.metadata (matches what pip + installed it as), not by import name — those differ for packages like + opencv-python (imports as cv2) or pyserial (imports as serial). + """ + missing = [] + for req in requires: + name = _dist_name(req) + if not name: + continue + try: + importlib.metadata.version(name) + except importlib.metadata.PackageNotFoundError: + missing.append(req) + return missing + + # ── Manager ─────────────────────────────────────────────────────────────────── class PluginManager: @@ -94,6 +122,7 @@ class PluginManager: description = data.get("description", ""), author = data.get("author", ""), entry_point = data.get("entry_point", "plugin.Plugin"), + requires = data.get("requires", []), plugin_dir = plugin_dir, ) self._manifests[m.plugin_id] = m @@ -146,6 +175,11 @@ class PluginManager: print(f"[PluginManager] No manifest for '{plugin_id}'") return None + missing = missing_requirements(manifest.requires) + if missing: + print(f"[Plugin] '{plugin_id}' missing dependencies: {', '.join(missing)}") + return None + module_name, class_name = manifest.entry_point.rsplit(".", 1) module_file = os.path.join( manifest.plugin_dir, *module_name.split("/") @@ -218,6 +252,10 @@ class PluginManager: def get_manifests(self) -> List[PluginManifest]: return list(self._manifests.values()) + def get_missing_dependencies(self, plugin_id: str) -> List[str]: + manifest = self._manifests.get(plugin_id) + return missing_requirements(manifest.requires) if manifest else [] + def get_loaded(self) -> List[LabPlugin]: return list(self._loaded.values()) diff --git a/ui/main_window.py b/ui/main_window.py index d0e0ac4..95cdb84 100644 --- a/ui/main_window.py +++ b/ui/main_window.py @@ -296,10 +296,22 @@ class MainWindow(QMainWindow): def plugin_enable(self, plugin_id: str): """Called by SettingsWindow when user enables a plugin.""" - ctx = self._make_plugin_context() - plugin = self._plugin_mgr.enable(plugin_id, ctx) - if plugin: - self._install_plugin(plugin) + missing = self._plugin_mgr.get_missing_dependencies(plugin_id) + if missing: + from PyQt6.QtWidgets import QMessageBox + QMessageBox.warning( + self, "Missing Plugin Dependencies", + f"Can't enable this plugin — missing Python packages:\n\n" + f" {', '.join(missing)}\n\n" + f"Install with:\n pip install {' '.join(missing)}" + ) + else: + ctx = self._make_plugin_context() + plugin = self._plugin_mgr.enable(plugin_id, ctx) + if plugin: + self._install_plugin(plugin) + if self._win_settings: + self._win_settings.sync_plugin_button(plugin_id) def plugin_disable(self, plugin_id: str): """Called by SettingsWindow when user disables a plugin.""" diff --git a/ui/windows/settings_window.py b/ui/windows/settings_window.py index 1630efa..553a3a7 100644 --- a/ui/windows/settings_window.py +++ b/ui/windows/settings_window.py @@ -50,6 +50,7 @@ class SettingsWindow(QWidget): self.registry = registry self.engine = engine self._plugin_mgr = plugin_manager + self._plugin_buttons: dict = {} # plugin_id -> QPushButton self.cfg = dict(self._defaults) if current: self.cfg.update(current) @@ -233,6 +234,7 @@ class SettingsWindow(QWidget): toggle.clicked.connect( lambda _, pid=manifest.plugin_id, btn=toggle: self._toggle_plugin(pid, btn) ) + self._plugin_buttons[manifest.plugin_id] = toggle hdr.addWidget(toggle) cl.addLayout(hdr) @@ -261,8 +263,16 @@ class SettingsWindow(QWidget): self.plugin_disable_requested.emit(plugin_id) btn.setText("Enable") else: + # Don't flip to "Disable" yet — enabling can fail (missing + # dependencies, bad plugin code). main_window confirms the + # real outcome via sync_plugin_button() once enable() returns. self.plugin_enable_requested.emit(plugin_id) - btn.setText("Disable") + + def sync_plugin_button(self, plugin_id: str): + """Refresh one plugin's toggle button to match its actual enabled state.""" + btn = self._plugin_buttons.get(plugin_id) + if btn is not None and self._plugin_mgr is not None: + btn.setText("Disable" if self._plugin_mgr.is_enabled(plugin_id) else "Enable") # ── Actions ─────────────────────────────────────────────────────────── -- cgit v1.2.3