summaryrefslogtreecommitdiff
path: root/core/profile.py
diff options
context:
space:
mode:
authorChristian Kolset <christian.kolset@gmail.com>2026-06-09 22:14:20 -0600
committerChristian Kolset <christian.kolset@gmail.com>2026-06-09 22:14:20 -0600
commit7aec470acd69e9c1810b40aa5eea9b96b9eb73ad (patch)
tree9146091077ec64ed1437621ebf2725edf987801f /core/profile.py
parentb138e72d6f81cf58f27c6c1e4ce65cfebbb58624 (diff)
Scripting: named signal vars, shared vars dict, control scripts, code templates
- Named variables in expressions: source channel IDs injected as Python identifiers alongside x[] (e.g. write `A0 * 2` instead of `x[0] * 2`) - Shared `vars` dict on SignalProcessor accessible from all expressions, functions, and control scripts; persisted in .labdaq profiles - Per-derived-channel `state` dict for persistent computation state in custom scripts - Control widgets gain optional on_action_script (Python snippet with value, vars, channels, math in scope); syntax-checked in editor dialog - Built-in derived kinds (derivative, rms, power, etc.) now show their Python implementation as read-only code previews; "Edit as Custom Script" converts to custom_script kind with template pre-filled Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'core/profile.py')
-rw-r--r--core/profile.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/profile.py b/core/profile.py
index 39cb3ca..16c923f 100644
--- a/core/profile.py
+++ b/core/profile.py
@@ -80,6 +80,8 @@ class Profile:
# plugin_state = {plugin_id: plugin.get_save_state()}
plugins_enabled: List[str] = field(default_factory=list)
# plugins_enabled = [plugin_id, ...] — which plugins were on when saved
+ script_vars: Dict[str, Any] = field(default_factory=dict)
+ # script_vars — shared vars dict accessible as `vars` in all expressions
def to_json(self) -> str:
return json.dumps(asdict(self), indent=2)
@@ -99,6 +101,7 @@ class Profile:
settings = d.get("settings", {}),
plugin_state = d.get("plugin_state", {}),
plugins_enabled = d.get("plugins_enabled", []),
+ script_vars = d.get("script_vars", {}),
)
def save(self, path: str):
@@ -213,6 +216,10 @@ class ProfileManager:
p.settings = dict(settings)
+ # Shared script variables
+ with processor._lock:
+ p.script_vars = dict(processor._script_vars)
+
# Plugin state + enabled list
if plugin_manager is not None:
p.plugins_enabled = plugin_manager.get_enabled_ids()
@@ -349,6 +356,11 @@ class ProfileManager:
specs = [ControlSpec.from_dict(d) for d in profile.controls]
control_panel.load_specs(specs)
+ # ── Script vars ──────────────────────────────────────────────────
+ if profile.script_vars:
+ with processor._lock:
+ processor._script_vars.update(profile.script_vars)
+
# ── Settings ─────────────────────────────────────────────────────
settings_ref.update(profile.settings)