diff options
Diffstat (limited to 'ui/windows/channels_window.py')
| -rw-r--r-- | ui/windows/channels_window.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/ui/windows/channels_window.py b/ui/windows/channels_window.py index 266432b..597b0b2 100644 --- a/ui/windows/channels_window.py +++ b/ui/windows/channels_window.py @@ -618,8 +618,8 @@ _KIND_HELP = { "Example:\n offset = vars.get('zero', 0)\n return x[0] - offset" ), "custom_script": ( - "Full Python. Must define: def compute(x, t): ...\n" - "Available globals: x, signal names, t, math, vars, state" + "Multi-line Python block. Assign computed value to result.\n" + "Available: x, signal names, t, math, vars, state" ), } @@ -758,9 +758,11 @@ class DerivedBlock(QFrame): from ui.code_templates import BUILTIN_TEMPLATES txt = BUILTIN_TEMPLATES.get(self.dc.kind, "") elif self.dc.kind == "expression": - txt = self.dc.expression + from ui.code_templates import SCRIPT_TEMPLATES + txt = self.dc.expression or SCRIPT_TEMPLATES.get("expression", "") else: - txt = self.dc.script + from ui.code_templates import SCRIPT_TEMPLATES + txt = self.dc.script or SCRIPT_TEMPLATES.get(self.dc.kind, "") self._code.setPlainText(txt) code_lay.addWidget(self._code) # "Edit as Custom Script" button — only visible for built-in kinds @@ -875,16 +877,19 @@ class DerivedBlock(QFrame): # expression kind: label-only, no code injection (single-line expr) def _on_kind(self, idx: int): - from ui.code_templates import BUILTIN_TEMPLATES + from ui.code_templates import BUILTIN_TEMPLATES, SCRIPT_TEMPLATES k = _ALL_KINDS[idx] self.dc.kind = k self._help.setText(_KIND_HELP.get(k, "")) if k in ("derivative", "second_derivative") and not self._src_combos: self._add_src() if k in _BUILTIN: - # Reset to bare template first; _update_vars_hint will prepend comment + # Reset to bare template; _update_vars_hint will prepend variable comment self._code.setPlainText(BUILTIN_TEMPLATES.get(k, "")) - self._update_vars_hint() # also injects variable comment into code + elif k in _SCRIPT: + # Show starter template for script kinds (always replace on kind switch) + self._code.setPlainText(SCRIPT_TEMPLATES.get(k, "")) + self._update_vars_hint() self._update_visibility() def _on_wrt_changed(self, idx: int): |
