lightfall 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lightfall/__init__.py +8 -0
- lightfall/__main__.py +10 -0
- lightfall/_version.py +24 -0
- lightfall/acquire/__init__.py +74 -0
- lightfall/acquire/buffer.py +363 -0
- lightfall/acquire/device_wrapper.py +416 -0
- lightfall/acquire/engine/__init__.py +155 -0
- lightfall/acquire/engine/base.py +587 -0
- lightfall/acquire/engine/bluesky.py +358 -0
- lightfall/acquire/engine/mock.py +165 -0
- lightfall/acquire/engine/plugins/__init__.py +9 -0
- lightfall/acquire/engine/plugins/bluesky_plugin.py +56 -0
- lightfall/acquire/engine/plugins/mock_plugin.py +55 -0
- lightfall/acquire/engine/protocol.py +145 -0
- lightfall/acquire/engine/registry.py +152 -0
- lightfall/acquire/engine/state.py +32 -0
- lightfall/acquire/engine/waiting_hook.py +225 -0
- lightfall/acquire/nats_bridge.py +62 -0
- lightfall/acquire/plan_ui.py +78 -0
- lightfall/acquire/plans/__init__.py +38 -0
- lightfall/acquire/plans/adaptive.py +288 -0
- lightfall/acquire/plans/example_plans.py +995 -0
- lightfall/acquire/plans/lightfall_plans.py +587 -0
- lightfall/acquire/plans/registry.py +543 -0
- lightfall/acquire/plans/standard_plans.py +186 -0
- lightfall/acquire/plans/user_plans.py +470 -0
- lightfall/acquire/runengine.py +36 -0
- lightfall/acquire/signals.py +452 -0
- lightfall/acquire/triggers/__init__.py +16 -0
- lightfall/acquire/triggers/base.py +25 -0
- lightfall/acquire/triggers/filter.py +37 -0
- lightfall/acquire/triggers/manager.py +73 -0
- lightfall/acquire/triggers/manual.py +36 -0
- lightfall/acquire/triggers/run_end.py +74 -0
- lightfall/acquire/triggers/run_start.py +52 -0
- lightfall/auth/__init__.py +38 -0
- lightfall/auth/policy.py +518 -0
- lightfall/auth/providers/__init__.py +30 -0
- lightfall/auth/providers/base.py +124 -0
- lightfall/auth/providers/keycloak.py +1017 -0
- lightfall/auth/providers/local.py +319 -0
- lightfall/auth/providers/pam.py +250 -0
- lightfall/auth/service_key.py +173 -0
- lightfall/auth/service_key_auth.py +79 -0
- lightfall/auth/session.py +656 -0
- lightfall/claude/__init__.py +52 -0
- lightfall/claude/_internal/__init__.py +1 -0
- lightfall/claude/_internal/serialization.py +195 -0
- lightfall/claude/_internal/threading.py +61 -0
- lightfall/claude/_internal/worker.py +757 -0
- lightfall/claude/_session_assembly.py +124 -0
- lightfall/claude/agent.py +596 -0
- lightfall/claude/lightfall_core_tools.py +410 -0
- lightfall/claude/markdown.py +103 -0
- lightfall/claude/permission_manager.py +588 -0
- lightfall/claude/tools/__init__.py +45 -0
- lightfall/claude/tools/controller.py +143 -0
- lightfall/claude/tools/interaction.py +177 -0
- lightfall/claude/tools/introspection.py +127 -0
- lightfall/claude/tools/logs.py +155 -0
- lightfall/claude/tools/screenshot.py +87 -0
- lightfall/claude/widget.py +851 -0
- lightfall/claude/widgets/__init__.py +5 -0
- lightfall/claude/widgets/permission_request.py +282 -0
- lightfall/claude/widgets/question_request.py +227 -0
- lightfall/claude/widgets/task_card.py +223 -0
- lightfall/config/__init__.py +23 -0
- lightfall/config/layers.py +317 -0
- lightfall/config/manager.py +244 -0
- lightfall/config/schema.py +154 -0
- lightfall/core/__init__.py +23 -0
- lightfall/core/application.py +727 -0
- lightfall/core/services.py +235 -0
- lightfall/devices/__init__.py +53 -0
- lightfall/devices/backends/__init__.py +17 -0
- lightfall/devices/backends/bcs.py +448 -0
- lightfall/devices/backends/happi.py +986 -0
- lightfall/devices/backends/mock.py +646 -0
- lightfall/devices/base.py +338 -0
- lightfall/devices/catalog.py +1039 -0
- lightfall/devices/connection_manager.py +676 -0
- lightfall/devices/model.py +290 -0
- lightfall/devices/monitoring.py +442 -0
- lightfall/devices/sim/__init__.py +26 -0
- lightfall/devices/sim/areadetector.py +436 -0
- lightfall/devices/sim/generators.py +223 -0
- lightfall/devices/sim/plugins.py +116 -0
- lightfall/epics/__init__.py +28 -0
- lightfall/epics/ca/__init__.py +10 -0
- lightfall/epics/ca/context.py +100 -0
- lightfall/epics/ca/pv.py +303 -0
- lightfall/epics/widgets/__init__.py +49 -0
- lightfall/epics/widgets/areadetector/__init__.py +16 -0
- lightfall/epics/widgets/areadetector/areadetector.py +281 -0
- lightfall/epics/widgets/areadetector/controls.py +478 -0
- lightfall/epics/widgets/areadetector/image_view.py +447 -0
- lightfall/epics/widgets/auto.py +319 -0
- lightfall/epics/widgets/base.py +404 -0
- lightfall/epics/widgets/checkbox.py +239 -0
- lightfall/epics/widgets/combobox.py +202 -0
- lightfall/epics/widgets/label.py +176 -0
- lightfall/epics/widgets/lineedit.py +253 -0
- lightfall/epics/widgets/motor.py +694 -0
- lightfall/epics/widgets/ophyd_base.py +469 -0
- lightfall/epics/widgets/ophyd_combobox.py +86 -0
- lightfall/epics/widgets/ophyd_label.py +54 -0
- lightfall/epics/widgets/ophyd_lineedit.py +170 -0
- lightfall/epics/widgets/ophyd_spinbox.py +79 -0
- lightfall/epics/widgets/slider.py +272 -0
- lightfall/epics/widgets/status_indicator.py +98 -0
- lightfall/epics/widgets/style.py +188 -0
- lightfall/exporter/__init__.py +1 -0
- lightfall/exporter/cli.py +67 -0
- lightfall/exporter/converters/__init__.py +26 -0
- lightfall/exporter/converters/base.py +39 -0
- lightfall/exporter/converters/noop.py +39 -0
- lightfall/exporter/converters/nxsas.py +73 -0
- lightfall/exporter/service.py +200 -0
- lightfall/exporter/tiled_utils.py +92 -0
- lightfall/ipc/__init__.py +6 -0
- lightfall/ipc/service.py +701 -0
- lightfall/ipc/trust.py +144 -0
- lightfall/logbook/__init__.py +46 -0
- lightfall/logbook/action_dialog.py +207 -0
- lightfall/logbook/action_logger.py +432 -0
- lightfall/logbook/block_mapper.py +562 -0
- lightfall/logbook/client.py +799 -0
- lightfall/logbook/converter.py +273 -0
- lightfall/logbook/editors/__init__.py +19 -0
- lightfall/logbook/editors/highlighter.py +305 -0
- lightfall/logbook/editors/markdown_editor.py +319 -0
- lightfall/logbook/editors/richtext_editor.py +1397 -0
- lightfall/logbook/entry_widget.py +1065 -0
- lightfall/logbook/event_listener.py +221 -0
- lightfall/logbook/fragment_widgets.py +925 -0
- lightfall/logbook/position_mapper.py +320 -0
- lightfall/logbook/protection.py +402 -0
- lightfall/logbook/style.py +394 -0
- lightfall/logbook/url.py +29 -0
- lightfall/logbook/visual_protection.py +330 -0
- lightfall/logbook/widget.py +680 -0
- lightfall/main.py +1091 -0
- lightfall/pipelines/__init__.py +4 -0
- lightfall/pipelines/client.py +148 -0
- lightfall/plugins/__init__.py +119 -0
- lightfall/plugins/agent_plugin.py +106 -0
- lightfall/plugins/agents/__init__.py +10 -0
- lightfall/plugins/agents/_mcp_helpers.py +52 -0
- lightfall/plugins/agents/alignment.py +94 -0
- lightfall/plugins/agents/autonomous_experiment/__init__.py +12 -0
- lightfall/plugins/agents/autonomous_experiment/nats_tools.py +210 -0
- lightfall/plugins/agents/autonomous_experiment/plugin.py +60 -0
- lightfall/plugins/agents/autonomous_experiment/prompts.py +164 -0
- lightfall/plugins/agents/current_esaf.py +435 -0
- lightfall/plugins/agents/device_tools.py +1043 -0
- lightfall/plugins/agents/engine_tools.py +720 -0
- lightfall/plugins/agents/ipython_tools.py +444 -0
- lightfall/plugins/agents/panel_builder.py +637 -0
- lightfall/plugins/agents/panel_design/references/cross_panel_patterns.md +95 -0
- lightfall/plugins/agents/panel_design/references/panel_design.md +680 -0
- lightfall/plugins/agents/panel_design.py +94 -0
- lightfall/plugins/agents/plan_design/references/plan_design.md +398 -0
- lightfall/plugins/agents/plan_design.py +90 -0
- lightfall/plugins/agents/plan_tools.py +878 -0
- lightfall/plugins/agents/scan_planning.py +101 -0
- lightfall/plugins/builtin_manifest.py +348 -0
- lightfall/plugins/controller_plugin.py +162 -0
- lightfall/plugins/engine_plugin.py +124 -0
- lightfall/plugins/errors.py +104 -0
- lightfall/plugins/info.py +112 -0
- lightfall/plugins/loader.py +878 -0
- lightfall/plugins/manifest.py +150 -0
- lightfall/plugins/panel_plugin.py +119 -0
- lightfall/plugins/plan_plugin.py +163 -0
- lightfall/plugins/registry.py +309 -0
- lightfall/plugins/settings_plugin.py +226 -0
- lightfall/plugins/statusbar_plugin.py +289 -0
- lightfall/plugins/theme_plugin.py +165 -0
- lightfall/plugins/types.py +136 -0
- lightfall/plugins/user_plugins.py +764 -0
- lightfall/project/__init__.py +37 -0
- lightfall/project/model.py +375 -0
- lightfall/project/service.py +427 -0
- lightfall/project/welcome.py +106 -0
- lightfall/resources/__init__.py +126 -0
- lightfall/resources/images/__init__.py +1 -0
- lightfall/resources/images/icon.ico +0 -0
- lightfall/resources/images/icon.png +0 -0
- lightfall/resources/images/logo.png +0 -0
- lightfall/services/__init__.py +33 -0
- lightfall/services/_alshub_client.py +73 -0
- lightfall/services/access_stamper.py +240 -0
- lightfall/services/als_beam_status.py +347 -0
- lightfall/services/ca_tunnel.py +325 -0
- lightfall/services/threaded_tiled_writer.py +174 -0
- lightfall/services/tiled_auth.py +21 -0
- lightfall/services/tiled_service.py +971 -0
- lightfall/services/tiled_writer_patch.py +301 -0
- lightfall/settings/__init__.py +1 -0
- lightfall/settings/image_helpers.py +30 -0
- lightfall/settings/user_settings_client.py +232 -0
- lightfall/ui/__init__.py +28 -0
- lightfall/ui/annotations.py +208 -0
- lightfall/ui/common/__init__.py +7 -0
- lightfall/ui/dialogs/__init__.py +26 -0
- lightfall/ui/dialogs/about_dialog.py +131 -0
- lightfall/ui/dialogs/add_trigger_dialog.py +152 -0
- lightfall/ui/dialogs/base.py +44 -0
- lightfall/ui/dialogs/bug_report_dialog.py +353 -0
- lightfall/ui/dialogs/create_plan_dialog.py +189 -0
- lightfall/ui/dialogs/device_edit_dialog.py +183 -0
- lightfall/ui/dialogs/export_dialog.py +565 -0
- lightfall/ui/dialogs/go_to_position_dialog.py +192 -0
- lightfall/ui/dialogs/login_dialog.py +756 -0
- lightfall/ui/dialogs/oauth_browser_dialog.py +305 -0
- lightfall/ui/dialogs/run_pipeline_dialog.py +131 -0
- lightfall/ui/dialogs/sample_metadata_dialog.py +316 -0
- lightfall/ui/docking/__init__.py +22 -0
- lightfall/ui/docking/icon_sidebar.py +806 -0
- lightfall/ui/docking/manager.py +682 -0
- lightfall/ui/docking/state.py +113 -0
- lightfall/ui/docking/theme.py +399 -0
- lightfall/ui/docking/widget.py +214 -0
- lightfall/ui/events.py +75 -0
- lightfall/ui/mainwindow.py +1006 -0
- lightfall/ui/models/__init__.py +49 -0
- lightfall/ui/models/device_selection.py +389 -0
- lightfall/ui/models/device_tree.py +1095 -0
- lightfall/ui/models/thread_model.py +667 -0
- lightfall/ui/models/tiled_model.py +384 -0
- lightfall/ui/panels/__init__.py +28 -0
- lightfall/ui/panels/base.py +525 -0
- lightfall/ui/panels/bluesky_panel.py +619 -0
- lightfall/ui/panels/claude/__init__.py +9 -0
- lightfall/ui/panels/claude/agent_registry.py +168 -0
- lightfall/ui/panels/claude_panel.py +887 -0
- lightfall/ui/panels/device_panel.py +370 -0
- lightfall/ui/panels/documents_panel.py +166 -0
- lightfall/ui/panels/ipython_panel.py +580 -0
- lightfall/ui/panels/logbook_entries_panel.py +84 -0
- lightfall/ui/panels/logbook_panel.py +627 -0
- lightfall/ui/panels/logging_panel.py +587 -0
- lightfall/ui/panels/pipeline_jobs_panel.py +160 -0
- lightfall/ui/panels/pipeline_triggers_panel.py +170 -0
- lightfall/ui/panels/plugins/__init__.py +34 -0
- lightfall/ui/panels/plugins/bluesky_plugin.py +27 -0
- lightfall/ui/panels/plugins/claude_plugin.py +29 -0
- lightfall/ui/panels/plugins/device_plugin.py +27 -0
- lightfall/ui/panels/plugins/documents_plugin.py +26 -0
- lightfall/ui/panels/plugins/ipython_plugin.py +27 -0
- lightfall/ui/panels/plugins/logbook_entries_plugin.py +23 -0
- lightfall/ui/panels/plugins/logbook_plugin.py +27 -0
- lightfall/ui/panels/plugins/logging_plugin.py +27 -0
- lightfall/ui/panels/plugins/pipeline_jobs_plugin.py +23 -0
- lightfall/ui/panels/plugins/pipeline_triggers_plugin.py +25 -0
- lightfall/ui/panels/plugins/queue_plugin.py +29 -0
- lightfall/ui/panels/plugins/synoptic_plugin.py +38 -0
- lightfall/ui/panels/plugins/threads_plugin.py +27 -0
- lightfall/ui/panels/plugins/tiled_browser_plugin.py +27 -0
- lightfall/ui/panels/plugins/visualization_plugin.py +27 -0
- lightfall/ui/panels/queue.py +754 -0
- lightfall/ui/panels/registry.py +483 -0
- lightfall/ui/panels/synoptic/__init__.py +27 -0
- lightfall/ui/panels/synoptic/editors.py +481 -0
- lightfall/ui/panels/synoptic/items.py +556 -0
- lightfall/ui/panels/synoptic/models.py +336 -0
- lightfall/ui/panels/synoptic/panel.py +889 -0
- lightfall/ui/panels/synoptic/serialization.py +300 -0
- lightfall/ui/panels/synoptic/view.py +504 -0
- lightfall/ui/panels/threads_panel.py +621 -0
- lightfall/ui/panels/tiled_browser_panel.py +854 -0
- lightfall/ui/panels/visualization_panel.py +508 -0
- lightfall/ui/preferences/__init__.py +24 -0
- lightfall/ui/preferences/backend.py +148 -0
- lightfall/ui/preferences/builtin.py +220 -0
- lightfall/ui/preferences/claude_settings.py +762 -0
- lightfall/ui/preferences/device_settings.py +461 -0
- lightfall/ui/preferences/dialog.py +234 -0
- lightfall/ui/preferences/editor_settings.py +227 -0
- lightfall/ui/preferences/ipc_settings.py +226 -0
- lightfall/ui/preferences/logbook_settings.py +232 -0
- lightfall/ui/preferences/login_settings.py +183 -0
- lightfall/ui/preferences/manager.py +562 -0
- lightfall/ui/preferences/plugin_settings.py +392 -0
- lightfall/ui/preferences/proxy_settings.py +561 -0
- lightfall/ui/preferences/skill_settings.py +28 -0
- lightfall/ui/preferences/tiled_settings.py +469 -0
- lightfall/ui/preferences/tool_settings.py +393 -0
- lightfall/ui/preferences/user_portable_backend.py +131 -0
- lightfall/ui/preferences/user_profile_settings.py +316 -0
- lightfall/ui/preferences/visualization_settings.py +159 -0
- lightfall/ui/resources/__init__.py +1 -0
- lightfall/ui/resources/logo.png +0 -0
- lightfall/ui/statusbar/__init__.py +11 -0
- lightfall/ui/statusbar/manager.py +379 -0
- lightfall/ui/statusbar/plugins/__init__.py +28 -0
- lightfall/ui/statusbar/plugins/als_beam_status.py +218 -0
- lightfall/ui/statusbar/plugins/auth_status.py +116 -0
- lightfall/ui/statusbar/plugins/connection_status.py +100 -0
- lightfall/ui/statusbar/plugins/thread_status.py +556 -0
- lightfall/ui/statusbar/plugins/tiled_status.py +179 -0
- lightfall/ui/statusbar/plugins/user_status.py +84 -0
- lightfall/ui/theater/__init__.py +28 -0
- lightfall/ui/theater/manager.py +124 -0
- lightfall/ui/theater/overlay.py +279 -0
- lightfall/ui/theater/proxy.py +111 -0
- lightfall/ui/theme/__init__.py +18 -0
- lightfall/ui/theme/builtin.py +1015 -0
- lightfall/ui/theme/manager.py +875 -0
- lightfall/ui/theme/registry.py +195 -0
- lightfall/ui/toast.py +221 -0
- lightfall/ui/tutorial.py +1100 -0
- lightfall/ui/widgets/__init__.py +110 -0
- lightfall/ui/widgets/base_control.py +259 -0
- lightfall/ui/widgets/camera/__init__.py +36 -0
- lightfall/ui/widgets/camera/base.py +815 -0
- lightfall/ui/widgets/camera/dark_frames.py +213 -0
- lightfall/ui/widgets/camera/image_view.py +649 -0
- lightfall/ui/widgets/camera/panels/__init__.py +14 -0
- lightfall/ui/widgets/camera/panels/cooler.py +320 -0
- lightfall/ui/widgets/camera/panels/temperature.py +192 -0
- lightfall/ui/widgets/camera/plan_based.py +202 -0
- lightfall/ui/widgets/compact_motor.py +522 -0
- lightfall/ui/widgets/controller_matcher.py +278 -0
- lightfall/ui/widgets/controller_registry.py +144 -0
- lightfall/ui/widgets/device_control.py +411 -0
- lightfall/ui/widgets/device_selector.py +438 -0
- lightfall/ui/widgets/device_tree_tab.py +461 -0
- lightfall/ui/widgets/document_stream.py +1028 -0
- lightfall/ui/widgets/favorites_tab.py +191 -0
- lightfall/ui/widgets/motor_control.py +1120 -0
- lightfall/ui/widgets/observers/__init__.py +8 -0
- lightfall/ui/widgets/observers/camera.py +48 -0
- lightfall/ui/widgets/observers/image_view.py +130 -0
- lightfall/ui/widgets/plan_config.py +954 -0
- lightfall/ui/widgets/plan_edit_dialog.py +294 -0
- lightfall/ui/widgets/plan_selector.py +452 -0
- lightfall/ui/widgets/profile_avatar.py +128 -0
- lightfall/ui/widgets/queue_view.py +647 -0
- lightfall/ui/widgets/runengine_control.py +549 -0
- lightfall/ui/widgets/signal_control.py +793 -0
- lightfall/ui/widgets/skill_trigger_button.py +183 -0
- lightfall/ui/widgets/tiled_filter_widget.py +314 -0
- lightfall/ui/widgets/tiled_status.py +149 -0
- lightfall/ui/widgets/warning_banner.py +185 -0
- lightfall/utils/__init__.py +53 -0
- lightfall/utils/crash_diagnostics.py +454 -0
- lightfall/utils/data_migration.py +22 -0
- lightfall/utils/editor_launcher.py +594 -0
- lightfall/utils/error_collector.py +245 -0
- lightfall/utils/git_tracker.py +197 -0
- lightfall/utils/log_buffer.py +233 -0
- lightfall/utils/logging.py +229 -0
- lightfall/utils/module_resolver.py +70 -0
- lightfall/utils/sentry.py +722 -0
- lightfall/utils/threads.py +991 -0
- lightfall/utils/tiled_helpers.py +96 -0
- lightfall/visualization/__init__.py +50 -0
- lightfall/visualization/base.py +5 -0
- lightfall/visualization/base_visualization.py +74 -0
- lightfall/visualization/fitting/__init__.py +24 -0
- lightfall/visualization/fitting/base.py +267 -0
- lightfall/visualization/fitting/fitters.py +325 -0
- lightfall/visualization/fitting/panel.py +265 -0
- lightfall/visualization/memory.py +392 -0
- lightfall/visualization/motor_mixin.py +524 -0
- lightfall/visualization/pg.py +156 -0
- lightfall/visualization/registry.py +144 -0
- lightfall/visualization/spec.py +79 -0
- lightfall/visualization/theme.py +266 -0
- lightfall/visualization/widgets/__init__.py +28 -0
- lightfall/visualization/widgets/adaptive/__init__.py +1 -0
- lightfall/visualization/widgets/adaptive/heatmap.py +655 -0
- lightfall/visualization/widgets/adaptive/plot.py +233 -0
- lightfall/visualization/widgets/heatmap.py +264 -0
- lightfall/visualization/widgets/image_stack.py +316 -0
- lightfall/visualization/widgets/image_view_toolbar.py +227 -0
- lightfall/visualization/widgets/lazy_image_view.py +590 -0
- lightfall/visualization/widgets/plot_1d.py +262 -0
- lightfall/visualization/widgets/scatter.py +247 -0
- lightfall/visualization/widgets/table.py +221 -0
- lightfall/visualization/widgets/time_axis.py +93 -0
- lightfall-0.1.1.dist-info/METADATA +223 -0
- lightfall-0.1.1.dist-info/RECORD +388 -0
- lightfall-0.1.1.dist-info/WHEEL +4 -0
- lightfall-0.1.1.dist-info/entry_points.txt +6 -0
- lightfall-0.1.1.dist-info/licenses/LEGAL.md +13 -0
- lightfall-0.1.1.dist-info/licenses/LICENSE.md +33 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Engine protocol definition.
|
|
2
|
+
|
|
3
|
+
Defines the interface that all execution engines must satisfy.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Callable
|
|
9
|
+
from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from lightfall.acquire.engine.state import EngineState
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@runtime_checkable
|
|
16
|
+
class Engine(Protocol):
|
|
17
|
+
"""Protocol for execution engines.
|
|
18
|
+
|
|
19
|
+
An Engine takes procedures from a queue and executes them, emitting
|
|
20
|
+
(name, dict) output pairs and Qt signals for state changes.
|
|
21
|
+
|
|
22
|
+
This protocol uses Qt signals for UI integration. Implementations
|
|
23
|
+
must be QObject subclasses or provide compatible signal attributes.
|
|
24
|
+
|
|
25
|
+
Required Qt Signals (documented here, cannot be enforced by Protocol):
|
|
26
|
+
sigOutput(str, dict): Emitted for each (name, document) output pair.
|
|
27
|
+
sigStart(): Emitted when a procedure starts executing.
|
|
28
|
+
sigFinish(): Emitted when a procedure finishes successfully.
|
|
29
|
+
sigPause(): Emitted when execution is paused.
|
|
30
|
+
sigResume(): Emitted when execution resumes.
|
|
31
|
+
sigAbort(): Emitted when execution is aborted.
|
|
32
|
+
sigException(Exception): Emitted when an error occurs.
|
|
33
|
+
sigReady(): Emitted when queue is empty and engine is idle.
|
|
34
|
+
sigStateChanged(str): Emitted on any state change.
|
|
35
|
+
|
|
36
|
+
Example:
|
|
37
|
+
def handle_output(name: str, doc: dict) -> None:
|
|
38
|
+
print(f"Received {name}: {doc}")
|
|
39
|
+
|
|
40
|
+
engine = get_engine()
|
|
41
|
+
engine.sigOutput.connect(handle_output)
|
|
42
|
+
engine.submit(my_procedure)
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
# === Properties ===
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def state(self) -> EngineState:
|
|
49
|
+
"""Current engine state."""
|
|
50
|
+
...
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def state_name(self) -> str:
|
|
54
|
+
"""Current state as lowercase string (for Qt signal compatibility)."""
|
|
55
|
+
...
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def is_idle(self) -> bool:
|
|
59
|
+
"""Whether engine is idle and ready for new procedures."""
|
|
60
|
+
...
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def queue_size(self) -> int:
|
|
64
|
+
"""Number of procedures waiting in the queue."""
|
|
65
|
+
...
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def name(self) -> str:
|
|
69
|
+
"""Human-readable engine name/identifier."""
|
|
70
|
+
...
|
|
71
|
+
|
|
72
|
+
# === Core Operations ===
|
|
73
|
+
|
|
74
|
+
def submit(self, procedure: Any, *, priority: int = 1, **kwargs: Any) -> None:
|
|
75
|
+
"""Submit a procedure for execution.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
procedure: The procedure to execute (type is implementation-specific).
|
|
79
|
+
priority: Queue priority (lower = higher priority). Default is 1.
|
|
80
|
+
**kwargs: Additional procedure parameters.
|
|
81
|
+
"""
|
|
82
|
+
...
|
|
83
|
+
|
|
84
|
+
def __call__(self, *args: Any, **kwargs: Any) -> None:
|
|
85
|
+
"""Convenience method for submit(). Alias for submit()."""
|
|
86
|
+
...
|
|
87
|
+
|
|
88
|
+
# === Control Operations ===
|
|
89
|
+
|
|
90
|
+
def pause(self, defer: bool = False) -> None:
|
|
91
|
+
"""Pause execution.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
defer: If True, pause at next safe point. If False, pause immediately.
|
|
95
|
+
"""
|
|
96
|
+
...
|
|
97
|
+
|
|
98
|
+
def resume(self) -> None:
|
|
99
|
+
"""Resume paused execution."""
|
|
100
|
+
...
|
|
101
|
+
|
|
102
|
+
def stop(self) -> None:
|
|
103
|
+
"""Request graceful stop at next safe point."""
|
|
104
|
+
...
|
|
105
|
+
|
|
106
|
+
def abort(self, reason: str = "") -> None:
|
|
107
|
+
"""Abort execution immediately.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
reason: Optional reason for the abort.
|
|
111
|
+
"""
|
|
112
|
+
...
|
|
113
|
+
|
|
114
|
+
def halt(self) -> None:
|
|
115
|
+
"""Emergency halt - immediately terminate execution."""
|
|
116
|
+
...
|
|
117
|
+
|
|
118
|
+
def clear_queue(self) -> int:
|
|
119
|
+
"""Clear all pending procedures from the queue.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
Number of procedures removed.
|
|
123
|
+
"""
|
|
124
|
+
...
|
|
125
|
+
|
|
126
|
+
# === Output Subscription ===
|
|
127
|
+
|
|
128
|
+
def subscribe(self, callback: Callable[[str, dict[str, Any]], Any]) -> int:
|
|
129
|
+
"""Subscribe to output stream.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
callback: Function called with (name, document) for each output.
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
Subscription token for unsubscribing.
|
|
136
|
+
"""
|
|
137
|
+
...
|
|
138
|
+
|
|
139
|
+
def unsubscribe(self, token: int) -> None:
|
|
140
|
+
"""Remove an output subscription.
|
|
141
|
+
|
|
142
|
+
Args:
|
|
143
|
+
token: Token returned by subscribe().
|
|
144
|
+
"""
|
|
145
|
+
...
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""Registry for engine plugins.
|
|
2
|
+
|
|
3
|
+
Provides a central registry for available engine plugins, enabling
|
|
4
|
+
engine discovery and selection based on user preferences.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import threading
|
|
10
|
+
from typing import TYPE_CHECKING, Any
|
|
11
|
+
|
|
12
|
+
from lightfall.utils.logging import logger
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from lightfall.plugins.engine_plugin import EnginePlugin
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class EngineRegistry:
|
|
19
|
+
"""Registry for available engine plugins.
|
|
20
|
+
|
|
21
|
+
Manages engine plugin discovery and provides engine selection
|
|
22
|
+
based on user preferences. This is a singleton that tracks all
|
|
23
|
+
registered engine plugins.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
>>> registry = EngineRegistry.get_instance()
|
|
27
|
+
>>> registry.register(BlueskyEnginePlugin())
|
|
28
|
+
>>> engine_plugin = registry.get("bluesky")
|
|
29
|
+
>>> engine = engine_plugin.create_engine()
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
_instance: EngineRegistry | None = None
|
|
33
|
+
_lock = threading.RLock()
|
|
34
|
+
|
|
35
|
+
def __init__(self) -> None:
|
|
36
|
+
"""Initialize the engine registry."""
|
|
37
|
+
self._engines: dict[str, EnginePlugin] = {}
|
|
38
|
+
self._default_engine: str = "bluesky"
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
def get_instance(cls) -> EngineRegistry:
|
|
42
|
+
"""Get the singleton instance.
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
The global EngineRegistry instance.
|
|
46
|
+
"""
|
|
47
|
+
if cls._instance is None:
|
|
48
|
+
with cls._lock:
|
|
49
|
+
if cls._instance is None:
|
|
50
|
+
cls._instance = cls()
|
|
51
|
+
return cls._instance
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def reset(cls) -> None:
|
|
55
|
+
"""Reset the singleton instance (for testing)."""
|
|
56
|
+
with cls._lock:
|
|
57
|
+
cls._instance = None
|
|
58
|
+
|
|
59
|
+
def register(self, plugin: EnginePlugin) -> None:
|
|
60
|
+
"""Register an engine plugin.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
plugin: The engine plugin to register.
|
|
64
|
+
"""
|
|
65
|
+
if plugin.name in self._engines:
|
|
66
|
+
logger.warning(f"Engine '{plugin.name}' already registered, replacing")
|
|
67
|
+
self._engines[plugin.name] = plugin
|
|
68
|
+
logger.debug(f"Registered engine plugin: {plugin.name}")
|
|
69
|
+
|
|
70
|
+
def unregister(self, name: str) -> bool:
|
|
71
|
+
"""Unregister an engine plugin.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
name: Name of the engine to unregister.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
True if the engine was removed, False if not found.
|
|
78
|
+
"""
|
|
79
|
+
if name in self._engines:
|
|
80
|
+
del self._engines[name]
|
|
81
|
+
logger.debug(f"Unregistered engine plugin: {name}")
|
|
82
|
+
return True
|
|
83
|
+
return False
|
|
84
|
+
|
|
85
|
+
def get(self, name: str) -> EnginePlugin | None:
|
|
86
|
+
"""Get an engine plugin by name.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
name: The engine identifier.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
The engine plugin or None if not found.
|
|
93
|
+
"""
|
|
94
|
+
return self._engines.get(name)
|
|
95
|
+
|
|
96
|
+
def get_all(self) -> list[EnginePlugin]:
|
|
97
|
+
"""Get all registered engine plugins.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
List of all registered engine plugins.
|
|
101
|
+
"""
|
|
102
|
+
return list(self._engines.values())
|
|
103
|
+
|
|
104
|
+
def get_names(self) -> list[str]:
|
|
105
|
+
"""Get all registered engine names.
|
|
106
|
+
|
|
107
|
+
Returns:
|
|
108
|
+
List of engine names.
|
|
109
|
+
"""
|
|
110
|
+
return list(self._engines.keys())
|
|
111
|
+
|
|
112
|
+
def has(self, name: str) -> bool:
|
|
113
|
+
"""Check if an engine is registered.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
name: The engine identifier.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
True if the engine is registered.
|
|
120
|
+
"""
|
|
121
|
+
return name in self._engines
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def default_engine(self) -> str:
|
|
125
|
+
"""Default engine name.
|
|
126
|
+
|
|
127
|
+
This is used when no preference is set.
|
|
128
|
+
"""
|
|
129
|
+
return self._default_engine
|
|
130
|
+
|
|
131
|
+
@default_engine.setter
|
|
132
|
+
def default_engine(self, name: str) -> None:
|
|
133
|
+
"""Set the default engine name.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
name: The engine identifier to use as default.
|
|
137
|
+
"""
|
|
138
|
+
self._default_engine = name
|
|
139
|
+
|
|
140
|
+
def get_introspection_data(self) -> dict[str, Any]:
|
|
141
|
+
"""Get introspection data for MCP tools.
|
|
142
|
+
|
|
143
|
+
Returns:
|
|
144
|
+
Dictionary with registry information.
|
|
145
|
+
"""
|
|
146
|
+
return {
|
|
147
|
+
"default_engine": self._default_engine,
|
|
148
|
+
"engines": {
|
|
149
|
+
name: plugin.get_introspection_data()
|
|
150
|
+
for name, plugin in self._engines.items()
|
|
151
|
+
},
|
|
152
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Engine state enumeration.
|
|
2
|
+
|
|
3
|
+
Defines the possible states for an execution engine.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from enum import Enum, auto
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class EngineState(Enum):
|
|
12
|
+
"""State of an execution engine.
|
|
13
|
+
|
|
14
|
+
Attributes:
|
|
15
|
+
IDLE: Engine is ready to accept procedures.
|
|
16
|
+
RUNNING: Engine is executing a procedure.
|
|
17
|
+
PAUSED: Execution is paused and can be resumed.
|
|
18
|
+
STOPPING: Graceful stop has been requested.
|
|
19
|
+
ABORTING: Immediate abort has been requested.
|
|
20
|
+
ERROR: Engine is in an error state.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
IDLE = auto()
|
|
24
|
+
RUNNING = auto()
|
|
25
|
+
PAUSED = auto()
|
|
26
|
+
STOPPING = auto()
|
|
27
|
+
ABORTING = auto()
|
|
28
|
+
ERROR = auto()
|
|
29
|
+
|
|
30
|
+
def __str__(self) -> str:
|
|
31
|
+
"""Return lowercase state name for display."""
|
|
32
|
+
return self.name.lower()
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
"""WaitingHookBridge — translates Bluesky waiting_hook callbacks to Qt signals.
|
|
2
|
+
|
|
3
|
+
Bluesky's RunEngine calls ``waiting_hook(status_objs)`` with a set of
|
|
4
|
+
StatusBase objects when it enters a wait, and ``waiting_hook(None)`` when all
|
|
5
|
+
waits resolve. This bridge converts those calls into throttled Qt signals
|
|
6
|
+
suitable for driving progress UI on the main thread.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import threading
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from PySide6.QtCore import QMetaObject, QObject, Qt, QTimer, Signal
|
|
15
|
+
|
|
16
|
+
from lightfall.utils.logging import logger
|
|
17
|
+
|
|
18
|
+
__all__ = ["WaitingHookBridge"]
|
|
19
|
+
|
|
20
|
+
# Flush interval in milliseconds (~10 Hz)
|
|
21
|
+
_FLUSH_INTERVAL_MS = 100
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class WaitingHookBridge(QObject):
|
|
25
|
+
"""Callable bridge between Bluesky waiting_hook and Qt signals.
|
|
26
|
+
|
|
27
|
+
Assigned to ``RE.waiting_hook``, this object is called from the
|
|
28
|
+
RunEngine thread. It buffers progress updates and flushes them to
|
|
29
|
+
Qt signals on the main thread via a QTimer.
|
|
30
|
+
|
|
31
|
+
All mutable state shared between threads is protected by ``_lock``.
|
|
32
|
+
The ``_done_buffer`` and ``_group_cleared`` flag allow the flush timer
|
|
33
|
+
(running on the main/Qt thread) to emit ``sigDeviceFinished`` and
|
|
34
|
+
``sigWaitGroupCleared`` safely, rather than emitting from the RE or
|
|
35
|
+
device threads directly.
|
|
36
|
+
|
|
37
|
+
Signals:
|
|
38
|
+
sigDeviceProgress(str, float, float, float, float):
|
|
39
|
+
``(device_name, current, initial, target, fraction)``
|
|
40
|
+
Emitted (on timer tick) when a status object's ``.watch()``
|
|
41
|
+
reports progress. ``fraction`` is fraction *complete* in
|
|
42
|
+
``[0.0, 1.0]`` (0.0 at move start, 1.0 at move end);
|
|
43
|
+
``fraction == -1`` signals indeterminate progress.
|
|
44
|
+
|
|
45
|
+
Note: ophyd's ``MoveStatus`` reports fraction *remaining*
|
|
46
|
+
(1.0 → 0.0); the bridge inverts it so consumers see the
|
|
47
|
+
conventional fraction-complete semantics.
|
|
48
|
+
sigDeviceFinished(str):
|
|
49
|
+
``(device_name,)`` — emitted when an individual status completes.
|
|
50
|
+
sigWaitGroupCleared:
|
|
51
|
+
Emitted when called with ``None`` (all waits resolved).
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
sigDeviceProgress = Signal(str, float, float, float, float)
|
|
55
|
+
sigDeviceFinished = Signal(str)
|
|
56
|
+
sigWaitGroupCleared = Signal()
|
|
57
|
+
|
|
58
|
+
def __init__(self, parent: QObject | None = None) -> None:
|
|
59
|
+
super().__init__(parent)
|
|
60
|
+
|
|
61
|
+
# Lock protects _buffer, _done_buffer, _group_cleared, _active_statuses
|
|
62
|
+
self._lock = threading.Lock()
|
|
63
|
+
|
|
64
|
+
# Buffer: device_name -> (current, initial, target, fraction)
|
|
65
|
+
self._buffer: dict[str, tuple[float, float, float, float]] = {}
|
|
66
|
+
|
|
67
|
+
# Buffer for finished device names (drained on main thread by _flush)
|
|
68
|
+
self._done_buffer: list[str] = []
|
|
69
|
+
|
|
70
|
+
# Flag: set True when _on_all_resolved is called, cleared by _flush
|
|
71
|
+
self._group_cleared: bool = False
|
|
72
|
+
|
|
73
|
+
# Active status objects we're tracking (prevent GC issues)
|
|
74
|
+
self._active_statuses: set[Any] = set()
|
|
75
|
+
|
|
76
|
+
# Flush timer — runs on the thread that owns this QObject (main thread)
|
|
77
|
+
self._timer = QTimer(self)
|
|
78
|
+
self._timer.setInterval(_FLUSH_INTERVAL_MS)
|
|
79
|
+
self._timer.timeout.connect(self._flush)
|
|
80
|
+
|
|
81
|
+
# ------------------------------------------------------------------
|
|
82
|
+
# Public callable interface (called from RE thread)
|
|
83
|
+
# ------------------------------------------------------------------
|
|
84
|
+
|
|
85
|
+
def __call__(self, status_objs: set[Any] | None) -> None:
|
|
86
|
+
"""Bluesky waiting_hook entry point.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
status_objs: A set of ophyd StatusBase objects, or ``None``
|
|
90
|
+
when all pending waits have resolved.
|
|
91
|
+
"""
|
|
92
|
+
if status_objs is None:
|
|
93
|
+
self._on_all_resolved()
|
|
94
|
+
return
|
|
95
|
+
|
|
96
|
+
new_statuses: list[Any] = []
|
|
97
|
+
with self._lock:
|
|
98
|
+
for st in status_objs:
|
|
99
|
+
# Skip if we're already tracking this status
|
|
100
|
+
if st in self._active_statuses:
|
|
101
|
+
continue
|
|
102
|
+
self._active_statuses.add(st)
|
|
103
|
+
new_statuses.append(st)
|
|
104
|
+
|
|
105
|
+
# Subscribe outside the lock — watch()/add_callback() may call back
|
|
106
|
+
# into our buffer methods which also acquire _lock.
|
|
107
|
+
for st in new_statuses:
|
|
108
|
+
self._subscribe_status(st)
|
|
109
|
+
|
|
110
|
+
# Ensure the flush timer is running (must be started from main thread)
|
|
111
|
+
QMetaObject.invokeMethod(
|
|
112
|
+
self._timer, "start", Qt.ConnectionType.QueuedConnection
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
# ------------------------------------------------------------------
|
|
116
|
+
# Internal helpers
|
|
117
|
+
# ------------------------------------------------------------------
|
|
118
|
+
|
|
119
|
+
def _subscribe_status(self, st: Any) -> None:
|
|
120
|
+
"""Subscribe to watch and completion callbacks on a single status."""
|
|
121
|
+
name = self._status_name(st)
|
|
122
|
+
|
|
123
|
+
if hasattr(st, "watch"):
|
|
124
|
+
try:
|
|
125
|
+
st.watch(self._make_watch_callback(name))
|
|
126
|
+
except Exception:
|
|
127
|
+
logger.warning(
|
|
128
|
+
f"[waiting_hook] watch() failed for {name}, treating as indeterminate"
|
|
129
|
+
)
|
|
130
|
+
self._buffer_update(name, 0.0, 0.0, 0.0, -1.0)
|
|
131
|
+
else:
|
|
132
|
+
# Non-watchable: indeterminate progress
|
|
133
|
+
self._buffer_update(name, 0.0, 0.0, 0.0, -1.0)
|
|
134
|
+
|
|
135
|
+
# Completion callback
|
|
136
|
+
st.add_callback(self._make_done_callback(name, st))
|
|
137
|
+
|
|
138
|
+
def _make_watch_callback(self, name: str):
|
|
139
|
+
"""Return a closure suitable for ``st.watch(callback)``."""
|
|
140
|
+
|
|
141
|
+
def _on_watch(**kwargs: Any) -> None:
|
|
142
|
+
current = float(kwargs.get("current", 0))
|
|
143
|
+
initial = float(kwargs.get("initial", 0))
|
|
144
|
+
target = float(kwargs.get("target", 0))
|
|
145
|
+
raw = kwargs.get("fraction", -1)
|
|
146
|
+
if raw is None:
|
|
147
|
+
# ophyd MoveStatus sends None for zero-distance / NaN moves.
|
|
148
|
+
fraction = -1.0
|
|
149
|
+
else:
|
|
150
|
+
raw_f = float(raw)
|
|
151
|
+
# ophyd emits fraction *remaining* (1.0 → 0.0); invert to
|
|
152
|
+
# fraction *complete* per the sigDeviceProgress contract.
|
|
153
|
+
# Preserve the -1 indeterminate sentinel as-is.
|
|
154
|
+
fraction = 1.0 - raw_f if 0.0 <= raw_f <= 1.0 else raw_f
|
|
155
|
+
self._buffer_update(name, current, initial, target, fraction)
|
|
156
|
+
|
|
157
|
+
return _on_watch
|
|
158
|
+
|
|
159
|
+
def _make_done_callback(self, name: str, st: Any):
|
|
160
|
+
"""Return a closure for ``st.add_callback(cb)``."""
|
|
161
|
+
|
|
162
|
+
def _on_done(status: Any = None) -> None:
|
|
163
|
+
with self._lock:
|
|
164
|
+
self._active_statuses.discard(st)
|
|
165
|
+
self._done_buffer.append(name)
|
|
166
|
+
logger.debug(f"[waiting_hook] {name} finished")
|
|
167
|
+
# Ensure the timer is running so the done event gets flushed
|
|
168
|
+
QMetaObject.invokeMethod(
|
|
169
|
+
self._timer, "start", Qt.ConnectionType.QueuedConnection
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
return _on_done
|
|
173
|
+
|
|
174
|
+
def _buffer_update(
|
|
175
|
+
self, name: str, current: float, initial: float, target: float, fraction: float
|
|
176
|
+
) -> None:
|
|
177
|
+
"""Thread-safe buffer write (called from RE/device thread)."""
|
|
178
|
+
with self._lock:
|
|
179
|
+
self._buffer[name] = (current, initial, target, fraction)
|
|
180
|
+
|
|
181
|
+
def _flush(self) -> None:
|
|
182
|
+
"""Timer slot — emit buffered signals on the main thread."""
|
|
183
|
+
with self._lock:
|
|
184
|
+
progress_snapshot = dict(self._buffer)
|
|
185
|
+
self._buffer.clear()
|
|
186
|
+
done_snapshot = list(self._done_buffer)
|
|
187
|
+
self._done_buffer.clear()
|
|
188
|
+
group_cleared = self._group_cleared
|
|
189
|
+
self._group_cleared = False
|
|
190
|
+
|
|
191
|
+
for name, (current, initial, target, fraction) in progress_snapshot.items():
|
|
192
|
+
self.sigDeviceProgress.emit(name, current, initial, target, fraction)
|
|
193
|
+
|
|
194
|
+
for name in done_snapshot:
|
|
195
|
+
self.sigDeviceFinished.emit(name)
|
|
196
|
+
|
|
197
|
+
if group_cleared:
|
|
198
|
+
self.sigWaitGroupCleared.emit()
|
|
199
|
+
self._timer.stop()
|
|
200
|
+
|
|
201
|
+
def _on_all_resolved(self) -> None:
|
|
202
|
+
"""Handle ``waiting_hook(None)`` — all waits cleared.
|
|
203
|
+
|
|
204
|
+
Called from the RE thread. Buffers the cleared flag so that
|
|
205
|
+
``_flush`` (main thread) emits ``sigWaitGroupCleared``.
|
|
206
|
+
"""
|
|
207
|
+
with self._lock:
|
|
208
|
+
self._group_cleared = True
|
|
209
|
+
self._active_statuses.clear()
|
|
210
|
+
logger.debug("[waiting_hook] all waits resolved")
|
|
211
|
+
# Ensure the timer is running so _flush can emit the cleared signal
|
|
212
|
+
QMetaObject.invokeMethod(
|
|
213
|
+
self._timer, "start", Qt.ConnectionType.QueuedConnection
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
@staticmethod
|
|
217
|
+
def _status_name(st: Any) -> str:
|
|
218
|
+
"""Extract a human-readable name from a status object."""
|
|
219
|
+
# ophyd statuses often expose .obj.name
|
|
220
|
+
if hasattr(st, "obj") and hasattr(st.obj, "name"):
|
|
221
|
+
return str(st.obj.name)
|
|
222
|
+
# Fall back to the name kwarg if stored
|
|
223
|
+
if hasattr(st, "name"):
|
|
224
|
+
return str(st.name)
|
|
225
|
+
return type(st).__name__
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""NATS <-> bluesky plan bridge.
|
|
2
|
+
|
|
3
|
+
Translates async NATS subscriptions into poll-able queues a generator-based
|
|
4
|
+
plan can drain via try_get(), yielding bps.sleep() between polls.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import queue
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class NATSPlanBridge:
|
|
14
|
+
"""Buffers NATS messages into thread-safe queues for synchronous plan polling.
|
|
15
|
+
|
|
16
|
+
The bridge subscribes to NATS subjects on behalf of a running plan. Incoming
|
|
17
|
+
messages land in an internal Queue. The plan drains the queue with
|
|
18
|
+
try_get() and yields bps.sleep() between polls, keeping the RunEngine
|
|
19
|
+
responsive.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, ipc_service: Any) -> None:
|
|
23
|
+
self._ipc = ipc_service
|
|
24
|
+
self._queues: dict[str, queue.Queue] = {}
|
|
25
|
+
self._subscriptions: list[Any] = []
|
|
26
|
+
|
|
27
|
+
def subscribe(self, subject: str) -> None:
|
|
28
|
+
"""Subscribe to a subject; incoming messages queue for try_get()."""
|
|
29
|
+
if subject in self._queues:
|
|
30
|
+
return
|
|
31
|
+
q: queue.Queue = queue.Queue()
|
|
32
|
+
self._queues[subject] = q
|
|
33
|
+
|
|
34
|
+
def handler(msg_subject: str, data: dict, reply: str | None) -> None:
|
|
35
|
+
q.put(data)
|
|
36
|
+
|
|
37
|
+
sub = self._ipc.subscribe(subject, callback=handler, main_thread=False)
|
|
38
|
+
self._subscriptions.append(sub)
|
|
39
|
+
|
|
40
|
+
def try_get(self, subject: str) -> dict | None:
|
|
41
|
+
"""Non-blocking: return next message or None if queue is empty."""
|
|
42
|
+
q = self._queues.get(subject)
|
|
43
|
+
if q is None:
|
|
44
|
+
return None
|
|
45
|
+
try:
|
|
46
|
+
return q.get_nowait()
|
|
47
|
+
except queue.Empty:
|
|
48
|
+
return None
|
|
49
|
+
|
|
50
|
+
def publish(self, subject: str, payload: dict) -> None:
|
|
51
|
+
"""Publish a message via the IPC service. Fire-and-forget."""
|
|
52
|
+
self._ipc.publish(subject, payload)
|
|
53
|
+
|
|
54
|
+
def cleanup(self) -> None:
|
|
55
|
+
"""Unsubscribe all subscriptions. Call from the plan's finally block."""
|
|
56
|
+
for sub in self._subscriptions:
|
|
57
|
+
try:
|
|
58
|
+
sub.unsubscribe()
|
|
59
|
+
except Exception:
|
|
60
|
+
pass
|
|
61
|
+
self._subscriptions.clear()
|
|
62
|
+
self._queues.clear()
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Plan UI framework — plans can embed runtime UI widgets.
|
|
2
|
+
|
|
3
|
+
Plans opt in by decorating with @plan_with_ui(UIClass). When Lightfall's
|
|
4
|
+
Plans panel submits such a plan, it creates a UI widget and shows it as
|
|
5
|
+
a tab in the panel. The plan and UI share state via a module-level
|
|
6
|
+
PlanState instance that the plan module defines.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from collections.abc import Callable
|
|
12
|
+
from typing import Any, TypeVar
|
|
13
|
+
|
|
14
|
+
from PySide6.QtCore import QObject, Signal
|
|
15
|
+
from PySide6.QtWidgets import QVBoxLayout, QWidget
|
|
16
|
+
|
|
17
|
+
_PlanFunc = TypeVar("_PlanFunc", bound=Callable[..., Any])
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class PlanState(QObject):
|
|
21
|
+
"""Shared state between a running plan and its UI.
|
|
22
|
+
|
|
23
|
+
Plan subclasses add their own signals and attributes. The plan module
|
|
24
|
+
keeps a module-level instance that both the plan function and the UI
|
|
25
|
+
widget reference directly.
|
|
26
|
+
|
|
27
|
+
Thread safety:
|
|
28
|
+
- Qt signals are thread-safe across threads.
|
|
29
|
+
- Simple attribute reads/writes on primitives are GIL-safe.
|
|
30
|
+
- Plans reset their state explicitly at the start of each run.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
status_changed = Signal(str)
|
|
34
|
+
|
|
35
|
+
stop_requested: bool = False
|
|
36
|
+
pause_requested: bool = False
|
|
37
|
+
|
|
38
|
+
def __init__(self) -> None:
|
|
39
|
+
super().__init__()
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class PlanUI(QWidget):
|
|
43
|
+
"""Base class for plan UI widgets.
|
|
44
|
+
|
|
45
|
+
Subclasses build their UI in __init__ and reference the module-level
|
|
46
|
+
PlanState instance directly (no framework injection needed).
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
def __init__(self, parent: QWidget | None = None) -> None:
|
|
50
|
+
super().__init__(parent)
|
|
51
|
+
self._layout = QVBoxLayout(self)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def plan_with_ui(ui_class: type[PlanUI]) -> Callable[[_PlanFunc], _PlanFunc]:
|
|
55
|
+
"""Decorator: attach a UI class to a plan function.
|
|
56
|
+
|
|
57
|
+
The Plans panel checks for the _plan_ui_class attribute when a plan is
|
|
58
|
+
submitted. If present, the panel instantiates the UI and shows it as
|
|
59
|
+
a tab while the plan runs.
|
|
60
|
+
|
|
61
|
+
Example:
|
|
62
|
+
>>> class MyPanel(PlanUI):
|
|
63
|
+
... pass
|
|
64
|
+
>>> @plan_with_ui(MyPanel)
|
|
65
|
+
... def my_plan(detectors):
|
|
66
|
+
... yield from bps.count(detectors)
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
def decorator(plan_func: _PlanFunc) -> _PlanFunc:
|
|
70
|
+
plan_func._plan_ui_class = ui_class # type: ignore[attr-defined]
|
|
71
|
+
return plan_func
|
|
72
|
+
|
|
73
|
+
return decorator
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def get_plan_ui_class(plan_func: Callable[..., Any]) -> type[PlanUI] | None:
|
|
77
|
+
"""Return the UI class attached to a plan, or None if it has none."""
|
|
78
|
+
return getattr(plan_func, "_plan_ui_class", None)
|