diff options
Diffstat (limited to 'ui/strip_chart.py')
| -rw-r--r-- | ui/strip_chart.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/ui/strip_chart.py b/ui/strip_chart.py index a212e5c..6c644be 100644 --- a/ui/strip_chart.py +++ b/ui/strip_chart.py @@ -79,6 +79,9 @@ class StripChartWidget(QWidget): self._cfg: Optional[LayoutConfig] = None # (dev_id, ch_id) → [{curve, plot, spec}] self._curves: Dict[Tuple, List[dict]] = {} + # (dev_id, ch_id) → last unit seen — lets refresh_pane_unit() tell an + # auto-seeded pane label apart from one the operator typed by hand + self._known_units: Dict[Tuple[str, str], str] = {} # Time-axis plots, scrolled continuously by _scroll_timer rather than # only when a new sample lands — decouples the visible scroll rate # from the (much slower) poll rate so it doesn't look stepped. @@ -179,6 +182,10 @@ class StripChartWidget(QWidget): key = (tr.device_id, tr.channel_id) self._curves.setdefault(key, []).append( {"curve": curve, "plot": plot, "spec": spec, "pane": spec}) + # Seed with the channel's true current unit (not spec.y_label, + # which may be pane title text or a custom label) so the first + # live unit-change after a layout rebuild is still detected. + self._known_units[key] = self._lookup_channel_unit(*key) def set_theme(self, theme: str): """Hot-swap pyqtgraph colours when the user changes theme.""" @@ -196,6 +203,34 @@ class StripChartWidget(QWidget): for e in self._curves.get(key, []): e["curve"].setVisible(enabled) + def _lookup_channel_unit(self, device_id: str, channel_id: str) -> str: + if device_id == "derived": + for dc in self.processor.get_derived(): + if dc.channel_id == channel_id: + return dc.unit + return "" + dev = self.registry.get_instance(device_id) + ch = dev.get_channel(channel_id) if dev else None + return ch.unit if ch else "" + + @pyqtSlot(str, str, str) + def refresh_pane_unit(self, device_id: str, channel_id: str, new_unit: str): + """A channel's unit changed live (e.g. a Mark-10 gauge switched + lb/kgF/N/ozF on its own front panel). Update any open pane's Y-axis + label that's still showing the *previous* unit verbatim — but never + touch a label the operator typed by hand.""" + key = (device_id, channel_id) + old_unit = self._known_units.get(key) + self._known_units[key] = new_unit + if old_unit == new_unit: + return + for entry in self._curves.get(key, []): + spec = entry["spec"] + if spec.y_label != old_unit: + continue + spec.y_label = new_unit + entry["plot"].setLabel("left", new_unit or spec.title) + @pyqtSlot(str, str, float, float) def on_new_data(self, device_id: str, channel_id: str, ts: float, val: float): if self._paused or not _HAS_PG or not self._cfg: return |
