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,186 @@
|
|
|
1
|
+
"""Standard typed wrapper plans for common Bluesky operations.
|
|
2
|
+
|
|
3
|
+
These replace the raw bluesky builtins (bp.scan, bp.count, etc.) which use
|
|
4
|
+
*args signatures that can't generate useful procedural UIs. Each wrapper
|
|
5
|
+
provides proper type hints and Lightfall annotations for automatic UI generation.
|
|
6
|
+
|
|
7
|
+
The raw bp.* plans remain accessible via lightfall_run_plan_code and the IPython
|
|
8
|
+
console for power users who need the full flexibility.
|
|
9
|
+
|
|
10
|
+
Usage:
|
|
11
|
+
from lightfall.acquire.plans.standard_plans import register_standard_plans
|
|
12
|
+
register_standard_plans(registry)
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from collections.abc import Generator
|
|
18
|
+
from typing import TYPE_CHECKING, Annotated, Any
|
|
19
|
+
|
|
20
|
+
from bluesky import plans as bp
|
|
21
|
+
|
|
22
|
+
from lightfall.ui.annotations import Default, DeviceDefault, DeviceFilter, Unit
|
|
23
|
+
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from lightfall.acquire.plans.registry import PlanRegistry
|
|
26
|
+
|
|
27
|
+
# Type aliases
|
|
28
|
+
Device = Any
|
|
29
|
+
Motor = Any
|
|
30
|
+
Detector = Any
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# =============================================================================
|
|
34
|
+
# Count
|
|
35
|
+
# =============================================================================
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def count(
|
|
39
|
+
detectors: Annotated[
|
|
40
|
+
list[Detector],
|
|
41
|
+
DeviceFilter(group="areadetectors"),
|
|
42
|
+
DeviceDefault("PI_MTE3"),
|
|
43
|
+
],
|
|
44
|
+
num: Annotated[int, Default(1)] = 1,
|
|
45
|
+
delay: Annotated[float | None, Unit("s"), Default(None)] = None,
|
|
46
|
+
) -> Generator[Any, Any, Any]:
|
|
47
|
+
"""Count detectors one or more times.
|
|
48
|
+
|
|
49
|
+
Takes one or more readings from the specified detectors without
|
|
50
|
+
moving any motors.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
detectors: Detectors to read.
|
|
54
|
+
num: Number of readings to take.
|
|
55
|
+
delay: Delay between readings in seconds (None for no delay).
|
|
56
|
+
|
|
57
|
+
Yields:
|
|
58
|
+
Bluesky plan messages.
|
|
59
|
+
"""
|
|
60
|
+
yield from bp.count(detectors, num=num, delay=delay)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# =============================================================================
|
|
64
|
+
# Relative 1D Scan
|
|
65
|
+
# =============================================================================
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def rel_scan_1d(
|
|
69
|
+
detectors: Annotated[
|
|
70
|
+
list[Detector],
|
|
71
|
+
DeviceFilter(group="areadetectors"),
|
|
72
|
+
DeviceDefault("PI_MTE3"),
|
|
73
|
+
],
|
|
74
|
+
motor: Annotated[
|
|
75
|
+
Motor,
|
|
76
|
+
DeviceFilter(device_class="EpicsMotor"),
|
|
77
|
+
],
|
|
78
|
+
start: float,
|
|
79
|
+
stop: float,
|
|
80
|
+
num_points: int,
|
|
81
|
+
) -> Generator[Any, Any, Any]:
|
|
82
|
+
"""Relative 1D scan over a single motor.
|
|
83
|
+
|
|
84
|
+
Scans the motor relative to its current position. Start and stop
|
|
85
|
+
are offsets from the current position.
|
|
86
|
+
|
|
87
|
+
Args:
|
|
88
|
+
detectors: Detectors to read at each point.
|
|
89
|
+
motor: Motor to scan.
|
|
90
|
+
start: Starting offset from current position.
|
|
91
|
+
stop: Ending offset from current position.
|
|
92
|
+
num_points: Number of points in the scan.
|
|
93
|
+
|
|
94
|
+
Yields:
|
|
95
|
+
Bluesky plan messages.
|
|
96
|
+
"""
|
|
97
|
+
yield from bp.rel_scan(detectors, motor, start, stop, num_points)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# =============================================================================
|
|
101
|
+
# Adaptive Scan
|
|
102
|
+
# =============================================================================
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def adaptive_scan_1d(
|
|
106
|
+
detectors: Annotated[
|
|
107
|
+
list[Detector],
|
|
108
|
+
DeviceFilter(group="areadetectors"),
|
|
109
|
+
DeviceDefault("PI_MTE3"),
|
|
110
|
+
],
|
|
111
|
+
target_field: str,
|
|
112
|
+
motor: Annotated[
|
|
113
|
+
Motor,
|
|
114
|
+
DeviceFilter(device_class="EpicsMotor"),
|
|
115
|
+
],
|
|
116
|
+
start: float,
|
|
117
|
+
stop: float,
|
|
118
|
+
min_step: Annotated[float, Default(0.01)] = 0.01,
|
|
119
|
+
max_step: Annotated[float, Default(5.0)] = 5.0,
|
|
120
|
+
target_delta: Annotated[float, Default(0.1)] = 0.1,
|
|
121
|
+
backstep: Annotated[bool, Default(True)] = True,
|
|
122
|
+
threshold: Annotated[float, Default(0.8)] = 0.8,
|
|
123
|
+
) -> Generator[Any, Any, Any]:
|
|
124
|
+
"""Adaptive 1D scan that adjusts step size based on signal change.
|
|
125
|
+
|
|
126
|
+
Automatically uses smaller steps where the signal is changing rapidly
|
|
127
|
+
and larger steps where it is relatively flat.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
detectors: Detectors to read at each point.
|
|
131
|
+
target_field: Name of the data field to use for adaptive logic.
|
|
132
|
+
motor: Motor to scan.
|
|
133
|
+
start: Starting position.
|
|
134
|
+
stop: Ending position.
|
|
135
|
+
min_step: Minimum step size.
|
|
136
|
+
max_step: Maximum step size.
|
|
137
|
+
target_delta: Target change in signal between points.
|
|
138
|
+
backstep: Whether to allow backstepping.
|
|
139
|
+
threshold: Threshold for step size adjustment.
|
|
140
|
+
|
|
141
|
+
Yields:
|
|
142
|
+
Bluesky plan messages.
|
|
143
|
+
"""
|
|
144
|
+
yield from bp.adaptive_scan(
|
|
145
|
+
detectors,
|
|
146
|
+
target_field,
|
|
147
|
+
motor,
|
|
148
|
+
start,
|
|
149
|
+
stop,
|
|
150
|
+
min_step,
|
|
151
|
+
max_step,
|
|
152
|
+
target_delta,
|
|
153
|
+
backstep,
|
|
154
|
+
threshold,
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# =============================================================================
|
|
159
|
+
# Registration
|
|
160
|
+
# =============================================================================
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def register_standard_plans(registry: PlanRegistry) -> None:
|
|
164
|
+
"""Register standard typed wrapper plans.
|
|
165
|
+
|
|
166
|
+
Args:
|
|
167
|
+
registry: PlanRegistry to register plans in.
|
|
168
|
+
"""
|
|
169
|
+
from lightfall.acquire.plans.registry import PlanInfo
|
|
170
|
+
|
|
171
|
+
plans_to_register = [
|
|
172
|
+
("count", count, "count", "Count", ("#2196F3", "C")),
|
|
173
|
+
("rel_scan_1d", rel_scan_1d, "scan", "Relative 1D Scan", ("#4CAF50", "R")),
|
|
174
|
+
("adaptive_scan_1d", adaptive_scan_1d, "scan", "Adaptive Scan", ("#FF9800", "A")),
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
for name, func, category, display_name, icon in plans_to_register:
|
|
178
|
+
plan_info = PlanInfo.from_function(
|
|
179
|
+
name=name,
|
|
180
|
+
func=func,
|
|
181
|
+
category=category,
|
|
182
|
+
)
|
|
183
|
+
plan_info.display_name = display_name
|
|
184
|
+
plan_info.icon = icon
|
|
185
|
+
registry._plans[plan_info.name] = plan_info
|
|
186
|
+
registry._categories.add(plan_info.category)
|
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
"""Service for loading and managing user-defined Bluesky plans.
|
|
2
|
+
|
|
3
|
+
User plans are Python files in ~/lightfall/plans/ that define a `plan` variable
|
|
4
|
+
which must be a callable (generator function) that can be run by the RunEngine.
|
|
5
|
+
|
|
6
|
+
Each file corresponds to one plan. The filename (without .py) becomes the plan name.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import importlib.util
|
|
12
|
+
import sys
|
|
13
|
+
import threading
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
from typing import TYPE_CHECKING, Any, ClassVar
|
|
16
|
+
|
|
17
|
+
from loguru import logger
|
|
18
|
+
from PySide6.QtCore import QFileSystemWatcher, QObject, Signal
|
|
19
|
+
|
|
20
|
+
from lightfall.utils.git_tracker import GitTracker
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from lightfall.acquire.plans.registry import PlanInfo
|
|
24
|
+
|
|
25
|
+
# Template for new user plans
|
|
26
|
+
PLAN_TEMPLATE = '''"""{{name}} - Custom Bluesky plan.
|
|
27
|
+
|
|
28
|
+
{{description}}
|
|
29
|
+
"""
|
|
30
|
+
from __future__ import annotations
|
|
31
|
+
|
|
32
|
+
from typing import Any, Generator
|
|
33
|
+
|
|
34
|
+
import bluesky.plans as bp
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def plan(
|
|
38
|
+
detectors: list,
|
|
39
|
+
motor: Any,
|
|
40
|
+
start: float = -10.0,
|
|
41
|
+
stop: float = 10.0,
|
|
42
|
+
num: int = 21,
|
|
43
|
+
) -> Generator[Any, Any, Any]:
|
|
44
|
+
"""{{description}}
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
detectors: List of detectors to read at each point.
|
|
48
|
+
motor: Motor to scan.
|
|
49
|
+
start: Starting position.
|
|
50
|
+
stop: Ending position.
|
|
51
|
+
num: Number of points.
|
|
52
|
+
|
|
53
|
+
Yields:
|
|
54
|
+
Bluesky plan messages.
|
|
55
|
+
"""
|
|
56
|
+
yield from bp.scan(detectors, motor, start, stop, num)
|
|
57
|
+
'''
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class UserPlanService(QObject):
|
|
61
|
+
"""Service for loading and managing user-defined plans.
|
|
62
|
+
|
|
63
|
+
User plans are loaded from ~/lightfall/plans/ directory. Each .py file
|
|
64
|
+
in this directory that contains a callable `plan` variable is
|
|
65
|
+
registered with the plan registry under the "user" category.
|
|
66
|
+
|
|
67
|
+
The service uses a QFileSystemWatcher to automatically reload
|
|
68
|
+
plans when files are modified.
|
|
69
|
+
|
|
70
|
+
Signals:
|
|
71
|
+
plan_loaded: Emitted when a plan is successfully loaded.
|
|
72
|
+
plan_unloaded: Emitted when a plan is unloaded (name).
|
|
73
|
+
plan_error: Emitted when a plan fails to load (path, error).
|
|
74
|
+
plans_refreshed: Emitted after refresh_plans() completes.
|
|
75
|
+
|
|
76
|
+
Example:
|
|
77
|
+
>>> service = UserPlanService.get_instance()
|
|
78
|
+
>>> service.load_all_plans()
|
|
79
|
+
>>> service.create_new_plan("my_scan", "My custom scan plan")
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
_instance: ClassVar[UserPlanService | None] = None
|
|
83
|
+
_lock = threading.RLock()
|
|
84
|
+
|
|
85
|
+
plan_loaded = Signal(object) # PlanInfo
|
|
86
|
+
plan_unloaded = Signal(str) # plan name
|
|
87
|
+
plan_error = Signal(str, str) # path, error message
|
|
88
|
+
plans_refreshed = Signal()
|
|
89
|
+
|
|
90
|
+
def __init__(self, parent: QObject | None = None) -> None:
|
|
91
|
+
"""Initialize the user plan service."""
|
|
92
|
+
super().__init__(parent)
|
|
93
|
+
self._plans_dir = Path.home() / "lightfall" / "plans"
|
|
94
|
+
self._loaded_plans: dict[str, Path] = {} # name -> file path
|
|
95
|
+
self._watcher = QFileSystemWatcher(self)
|
|
96
|
+
self._watcher.fileChanged.connect(self._on_file_changed)
|
|
97
|
+
self._watcher.directoryChanged.connect(self._on_directory_changed)
|
|
98
|
+
|
|
99
|
+
# Ensure plans directory exists
|
|
100
|
+
self._ensure_directory()
|
|
101
|
+
|
|
102
|
+
logger.debug("UserPlanService initialized, plans dir: {}", self._plans_dir)
|
|
103
|
+
|
|
104
|
+
@classmethod
|
|
105
|
+
def get_instance(cls) -> UserPlanService:
|
|
106
|
+
"""Get the singleton UserPlanService instance."""
|
|
107
|
+
if cls._instance is None:
|
|
108
|
+
with cls._lock:
|
|
109
|
+
if cls._instance is None:
|
|
110
|
+
cls._instance = cls()
|
|
111
|
+
return cls._instance
|
|
112
|
+
|
|
113
|
+
@classmethod
|
|
114
|
+
def reset_instance(cls) -> None:
|
|
115
|
+
"""Reset the singleton instance (for testing)."""
|
|
116
|
+
with cls._lock:
|
|
117
|
+
if cls._instance is not None:
|
|
118
|
+
cls._instance.deleteLater()
|
|
119
|
+
cls._instance = None
|
|
120
|
+
|
|
121
|
+
def _ensure_directory(self) -> bool:
|
|
122
|
+
"""Ensure the plans directory exists.
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
True if directory exists or was created.
|
|
126
|
+
"""
|
|
127
|
+
try:
|
|
128
|
+
self._plans_dir.mkdir(parents=True, exist_ok=True)
|
|
129
|
+
# Watch the directory for new/deleted files
|
|
130
|
+
if str(self._plans_dir) not in self._watcher.directories():
|
|
131
|
+
self._watcher.addPath(str(self._plans_dir))
|
|
132
|
+
return True
|
|
133
|
+
except Exception as e:
|
|
134
|
+
logger.error("Failed to create plans directory: {}", e)
|
|
135
|
+
return False
|
|
136
|
+
|
|
137
|
+
def get_plans_directory(self) -> Path:
|
|
138
|
+
"""Get the user plans directory path.
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
Path to ~/lightfall/plans/
|
|
142
|
+
"""
|
|
143
|
+
return self._plans_dir
|
|
144
|
+
|
|
145
|
+
def open_plans_folder(self) -> bool:
|
|
146
|
+
"""Open the plans folder in the system file explorer.
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
True if successful.
|
|
150
|
+
"""
|
|
151
|
+
import os
|
|
152
|
+
import subprocess
|
|
153
|
+
import sys
|
|
154
|
+
|
|
155
|
+
self._ensure_directory()
|
|
156
|
+
|
|
157
|
+
try:
|
|
158
|
+
if sys.platform == "win32":
|
|
159
|
+
os.startfile(str(self._plans_dir))
|
|
160
|
+
elif sys.platform == "darwin":
|
|
161
|
+
subprocess.run(["open", str(self._plans_dir)], check=True)
|
|
162
|
+
else:
|
|
163
|
+
subprocess.run(["xdg-open", str(self._plans_dir)], check=True)
|
|
164
|
+
return True
|
|
165
|
+
except Exception as e:
|
|
166
|
+
logger.error("Failed to open plans folder: {}", e)
|
|
167
|
+
return False
|
|
168
|
+
|
|
169
|
+
def load_all_plans(self) -> list[tuple[Path, PlanInfo | Exception]]:
|
|
170
|
+
"""Load all plans from the plans directory.
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
List of (path, PlanInfo or Exception) tuples.
|
|
174
|
+
"""
|
|
175
|
+
from lightfall.acquire.plans.registry import PlanRegistry
|
|
176
|
+
|
|
177
|
+
results: list[tuple[Path, PlanInfo | Exception]] = []
|
|
178
|
+
|
|
179
|
+
if not self._plans_dir.exists():
|
|
180
|
+
logger.debug("Plans directory does not exist: {}", self._plans_dir)
|
|
181
|
+
return results
|
|
182
|
+
|
|
183
|
+
registry = PlanRegistry.get_instance()
|
|
184
|
+
|
|
185
|
+
for py_file in self._plans_dir.glob("*.py"):
|
|
186
|
+
if py_file.name.startswith("_"):
|
|
187
|
+
continue # Skip private files
|
|
188
|
+
|
|
189
|
+
result = self._load_plan_from_file(py_file, registry)
|
|
190
|
+
if result is not None:
|
|
191
|
+
results.append((py_file, result))
|
|
192
|
+
|
|
193
|
+
self.plans_refreshed.emit()
|
|
194
|
+
logger.info("Loaded {} user plans from {}", len(self._loaded_plans), self._plans_dir)
|
|
195
|
+
|
|
196
|
+
return results
|
|
197
|
+
|
|
198
|
+
def _commit_change(self, path: Path, commit_msg: str | None) -> None:
|
|
199
|
+
"""Commit a change to ``path`` via the GitTracker singleton.
|
|
200
|
+
|
|
201
|
+
Mirrors :meth:`UserPluginService._commit_change`. Called on every
|
|
202
|
+
terminal path of :meth:`load_plan_from_file` where the file has been
|
|
203
|
+
written to disk. Failed loads still commit -- the file's presence is
|
|
204
|
+
forensic evidence even when the load itself didn't take.
|
|
205
|
+
|
|
206
|
+
No-op if the path doesn't exist (delete paths handle their own
|
|
207
|
+
``commit_removal`` in the watcher slot). The tracker swallows all
|
|
208
|
+
errors, so this never raises.
|
|
209
|
+
"""
|
|
210
|
+
if not path.exists():
|
|
211
|
+
return # delete path: handled elsewhere
|
|
212
|
+
msg = commit_msg or f"auto: updated {path.name}"
|
|
213
|
+
GitTracker.get_instance().commit([path], msg)
|
|
214
|
+
|
|
215
|
+
def _commit_removal(self, path: Path, commit_msg: str) -> None:
|
|
216
|
+
"""Commit a removal of ``path`` via the GitTracker singleton.
|
|
217
|
+
|
|
218
|
+
Mirrors :meth:`_commit_change` for the deletion path. The tracker
|
|
219
|
+
swallows all errors, so this never raises.
|
|
220
|
+
"""
|
|
221
|
+
GitTracker.get_instance().commit_removal([path], commit_msg)
|
|
222
|
+
|
|
223
|
+
def load_plan_from_file(
|
|
224
|
+
self, path: Path, commit_msg: str | None = None,
|
|
225
|
+
) -> PlanInfo | None:
|
|
226
|
+
"""Load a single plan from a file.
|
|
227
|
+
|
|
228
|
+
Args:
|
|
229
|
+
path: Path to the Python file.
|
|
230
|
+
commit_msg: Optional subject for the auto-commit. Defaults to
|
|
231
|
+
``"auto: updated <name>"`` when omitted. Commits happen
|
|
232
|
+
regardless of load outcome -- failed loads land in history
|
|
233
|
+
as forensic evidence.
|
|
234
|
+
|
|
235
|
+
Returns:
|
|
236
|
+
PlanInfo if successful, None otherwise.
|
|
237
|
+
"""
|
|
238
|
+
from lightfall.acquire.plans.registry import PlanInfo, PlanRegistry
|
|
239
|
+
|
|
240
|
+
registry = PlanRegistry.get_instance()
|
|
241
|
+
result = self._load_plan_from_file(path, registry)
|
|
242
|
+
|
|
243
|
+
# Commit regardless of load outcome -- failed loads stay in history
|
|
244
|
+
# (forensics). The _commit_change helper guards against missing path.
|
|
245
|
+
self._commit_change(path, commit_msg)
|
|
246
|
+
|
|
247
|
+
if isinstance(result, PlanInfo):
|
|
248
|
+
return result
|
|
249
|
+
return None
|
|
250
|
+
|
|
251
|
+
def _load_plan_from_file(
|
|
252
|
+
self, path: Path, registry: Any
|
|
253
|
+
) -> PlanInfo | Exception | None:
|
|
254
|
+
"""Internal: Load a plan from file and register it.
|
|
255
|
+
|
|
256
|
+
Args:
|
|
257
|
+
path: Path to the Python file.
|
|
258
|
+
registry: PlanRegistry to register with.
|
|
259
|
+
|
|
260
|
+
Returns:
|
|
261
|
+
PlanInfo on success, Exception on error, None if no plan variable.
|
|
262
|
+
"""
|
|
263
|
+
|
|
264
|
+
plan_name = path.stem
|
|
265
|
+
|
|
266
|
+
try:
|
|
267
|
+
# Load the module
|
|
268
|
+
spec = importlib.util.spec_from_file_location(
|
|
269
|
+
f"lightfall_user_plans.{plan_name}", path
|
|
270
|
+
)
|
|
271
|
+
if spec is None or spec.loader is None:
|
|
272
|
+
logger.warning("Could not load module spec for: {}", path)
|
|
273
|
+
return None
|
|
274
|
+
|
|
275
|
+
module = importlib.util.module_from_spec(spec)
|
|
276
|
+
|
|
277
|
+
# Add to sys.modules temporarily for imports to work
|
|
278
|
+
module_name = f"lightfall_user_plans.{plan_name}"
|
|
279
|
+
sys.modules[module_name] = module
|
|
280
|
+
|
|
281
|
+
try:
|
|
282
|
+
spec.loader.exec_module(module)
|
|
283
|
+
except SyntaxError as e:
|
|
284
|
+
error_msg = f"Syntax error at line {e.lineno}: {e.msg}"
|
|
285
|
+
logger.warning("Syntax error in {}: {}", path.name, error_msg)
|
|
286
|
+
self.plan_error.emit(str(path), error_msg)
|
|
287
|
+
return e
|
|
288
|
+
except Exception as e:
|
|
289
|
+
error_msg = str(e)
|
|
290
|
+
logger.warning("Error loading {}: {}", path.name, error_msg)
|
|
291
|
+
self.plan_error.emit(str(path), error_msg)
|
|
292
|
+
return e
|
|
293
|
+
|
|
294
|
+
# Check for plan variable
|
|
295
|
+
if not hasattr(module, "plan"):
|
|
296
|
+
logger.debug("No 'plan' variable in {}", path.name)
|
|
297
|
+
return None
|
|
298
|
+
|
|
299
|
+
plan_func = module.plan
|
|
300
|
+
|
|
301
|
+
if not callable(plan_func):
|
|
302
|
+
logger.warning("'plan' in {} is not callable", path.name)
|
|
303
|
+
self.plan_error.emit(str(path), "'plan' is not callable")
|
|
304
|
+
return ValueError("'plan' is not callable")
|
|
305
|
+
|
|
306
|
+
# Register or replace the plan
|
|
307
|
+
plan_info = registry.register_or_replace(plan_name, plan_func, "user")
|
|
308
|
+
|
|
309
|
+
# Track loaded plan and watch file
|
|
310
|
+
self._loaded_plans[plan_name] = path
|
|
311
|
+
if str(path) not in self._watcher.files():
|
|
312
|
+
self._watcher.addPath(str(path))
|
|
313
|
+
|
|
314
|
+
self.plan_loaded.emit(plan_info)
|
|
315
|
+
logger.debug("Loaded user plan: {} from {}", plan_name, path.name)
|
|
316
|
+
|
|
317
|
+
return plan_info
|
|
318
|
+
|
|
319
|
+
except Exception as e:
|
|
320
|
+
logger.error("Failed to load plan from {}: {}", path, e)
|
|
321
|
+
self.plan_error.emit(str(path), str(e))
|
|
322
|
+
return e
|
|
323
|
+
|
|
324
|
+
def _unload_plan(self, name: str) -> bool:
|
|
325
|
+
"""Unload a plan by name.
|
|
326
|
+
|
|
327
|
+
Args:
|
|
328
|
+
name: Plan name.
|
|
329
|
+
|
|
330
|
+
Returns:
|
|
331
|
+
True if unloaded.
|
|
332
|
+
"""
|
|
333
|
+
from lightfall.acquire.plans.registry import PlanRegistry
|
|
334
|
+
|
|
335
|
+
if name not in self._loaded_plans:
|
|
336
|
+
return False
|
|
337
|
+
|
|
338
|
+
registry = PlanRegistry.get_instance()
|
|
339
|
+
registry.unregister(name)
|
|
340
|
+
|
|
341
|
+
path = self._loaded_plans.pop(name)
|
|
342
|
+
if str(path) in self._watcher.files():
|
|
343
|
+
self._watcher.removePath(str(path))
|
|
344
|
+
|
|
345
|
+
# Remove from sys.modules
|
|
346
|
+
module_name = f"lightfall_user_plans.{name}"
|
|
347
|
+
if module_name in sys.modules:
|
|
348
|
+
del sys.modules[module_name]
|
|
349
|
+
|
|
350
|
+
self.plan_unloaded.emit(name)
|
|
351
|
+
logger.debug("Unloaded user plan: {}", name)
|
|
352
|
+
|
|
353
|
+
return True
|
|
354
|
+
|
|
355
|
+
def create_new_plan(
|
|
356
|
+
self,
|
|
357
|
+
name: str,
|
|
358
|
+
description: str = "",
|
|
359
|
+
commit_msg: str | None = None,
|
|
360
|
+
) -> Path:
|
|
361
|
+
"""Create a new plan file from template.
|
|
362
|
+
|
|
363
|
+
Args:
|
|
364
|
+
name: Plan name (will be used as filename).
|
|
365
|
+
description: Optional plan description.
|
|
366
|
+
commit_msg: Optional subject for the auto-commit. Forwarded to
|
|
367
|
+
:meth:`load_plan_from_file`; defaults to
|
|
368
|
+
``"auto: updated <name>"`` when omitted.
|
|
369
|
+
|
|
370
|
+
Returns:
|
|
371
|
+
Path to the created file.
|
|
372
|
+
|
|
373
|
+
Raises:
|
|
374
|
+
ValueError: If name is invalid or file already exists.
|
|
375
|
+
OSError: If file creation fails.
|
|
376
|
+
"""
|
|
377
|
+
# Validate name is a valid Python identifier
|
|
378
|
+
if not name.isidentifier():
|
|
379
|
+
raise ValueError(f"'{name}' is not a valid Python identifier")
|
|
380
|
+
|
|
381
|
+
self._ensure_directory()
|
|
382
|
+
|
|
383
|
+
file_path = self._plans_dir / f"{name}.py"
|
|
384
|
+
|
|
385
|
+
if file_path.exists():
|
|
386
|
+
raise ValueError(f"Plan file already exists: {file_path}")
|
|
387
|
+
|
|
388
|
+
# Generate content from template
|
|
389
|
+
content = PLAN_TEMPLATE.replace("{{name}}", name)
|
|
390
|
+
content = content.replace(
|
|
391
|
+
"{{description}}", description if description else f"Custom plan: {name}"
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
# Write the file
|
|
395
|
+
file_path.write_text(content, encoding="utf-8")
|
|
396
|
+
logger.info("Created new plan file: {}", file_path)
|
|
397
|
+
|
|
398
|
+
# Load the new plan immediately. Forwarding commit_msg ensures a single
|
|
399
|
+
# commit happens with the user-supplied message.
|
|
400
|
+
self.load_plan_from_file(file_path, commit_msg=commit_msg)
|
|
401
|
+
|
|
402
|
+
return file_path
|
|
403
|
+
|
|
404
|
+
def refresh_plans(self) -> None:
|
|
405
|
+
"""Refresh all user plans from disk.
|
|
406
|
+
|
|
407
|
+
Unloads all current plans and reloads them from the directory.
|
|
408
|
+
"""
|
|
409
|
+
# Unload all current plans
|
|
410
|
+
for name in list(self._loaded_plans.keys()):
|
|
411
|
+
self._unload_plan(name)
|
|
412
|
+
|
|
413
|
+
# Reload all plans
|
|
414
|
+
self.load_all_plans()
|
|
415
|
+
|
|
416
|
+
def _on_file_changed(self, path: str) -> None:
|
|
417
|
+
"""Handle file change notification.
|
|
418
|
+
|
|
419
|
+
Args:
|
|
420
|
+
path: Path to the changed file.
|
|
421
|
+
"""
|
|
422
|
+
file_path = Path(path)
|
|
423
|
+
if not file_path.exists():
|
|
424
|
+
# File was deleted
|
|
425
|
+
plan_name = file_path.stem
|
|
426
|
+
if plan_name in self._loaded_plans:
|
|
427
|
+
self._unload_plan(plan_name)
|
|
428
|
+
self._commit_removal(
|
|
429
|
+
file_path, f"external delete: {file_path.name}"
|
|
430
|
+
)
|
|
431
|
+
self.plans_refreshed.emit()
|
|
432
|
+
else:
|
|
433
|
+
# File was modified - reload it (commit happens in load_plan_from_file)
|
|
434
|
+
self.load_plan_from_file(
|
|
435
|
+
file_path, commit_msg=f"external edit: {file_path.name}"
|
|
436
|
+
)
|
|
437
|
+
self.plans_refreshed.emit()
|
|
438
|
+
|
|
439
|
+
# Re-add the path to the watcher (Qt removes it after change)
|
|
440
|
+
if file_path.exists() and str(path) not in self._watcher.files():
|
|
441
|
+
self._watcher.addPath(path)
|
|
442
|
+
|
|
443
|
+
def _on_directory_changed(self, path: str) -> None:
|
|
444
|
+
"""Handle directory change notification.
|
|
445
|
+
|
|
446
|
+
Args:
|
|
447
|
+
path: Path to the changed directory.
|
|
448
|
+
"""
|
|
449
|
+
# Rescan for new/deleted files
|
|
450
|
+
current_files = {
|
|
451
|
+
p.stem for p in self._plans_dir.glob("*.py")
|
|
452
|
+
if not p.name.startswith("_")
|
|
453
|
+
}
|
|
454
|
+
loaded_names = set(self._loaded_plans.keys())
|
|
455
|
+
|
|
456
|
+
# Load new files
|
|
457
|
+
for name in current_files - loaded_names:
|
|
458
|
+
file_path = self._plans_dir / f"{name}.py"
|
|
459
|
+
self.load_plan_from_file(
|
|
460
|
+
file_path, commit_msg=f"external add: {file_path.name}"
|
|
461
|
+
)
|
|
462
|
+
|
|
463
|
+
# Unload deleted files
|
|
464
|
+
for name in loaded_names - current_files:
|
|
465
|
+
path = self._loaded_plans.get(name)
|
|
466
|
+
self._unload_plan(name)
|
|
467
|
+
if path is not None:
|
|
468
|
+
self._commit_removal(path, f"external delete: {path.name}")
|
|
469
|
+
|
|
470
|
+
self.plans_refreshed.emit()
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Qt-integrated Bluesky RunEngine for NCS.
|
|
2
|
+
|
|
3
|
+
Deprecated: This module is maintained for backward compatibility.
|
|
4
|
+
Use ncs.acquire.engine instead.
|
|
5
|
+
|
|
6
|
+
Example (old):
|
|
7
|
+
from lightfall.acquire.runengine import QRunEngine, get_run_engine
|
|
8
|
+
re = get_run_engine()
|
|
9
|
+
|
|
10
|
+
Example (new):
|
|
11
|
+
from lightfall.acquire import get_engine, BlueskyEngine
|
|
12
|
+
engine = get_engine()
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from lightfall.acquire.engine import BlueskyEngine, get_engine
|
|
18
|
+
|
|
19
|
+
__all__ = ["QRunEngine", "get_run_engine"]
|
|
20
|
+
|
|
21
|
+
# Backward compatibility aliases
|
|
22
|
+
QRunEngine = BlueskyEngine
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_run_engine(**kwargs):
|
|
26
|
+
"""Get the global QRunEngine instance.
|
|
27
|
+
|
|
28
|
+
Deprecated: Use get_engine() instead.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
**kwargs: Arguments passed to BlueskyEngine on first initialization.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
The global BlueskyEngine instance.
|
|
35
|
+
"""
|
|
36
|
+
return get_engine(**kwargs)
|