diff options
| author | Christian Kolset <ckolset@colostate.edu> | 2026-08-10 16:12:05 -0600 |
|---|---|---|
| committer | Christian Kolset <ckolset@colostate.edu> | 2026-08-10 16:12:05 -0600 |
| commit | 5d5bcaed8639a162fda85c8cd0d340c296a054b8 (patch) | |
| tree | a7a1a62fb607c9c85127dab4aab17ccf8e22c906 /ui/control_panel.py | |
| parent | 46231c00994cd681d598961f2056dbda31c3e483 (diff) | |
Unify Signals/Channels around auto-naming, plot-by-channel, and shared vars
Devices: auto-name from OS-reported port description (Device Manager /
udev string) instead of a generic label; default Serial #Channels 1;
consistent simulate-mode checkbox across backends; inline device rename.
Channels: calibration/filters move out of Signals into a Channel
"Operation" (adds Scale/Offset alongside the existing math kinds);
single-physical-source Channels get an embedded Filters block; new
Channels auto-name/auto-ID from their source and reject duplicate
names/IDs on apply; "Create Channel" button on each Signal row; renamed
"Sources" -> "Signals" in the Channels UI; Signals' READ/WRITE dir badge
(was silently-broken IN/OUT) now reflects the real writable flag.
Plot: default layout is one pane per Channel (not per device, not raw
Signals) titled by channel name; "+ Add Channel" is a checkbox dialog
instead of an inline dropdown; traces get up/down reorder; live unit
changes (e.g. a Mark-10 gauge switching lb/kgF/N/ozF) propagate to an
open pane's axis label without clobbering a manually-typed one.
Control Panel: hardware assignment now picks from the same writable-
Signals list instead of a separate device/channel combo with a
hardcoded Arduino pin list; stale visual indicator when a control's
target device/channel disconnects or disappears; documented the `vars`
bridge (Control Panel On Action Script <-> Channel scripts) in both
directions' help text and script templates.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'ui/control_panel.py')
| -rw-r--r-- | ui/control_panel.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/ui/control_panel.py b/ui/control_panel.py index 3499a44..adf48e6 100644 --- a/ui/control_panel.py +++ b/ui/control_panel.py @@ -88,6 +88,8 @@ class ControlWidget(QFrame): self._compile_action(on_action_script) self.setObjectName("controlWidget") self._build_frame() + self._stale = None + self._check_stale() def _compile_action(self, script: str): try: @@ -96,6 +98,31 @@ class ControlWidget(QFrame): except SyntaxError as e: print(f"[Control '{self.title}'] script syntax error: {e}") + def _check_stale(self): + """Re-evaluate whether this control's target signal is currently + reachable — unbound controls (no device/channel assigned) are never + stale, only ones pointing at a signal that's since gone missing.""" + stale = False + if self.device_id and self.channel_id: + dev = self.registry.get_instance(self.device_id) if self.registry else None + if dev is None: + stale = True + else: + ch = dev.get_channel(self.channel_id) + if ch is None or not ch.enabled: + stale = True + elif dev.status not in (DeviceStatus.CONNECTED, DeviceStatus.SIMULATED): + stale = True + self._set_stale(stale) + + def _set_stale(self, stale: bool): + if self._stale == stale: + return + self._stale = stale + self._stale_lbl.setVisible(stale) + self.setProperty("stale", "true" if stale else "false") + self.style().unpolish(self); self.style().polish(self) + def _logic_level(self, enabled: bool) -> float: """Map logical ON/OFF to electrical level, respecting active-low outputs.""" if self.active_low: @@ -123,6 +150,11 @@ class ControlWidget(QFrame): title_lbl.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents) hdr_lay.addWidget(icon_lbl) hdr_lay.addWidget(title_lbl, 1) + self._stale_lbl = QLabel("⚠") + self._stale_lbl.setObjectName("controlWidgetStale") + self._stale_lbl.setToolTip("Target signal not connected") + self._stale_lbl.setVisible(False) + hdr_lay.addWidget(self._stale_lbl) self._header = hdr self._header_layout = hdr_lay outer.addWidget(hdr) @@ -635,13 +667,20 @@ class ControlPanel(QWidget): controls_changed = pyqtSignal() # emitted whenever widgets are added/edited/removed - def __init__(self, registry: DeviceRegistry, processor=None): + def __init__(self, registry: DeviceRegistry, processor=None, engine=None): super().__init__() self.registry = registry self.processor = processor + self.engine = engine self._widgets: list[ControlWidget] = [] self._specs: list = [] # parallel list of ControlSpec self._build() + if engine is not None: + engine.device_status_changed.connect(self._on_device_status_changed) + + def _on_device_status_changed(self, device_id: str, status: str): + for w in self._widgets: + w._check_stale() # ── Layout ─────────────────────────────────────────────────────────────── |
