diff options
| author | Christian Kolset <christian.kolset@gmail.com> | 2026-06-09 22:21:01 -0600 |
|---|---|---|
| committer | Christian Kolset <christian.kolset@gmail.com> | 2026-06-09 22:21:01 -0600 |
| commit | 4d62e4c03227500984a2770ef9615c603a5b71aa (patch) | |
| tree | 62dc7ab6f1a97057b41b35a64346ebfe1c9c1bc9 | |
| parent | 7aec470acd69e9c1810b40aa5eea9b96b9eb73ad (diff) | |
Channels: live variable-name hint in code editor updates with sources
When sources are added, removed, or changed in the derived channel editor,
the code group now shows a live "Variables: A0 = x[0] · encoder = x[1]"
hint above the code editor so users know the exact names to use in scripts.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| -rw-r--r-- | ui/windows/channels_window.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ui/windows/channels_window.py b/ui/windows/channels_window.py index ecc7cbc..3730b12 100644 --- a/ui/windows/channels_window.py +++ b/ui/windows/channels_window.py @@ -743,6 +743,10 @@ class DerivedBlock(QFrame): # Code editor (shown for all kinds — read-only for built-ins) self._code_grp = QGroupBox("Code") code_lay = QVBoxLayout(self._code_grp); code_lay.setContentsMargins(6, 4, 6, 4) + # Live variable-name hint — updated whenever sources change + self._vars_lbl = QLabel("") + self._vars_lbl.setObjectName("traceSource"); self._vars_lbl.setWordWrap(True) + code_lay.addWidget(self._vars_lbl) _mono = QFont("IBM Plex Mono, Consolas, Monospace"); _mono.setStyleHint(QFont.StyleHint.Monospace) self._code = QTextEdit(); self._code.setObjectName("codeEditor") self._code.setMinimumHeight(90); self._code.setMaximumHeight(180) @@ -776,6 +780,7 @@ class DerivedBlock(QFrame): body.setVisible(False) outer.addWidget(body) self._body = body + self._update_vars_hint() self._update_visibility() def _toggle(self): @@ -792,11 +797,13 @@ class DerivedBlock(QFrame): for i in range(cb.count()): if cb.itemData(i) == src: cb.setCurrentIndex(i); break + cb.currentIndexChanged.connect(lambda _: self._update_vars_hint()) rm = QToolButton(); rm.setText("✕"); rm.setObjectName("traceRemoveBtn") rm.setFixedSize(22, 22); rm.clicked.connect(lambda: self._rm_src(row, cb)) row.addWidget(cb, 1); row.addWidget(rm) self._src_vlay.addLayout(row) self._src_combos.append(cb) + self._update_vars_hint() def _rm_src(self, row, cb): if cb in self._src_combos: @@ -804,6 +811,20 @@ class DerivedBlock(QFrame): while row.count(): it = row.takeAt(0) if it.widget(): it.widget().deleteLater() + self._update_vars_hint() + + def _update_vars_hint(self): + """Refresh the variable-name hint above the code editor.""" + if not hasattr(self, "_vars_lbl"): + return + from core.signal_processor import _make_src_names + sources = [cb.currentData() for cb in self._src_combos if cb.currentData()] + if not sources: + self._vars_lbl.setText("No sources — add sources above to use named variables") + return + names = _make_src_names(sources) + parts = [f"{name} = x[{i}]" for i, name in enumerate(names)] + self._vars_lbl.setText("Variables: " + " · ".join(parts)) def _on_kind(self, idx: int): from ui.code_templates import BUILTIN_TEMPLATES @@ -815,6 +836,7 @@ class DerivedBlock(QFrame): if k in _BUILTIN: # Show the template as a read-only preview self._code.setPlainText(BUILTIN_TEMPLATES.get(k, "")) + self._update_vars_hint() self._update_visibility() def _on_wrt_changed(self, idx: int): |
