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,954 @@
|
|
|
1
|
+
"""Dynamic plan configuration widget.
|
|
2
|
+
|
|
3
|
+
Generates UI from plan function signatures using pyqtgraph's ParameterTree
|
|
4
|
+
for automatic parameter editing, with custom DeviceParameter for device selection.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import inspect
|
|
10
|
+
from collections.abc import Callable
|
|
11
|
+
from enum import Enum, StrEnum
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import TYPE_CHECKING, Annotated, Any, get_args, get_origin
|
|
14
|
+
|
|
15
|
+
from loguru import logger
|
|
16
|
+
from PySide6.QtCore import Signal, Slot
|
|
17
|
+
from PySide6.QtWidgets import (
|
|
18
|
+
QHBoxLayout,
|
|
19
|
+
QLabel,
|
|
20
|
+
QPushButton,
|
|
21
|
+
QVBoxLayout,
|
|
22
|
+
QWidget,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
from lightfall.utils.editor_launcher import CodeEditor, get_editor_from_string, open_in_editor
|
|
26
|
+
|
|
27
|
+
try:
|
|
28
|
+
from pyqtgraph.parametertree import Parameter, ParameterTree
|
|
29
|
+
from pyqtgraph.parametertree.parameterTypes import GroupParameter
|
|
30
|
+
|
|
31
|
+
HAS_PYQTGRAPH = True
|
|
32
|
+
except ImportError:
|
|
33
|
+
HAS_PYQTGRAPH = False
|
|
34
|
+
Parameter = None
|
|
35
|
+
ParameterTree = None
|
|
36
|
+
GroupParameter = None
|
|
37
|
+
|
|
38
|
+
if TYPE_CHECKING:
|
|
39
|
+
from lightfall.acquire.plans import PlanInfo
|
|
40
|
+
from lightfall.devices import DeviceCatalog
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# Parameter type categories for special handling
|
|
44
|
+
class ParamCategory(StrEnum):
|
|
45
|
+
"""Categories of plan parameters for UI generation."""
|
|
46
|
+
|
|
47
|
+
BASIC = "basic" # int, float, str, bool
|
|
48
|
+
DEVICE = "device" # Single device (motor, positioner)
|
|
49
|
+
DEVICES = "devices" # Multiple devices (detectors)
|
|
50
|
+
ENUM = "enum" # Enumeration type
|
|
51
|
+
LIST = "list" # Generic list
|
|
52
|
+
OTHER = "other" # Unknown type
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# Mapping from Python types to pyqtgraph parameter types
|
|
56
|
+
PARAM_TYPE_MAP = {
|
|
57
|
+
"int": "int",
|
|
58
|
+
"float": "float",
|
|
59
|
+
"str": "str",
|
|
60
|
+
"bool": "bool",
|
|
61
|
+
"list": "list",
|
|
62
|
+
"tuple": "list",
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def get_param_category(name: str, annotation: Any) -> ParamCategory:
|
|
67
|
+
"""Determine the category of a parameter based on name and type.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
name: Parameter name.
|
|
71
|
+
annotation: Type annotation.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
ParamCategory for the parameter.
|
|
75
|
+
"""
|
|
76
|
+
name_lower = name.lower()
|
|
77
|
+
|
|
78
|
+
# Check by name first (most reliable for bluesky plans)
|
|
79
|
+
if name_lower == "detectors" or name_lower == "dets":
|
|
80
|
+
return ParamCategory.DEVICES
|
|
81
|
+
if name_lower in ("motor", "signal", "positioner", "obj"):
|
|
82
|
+
return ParamCategory.DEVICE
|
|
83
|
+
|
|
84
|
+
# Check by annotation
|
|
85
|
+
if annotation is None or annotation is inspect.Parameter.empty:
|
|
86
|
+
return ParamCategory.OTHER
|
|
87
|
+
|
|
88
|
+
# Check if the type is a collection (list, tuple, etc.)
|
|
89
|
+
origin = get_origin(annotation)
|
|
90
|
+
is_collection = origin in (list, tuple)
|
|
91
|
+
|
|
92
|
+
type_str = str(annotation).lower()
|
|
93
|
+
|
|
94
|
+
# Device types - check if it's a collection to determine single vs multi
|
|
95
|
+
if "detector" in type_str or "readable" in type_str:
|
|
96
|
+
return ParamCategory.DEVICES if is_collection else ParamCategory.DEVICE
|
|
97
|
+
if "motor" in type_str or "positioner" in type_str or "movable" in type_str:
|
|
98
|
+
return ParamCategory.DEVICE
|
|
99
|
+
|
|
100
|
+
# Enum
|
|
101
|
+
if isinstance(annotation, type) and issubclass(annotation, Enum):
|
|
102
|
+
return ParamCategory.ENUM
|
|
103
|
+
|
|
104
|
+
# Basic types
|
|
105
|
+
type_name = getattr(annotation, "__name__", "").lower()
|
|
106
|
+
if type_name in PARAM_TYPE_MAP:
|
|
107
|
+
return ParamCategory.BASIC
|
|
108
|
+
|
|
109
|
+
# List/tuple
|
|
110
|
+
origin = get_origin(annotation)
|
|
111
|
+
if origin in (list, tuple):
|
|
112
|
+
return ParamCategory.LIST
|
|
113
|
+
|
|
114
|
+
return ParamCategory.OTHER
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# Ensure DeviceParameter is registered when this module is imported
|
|
118
|
+
def _ensure_device_parameter_registered():
|
|
119
|
+
"""Ensure the DeviceParameter type is registered with pyqtgraph."""
|
|
120
|
+
if HAS_PYQTGRAPH:
|
|
121
|
+
# Import triggers registration
|
|
122
|
+
import lightfall.ui.widgets.device_selector # noqa: F401
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
_ensure_device_parameter_registered()
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def resolve_string_annotation(annotation: Any, func: Callable | None = None) -> Any:
|
|
129
|
+
"""Resolve a string annotation to its actual type.
|
|
130
|
+
|
|
131
|
+
When using `from __future__ import annotations`, annotations are stored
|
|
132
|
+
as strings. This function evaluates them to get the actual type objects.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
annotation: The annotation (possibly a string).
|
|
136
|
+
func: The function the annotation belongs to (for namespace resolution).
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
The resolved annotation type.
|
|
140
|
+
"""
|
|
141
|
+
if not isinstance(annotation, str):
|
|
142
|
+
return annotation
|
|
143
|
+
|
|
144
|
+
# Build namespace for eval
|
|
145
|
+
namespace: dict[str, Any] = {}
|
|
146
|
+
|
|
147
|
+
# Add typing module contents
|
|
148
|
+
import typing
|
|
149
|
+
namespace.update(vars(typing))
|
|
150
|
+
|
|
151
|
+
# Add common types
|
|
152
|
+
namespace["Any"] = Any
|
|
153
|
+
namespace["Annotated"] = Annotated
|
|
154
|
+
|
|
155
|
+
# Add annotation classes
|
|
156
|
+
try:
|
|
157
|
+
from lightfall.ui.annotations import (
|
|
158
|
+
Decimals,
|
|
159
|
+
Default,
|
|
160
|
+
DeviceDefault,
|
|
161
|
+
DeviceFilter,
|
|
162
|
+
DeviceFilterAny,
|
|
163
|
+
DeviceIcon,
|
|
164
|
+
Range,
|
|
165
|
+
Unit,
|
|
166
|
+
)
|
|
167
|
+
namespace.update({
|
|
168
|
+
"Unit": Unit,
|
|
169
|
+
"Decimals": Decimals,
|
|
170
|
+
"Range": Range,
|
|
171
|
+
"Default": Default,
|
|
172
|
+
"DeviceFilter": DeviceFilter,
|
|
173
|
+
"DeviceFilterAny": DeviceFilterAny,
|
|
174
|
+
"DeviceDefault": DeviceDefault,
|
|
175
|
+
"DeviceIcon": DeviceIcon,
|
|
176
|
+
})
|
|
177
|
+
except ImportError:
|
|
178
|
+
pass
|
|
179
|
+
|
|
180
|
+
# Add function's module namespace if available
|
|
181
|
+
if func is not None:
|
|
182
|
+
module = inspect.getmodule(func)
|
|
183
|
+
if module is not None:
|
|
184
|
+
namespace.update(vars(module))
|
|
185
|
+
|
|
186
|
+
try:
|
|
187
|
+
return eval(annotation, namespace)
|
|
188
|
+
except Exception as e:
|
|
189
|
+
logger.debug(f"Failed to resolve annotation '{annotation}': {e}")
|
|
190
|
+
return annotation
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def extract_annotated_metadata(annotation: Any, func: Callable | None = None) -> tuple[Any, list[Any]]:
|
|
194
|
+
"""Extract base type and metadata from Annotated type hints.
|
|
195
|
+
|
|
196
|
+
Handles both actual type objects and string annotations (from
|
|
197
|
+
`from __future__ import annotations`).
|
|
198
|
+
|
|
199
|
+
Args:
|
|
200
|
+
annotation: A type annotation, possibly Annotated[T, meta1, meta2, ...].
|
|
201
|
+
func: Optional function for resolving string annotations.
|
|
202
|
+
|
|
203
|
+
Returns:
|
|
204
|
+
Tuple of (base_type, [metadata_items]).
|
|
205
|
+
If not an Annotated type, returns (annotation, []).
|
|
206
|
+
"""
|
|
207
|
+
# Resolve string annotation if needed
|
|
208
|
+
resolved = resolve_string_annotation(annotation, func)
|
|
209
|
+
|
|
210
|
+
origin = get_origin(resolved)
|
|
211
|
+
if origin is Annotated:
|
|
212
|
+
args = get_args(resolved)
|
|
213
|
+
if args:
|
|
214
|
+
return args[0], list(args[1:])
|
|
215
|
+
return resolved, []
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def annotation_to_param_type(annotation: Any) -> tuple[str, dict[str, Any]]:
|
|
219
|
+
"""Convert a type annotation to pyqtgraph parameter type.
|
|
220
|
+
|
|
221
|
+
Args:
|
|
222
|
+
annotation: Type annotation from function signature.
|
|
223
|
+
|
|
224
|
+
Returns:
|
|
225
|
+
Tuple of (param_type, extra_opts) for Parameter creation.
|
|
226
|
+
"""
|
|
227
|
+
extra_opts: dict[str, Any] = {}
|
|
228
|
+
|
|
229
|
+
if annotation is None or annotation is inspect.Parameter.empty:
|
|
230
|
+
return "str", extra_opts
|
|
231
|
+
|
|
232
|
+
# Handle string annotations
|
|
233
|
+
if isinstance(annotation, str):
|
|
234
|
+
annotation_name = annotation.lower()
|
|
235
|
+
if annotation_name in PARAM_TYPE_MAP:
|
|
236
|
+
return PARAM_TYPE_MAP[annotation_name], extra_opts
|
|
237
|
+
return "str", extra_opts
|
|
238
|
+
|
|
239
|
+
# Get the base type for generic types
|
|
240
|
+
origin = get_origin(annotation)
|
|
241
|
+
args = get_args(annotation)
|
|
242
|
+
|
|
243
|
+
# Handle Optional[X] (Union[X, None])
|
|
244
|
+
if origin is type(None) or (hasattr(origin, "__name__") and origin.__name__ == "Union"):
|
|
245
|
+
# Get the non-None type
|
|
246
|
+
non_none_args = [a for a in args if a is not type(None)]
|
|
247
|
+
if non_none_args:
|
|
248
|
+
return annotation_to_param_type(non_none_args[0])
|
|
249
|
+
|
|
250
|
+
# Handle list/tuple
|
|
251
|
+
if origin in (list, tuple):
|
|
252
|
+
return "text", extra_opts # Use text for entering list values
|
|
253
|
+
|
|
254
|
+
# Handle Enum
|
|
255
|
+
if isinstance(annotation, type) and issubclass(annotation, Enum):
|
|
256
|
+
extra_opts["limits"] = [e.value for e in annotation]
|
|
257
|
+
return "list", extra_opts
|
|
258
|
+
|
|
259
|
+
# Handle basic types
|
|
260
|
+
type_name = getattr(annotation, "__name__", str(annotation)).lower()
|
|
261
|
+
if type_name in PARAM_TYPE_MAP:
|
|
262
|
+
return PARAM_TYPE_MAP[type_name], extra_opts
|
|
263
|
+
|
|
264
|
+
# Special handling for common ophyd/bluesky types
|
|
265
|
+
type_str = str(annotation).lower()
|
|
266
|
+
if "motor" in type_str or "positioner" in type_str or "movable" in type_str:
|
|
267
|
+
return "str", {"tip": "Device name from catalog"}
|
|
268
|
+
if "detector" in type_str or "readable" in type_str:
|
|
269
|
+
return "str", {"tip": "Detector name(s) from catalog"}
|
|
270
|
+
|
|
271
|
+
return "str", extra_opts
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def signature_to_parameters(
|
|
275
|
+
sig: inspect.Signature,
|
|
276
|
+
param_docs: dict[str, str] | None = None,
|
|
277
|
+
) -> list[dict[str, Any]]:
|
|
278
|
+
"""Convert a function signature to pyqtgraph Parameter specifications.
|
|
279
|
+
|
|
280
|
+
Args:
|
|
281
|
+
sig: Function signature.
|
|
282
|
+
param_docs: Optional mapping of param names to descriptions.
|
|
283
|
+
|
|
284
|
+
Returns:
|
|
285
|
+
List of parameter dictionaries for Parameter.create().
|
|
286
|
+
"""
|
|
287
|
+
param_docs = param_docs or {}
|
|
288
|
+
param_specs = []
|
|
289
|
+
|
|
290
|
+
for name, param in sig.parameters.items():
|
|
291
|
+
# Skip *args and **kwargs
|
|
292
|
+
if param.kind in (
|
|
293
|
+
inspect.Parameter.VAR_POSITIONAL,
|
|
294
|
+
inspect.Parameter.VAR_KEYWORD,
|
|
295
|
+
):
|
|
296
|
+
continue
|
|
297
|
+
|
|
298
|
+
param_type, extra_opts = annotation_to_param_type(param.annotation)
|
|
299
|
+
|
|
300
|
+
spec = {
|
|
301
|
+
"name": name,
|
|
302
|
+
"type": param_type,
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
# Add default value
|
|
306
|
+
if param.default is not inspect.Parameter.empty:
|
|
307
|
+
# Convert list/tuple to string for text parameters
|
|
308
|
+
if param_type == "text" and isinstance(param.default, (list, tuple)):
|
|
309
|
+
spec["value"] = ", ".join(str(v) for v in param.default)
|
|
310
|
+
else:
|
|
311
|
+
spec["value"] = param.default
|
|
312
|
+
else:
|
|
313
|
+
# Set sensible defaults for required parameters
|
|
314
|
+
if param_type == "int":
|
|
315
|
+
spec["value"] = 0
|
|
316
|
+
elif param_type == "float":
|
|
317
|
+
spec["value"] = 0.0
|
|
318
|
+
elif param_type == "bool":
|
|
319
|
+
spec["value"] = False
|
|
320
|
+
elif param_type in ("str", "text"):
|
|
321
|
+
spec["value"] = ""
|
|
322
|
+
|
|
323
|
+
# Add tooltip from docstring
|
|
324
|
+
if name in param_docs:
|
|
325
|
+
spec["tip"] = param_docs[name]
|
|
326
|
+
|
|
327
|
+
# Merge extra options
|
|
328
|
+
spec.update(extra_opts)
|
|
329
|
+
|
|
330
|
+
param_specs.append(spec)
|
|
331
|
+
|
|
332
|
+
return param_specs
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
class PlanConfigWidget(QWidget):
|
|
336
|
+
"""Dynamically generated UI for configuring plan parameters.
|
|
337
|
+
|
|
338
|
+
Uses pyqtgraph's ParameterTree for all parameters, including custom
|
|
339
|
+
DeviceParameter type for device selection. Provides validation
|
|
340
|
+
and Run button.
|
|
341
|
+
|
|
342
|
+
Signals:
|
|
343
|
+
run_requested(PlanInfo, dict): Emitted when Run is clicked with plan and kwargs.
|
|
344
|
+
values_changed(dict): Emitted when any parameter value changes.
|
|
345
|
+
|
|
346
|
+
Example:
|
|
347
|
+
>>> from lightfall.acquire.plans import get_registry
|
|
348
|
+
>>> registry = get_registry()
|
|
349
|
+
>>> plan_info = registry.get_plan("scan")
|
|
350
|
+
>>> config = PlanConfigWidget()
|
|
351
|
+
>>> config.set_catalog(device_catalog)
|
|
352
|
+
>>> config.set_plan(plan_info)
|
|
353
|
+
>>> config.run_requested.connect(run_plan)
|
|
354
|
+
"""
|
|
355
|
+
|
|
356
|
+
run_requested = Signal(object, dict) # (PlanInfo, kwargs)
|
|
357
|
+
values_changed = Signal(dict)
|
|
358
|
+
|
|
359
|
+
def __init__(self, parent: QWidget | None = None) -> None:
|
|
360
|
+
"""Initialize the config widget.
|
|
361
|
+
|
|
362
|
+
Args:
|
|
363
|
+
parent: Optional parent widget.
|
|
364
|
+
"""
|
|
365
|
+
super().__init__(parent)
|
|
366
|
+
self._plan: PlanInfo | None = None
|
|
367
|
+
self._root_param: Parameter | None = None
|
|
368
|
+
self._catalog: DeviceCatalog | None = None
|
|
369
|
+
self._values_cache: dict[str, dict[str, Any]] = {}
|
|
370
|
+
self._setup_ui()
|
|
371
|
+
|
|
372
|
+
def _setup_ui(self) -> None:
|
|
373
|
+
"""Set up the user interface."""
|
|
374
|
+
layout = QVBoxLayout(self)
|
|
375
|
+
layout.setContentsMargins(4, 4, 4, 4)
|
|
376
|
+
|
|
377
|
+
# Header
|
|
378
|
+
self._header_label = QLabel("No plan selected")
|
|
379
|
+
self._header_label.setStyleSheet("font-weight: bold; font-size: 12pt;")
|
|
380
|
+
layout.addWidget(self._header_label)
|
|
381
|
+
|
|
382
|
+
self._desc_label = QLabel("")
|
|
383
|
+
self._desc_label.setWordWrap(True)
|
|
384
|
+
layout.addWidget(self._desc_label)
|
|
385
|
+
|
|
386
|
+
# Parameter tree for all parameters
|
|
387
|
+
if HAS_PYQTGRAPH:
|
|
388
|
+
self._param_tree = ParameterTree(showHeader=False)
|
|
389
|
+
layout.addWidget(self._param_tree, 1)
|
|
390
|
+
else:
|
|
391
|
+
self._param_tree = None
|
|
392
|
+
self._fallback_label = QLabel(
|
|
393
|
+
"pyqtgraph not available.\n"
|
|
394
|
+
"Install with: pip install pyqtgraph"
|
|
395
|
+
)
|
|
396
|
+
layout.addWidget(self._fallback_label, 1)
|
|
397
|
+
|
|
398
|
+
# Button row
|
|
399
|
+
button_layout = QHBoxLayout()
|
|
400
|
+
button_layout.addStretch()
|
|
401
|
+
|
|
402
|
+
self._reset_btn = QPushButton("Reset")
|
|
403
|
+
self._reset_btn.setToolTip("Reset to default values")
|
|
404
|
+
self._reset_btn.clicked.connect(self._on_reset_clicked)
|
|
405
|
+
self._reset_btn.setEnabled(False)
|
|
406
|
+
button_layout.addWidget(self._reset_btn)
|
|
407
|
+
|
|
408
|
+
self._edit_btn = QPushButton("Edit")
|
|
409
|
+
self._edit_btn.setToolTip("Open plan source file in editor")
|
|
410
|
+
self._edit_btn.clicked.connect(self._on_edit_clicked)
|
|
411
|
+
self._edit_btn.setEnabled(False)
|
|
412
|
+
button_layout.addWidget(self._edit_btn)
|
|
413
|
+
|
|
414
|
+
self._run_btn = QPushButton("Run")
|
|
415
|
+
self._run_btn.setToolTip("Run the plan with current parameters")
|
|
416
|
+
self._run_btn.clicked.connect(self._on_run_clicked)
|
|
417
|
+
self._run_btn.setEnabled(False)
|
|
418
|
+
button_layout.addWidget(self._run_btn)
|
|
419
|
+
|
|
420
|
+
layout.addLayout(button_layout)
|
|
421
|
+
|
|
422
|
+
def set_catalog(self, catalog: DeviceCatalog) -> None:
|
|
423
|
+
"""Set the device catalog for device selection.
|
|
424
|
+
|
|
425
|
+
Args:
|
|
426
|
+
catalog: DeviceCatalog instance.
|
|
427
|
+
"""
|
|
428
|
+
self._catalog = catalog
|
|
429
|
+
|
|
430
|
+
def _build_param_spec(
|
|
431
|
+
self,
|
|
432
|
+
name: str,
|
|
433
|
+
annotation: Any,
|
|
434
|
+
default: Any,
|
|
435
|
+
doc: str | None,
|
|
436
|
+
func: Callable | None = None,
|
|
437
|
+
) -> dict[str, Any]:
|
|
438
|
+
"""Build a parameter spec from annotation with metadata.
|
|
439
|
+
|
|
440
|
+
Extracts annotation metadata (Unit, Decimals, Range, DeviceFilter, etc.)
|
|
441
|
+
and applies them to the parameter specification.
|
|
442
|
+
|
|
443
|
+
Args:
|
|
444
|
+
name: Parameter name.
|
|
445
|
+
annotation: Type annotation (possibly Annotated[...]).
|
|
446
|
+
default: Default value from function signature.
|
|
447
|
+
doc: Documentation string for tooltip.
|
|
448
|
+
func: The plan function (for resolving string annotations).
|
|
449
|
+
|
|
450
|
+
Returns:
|
|
451
|
+
Parameter specification dict for pyqtgraph Parameter.create().
|
|
452
|
+
"""
|
|
453
|
+
from lightfall.ui.annotations import (
|
|
454
|
+
Decimals,
|
|
455
|
+
Default,
|
|
456
|
+
DeviceDefault,
|
|
457
|
+
DeviceFilter,
|
|
458
|
+
DeviceFilterAny,
|
|
459
|
+
Range,
|
|
460
|
+
Unit,
|
|
461
|
+
)
|
|
462
|
+
|
|
463
|
+
# Extract base type and metadata from Annotated[T, meta1, meta2, ...]
|
|
464
|
+
base_type, metadata = extract_annotated_metadata(annotation, func)
|
|
465
|
+
|
|
466
|
+
# Determine parameter category and type using the base type
|
|
467
|
+
category = get_param_category(name, base_type)
|
|
468
|
+
|
|
469
|
+
# Check if metadata contains DeviceFilter - this overrides category detection
|
|
470
|
+
# This handles cases like `Annotated[Any, DeviceFilter(...)]` where the base
|
|
471
|
+
# type doesn't indicate it's a device but the annotation metadata does
|
|
472
|
+
has_device_filter = any(
|
|
473
|
+
isinstance(meta, (DeviceFilter, DeviceFilterAny)) for meta in metadata
|
|
474
|
+
)
|
|
475
|
+
if has_device_filter and category not in (ParamCategory.DEVICE, ParamCategory.DEVICES):
|
|
476
|
+
# Determine single vs multi-select based on whether base type is a list
|
|
477
|
+
origin = get_origin(base_type)
|
|
478
|
+
if origin in (list, tuple):
|
|
479
|
+
category = ParamCategory.DEVICES
|
|
480
|
+
else:
|
|
481
|
+
category = ParamCategory.DEVICE
|
|
482
|
+
|
|
483
|
+
# Start building the spec
|
|
484
|
+
spec: dict[str, Any] = {"name": name}
|
|
485
|
+
|
|
486
|
+
if category in (ParamCategory.DEVICE, ParamCategory.DEVICES):
|
|
487
|
+
from lightfall.devices.model import DeviceCategory as DC
|
|
488
|
+
from lightfall.ui.annotations import DeviceDefault, DeviceIcon
|
|
489
|
+
|
|
490
|
+
spec["type"] = "device"
|
|
491
|
+
spec["value"] = []
|
|
492
|
+
spec["catalog"] = self._catalog
|
|
493
|
+
spec["multi_select"] = category == ParamCategory.DEVICES
|
|
494
|
+
|
|
495
|
+
for meta in metadata:
|
|
496
|
+
if isinstance(meta, DeviceFilter):
|
|
497
|
+
# Translate category to set[DeviceCategory]
|
|
498
|
+
if meta.category is not None:
|
|
499
|
+
if isinstance(meta.category, set):
|
|
500
|
+
spec["categories"] = {DC(c) for c in meta.category}
|
|
501
|
+
else:
|
|
502
|
+
spec["categories"] = {DC(meta.category)}
|
|
503
|
+
if meta.device_class is not None:
|
|
504
|
+
spec.setdefault("filter_func_parts", []).append(
|
|
505
|
+
lambda m, dc=meta.device_class: (
|
|
506
|
+
m["device_info"] is not None
|
|
507
|
+
and (
|
|
508
|
+
m["device_info"].device_class == dc
|
|
509
|
+
or m["device_info"].device_class.rsplit(".", 1)[-1] == dc
|
|
510
|
+
)
|
|
511
|
+
)
|
|
512
|
+
)
|
|
513
|
+
if meta.group is not None:
|
|
514
|
+
spec.setdefault("filter_func_parts", []).append(
|
|
515
|
+
lambda m, g=meta.group: (
|
|
516
|
+
m["device_info"] is not None
|
|
517
|
+
and g in m["device_info"].tags
|
|
518
|
+
)
|
|
519
|
+
)
|
|
520
|
+
if meta.name_pattern is not None:
|
|
521
|
+
import re as _re
|
|
522
|
+
spec.setdefault("filter_func_parts", []).append(
|
|
523
|
+
lambda m, p=meta.name_pattern: bool(
|
|
524
|
+
_re.match(p, m["name"], _re.IGNORECASE)
|
|
525
|
+
)
|
|
526
|
+
)
|
|
527
|
+
elif isinstance(meta, DeviceFilterAny):
|
|
528
|
+
# Collect all categories from sub-filters
|
|
529
|
+
cats: set[DC] = set()
|
|
530
|
+
for flt in meta.filters:
|
|
531
|
+
if flt.category is not None:
|
|
532
|
+
if isinstance(flt.category, set):
|
|
533
|
+
cats.update(DC(c) for c in flt.category)
|
|
534
|
+
else:
|
|
535
|
+
cats.add(DC(flt.category))
|
|
536
|
+
if cats:
|
|
537
|
+
spec["categories"] = cats
|
|
538
|
+
elif isinstance(meta, DeviceDefault):
|
|
539
|
+
if meta.names:
|
|
540
|
+
spec["value"] = list(meta.names)
|
|
541
|
+
elif isinstance(meta, DeviceIcon):
|
|
542
|
+
spec["icon"] = meta.name
|
|
543
|
+
|
|
544
|
+
# Combine filter_func_parts into a single filter_func
|
|
545
|
+
parts = spec.pop("filter_func_parts", [])
|
|
546
|
+
if parts:
|
|
547
|
+
spec["filter_func"] = lambda m, _parts=parts: all(f(m) for f in _parts)
|
|
548
|
+
else:
|
|
549
|
+
# Use standard parameter type
|
|
550
|
+
param_type, extra_opts = annotation_to_param_type(base_type)
|
|
551
|
+
spec["type"] = param_type
|
|
552
|
+
spec.update(extra_opts)
|
|
553
|
+
|
|
554
|
+
# Add default value from signature
|
|
555
|
+
if default is not inspect.Parameter.empty:
|
|
556
|
+
# Convert list/tuple to string for text parameters
|
|
557
|
+
if param_type == "text" and isinstance(default, (list, tuple)):
|
|
558
|
+
# Format as comma-separated values for user editing
|
|
559
|
+
spec["value"] = ", ".join(str(v) for v in default)
|
|
560
|
+
else:
|
|
561
|
+
spec["value"] = default
|
|
562
|
+
else:
|
|
563
|
+
# Set sensible defaults for required parameters
|
|
564
|
+
if param_type == "int":
|
|
565
|
+
spec["value"] = 0
|
|
566
|
+
elif param_type == "float":
|
|
567
|
+
spec["value"] = 0.0
|
|
568
|
+
elif param_type == "bool":
|
|
569
|
+
spec["value"] = False
|
|
570
|
+
elif param_type in ("str", "text"):
|
|
571
|
+
spec["value"] = ""
|
|
572
|
+
|
|
573
|
+
# Process metadata for numeric/other parameters
|
|
574
|
+
for meta in metadata:
|
|
575
|
+
if isinstance(meta, Unit):
|
|
576
|
+
spec["suffix"] = meta.suffix
|
|
577
|
+
elif isinstance(meta, Decimals):
|
|
578
|
+
spec["decimals"] = meta.places
|
|
579
|
+
elif isinstance(meta, Range):
|
|
580
|
+
limits = []
|
|
581
|
+
if meta.min is not None or meta.max is not None:
|
|
582
|
+
# pyqtgraph expects (min, max) tuple
|
|
583
|
+
limits = [meta.min, meta.max]
|
|
584
|
+
# Replace None with appropriate defaults
|
|
585
|
+
if limits[0] is None:
|
|
586
|
+
limits[0] = float("-inf") if param_type == "float" else -(2**31)
|
|
587
|
+
if limits[1] is None:
|
|
588
|
+
limits[1] = float("inf") if param_type == "float" else 2**31 - 1
|
|
589
|
+
spec["limits"] = tuple(limits)
|
|
590
|
+
elif isinstance(meta, Default):
|
|
591
|
+
# Convert list/tuple to string for text parameters
|
|
592
|
+
if param_type == "text" and isinstance(meta.value, (list, tuple)):
|
|
593
|
+
spec["value"] = ", ".join(str(v) for v in meta.value)
|
|
594
|
+
else:
|
|
595
|
+
spec["value"] = meta.value
|
|
596
|
+
|
|
597
|
+
# Add tooltip from docstring
|
|
598
|
+
if doc:
|
|
599
|
+
spec["tip"] = doc
|
|
600
|
+
|
|
601
|
+
return spec
|
|
602
|
+
|
|
603
|
+
def set_plan(self, plan_info: PlanInfo) -> None:
|
|
604
|
+
"""Configure UI for a new plan.
|
|
605
|
+
|
|
606
|
+
Supports Annotated type hints with metadata for:
|
|
607
|
+
- Unit: Display suffix (e.g., "eV", "s", "mm")
|
|
608
|
+
- Decimals: Float precision (number of decimal places)
|
|
609
|
+
- Range: Min/max limits for numeric inputs
|
|
610
|
+
- DeviceFilter/DeviceFilterAny: Device selection filtering
|
|
611
|
+
- DeviceDefault: Pre-selected devices
|
|
612
|
+
|
|
613
|
+
Args:
|
|
614
|
+
plan_info: Plan to configure.
|
|
615
|
+
"""
|
|
616
|
+
# Cache current values before switching
|
|
617
|
+
if self._plan is not None and self._root_param is not None:
|
|
618
|
+
self._values_cache[self._plan.name] = self.get_kwargs()
|
|
619
|
+
|
|
620
|
+
self._plan = plan_info
|
|
621
|
+
# Use display name for header
|
|
622
|
+
self._header_label.setText(plan_info.get_display_name())
|
|
623
|
+
self._desc_label.setText(plan_info.description)
|
|
624
|
+
|
|
625
|
+
if not HAS_PYQTGRAPH or self._param_tree is None:
|
|
626
|
+
logger.warning("pyqtgraph not available, cannot configure plan")
|
|
627
|
+
return
|
|
628
|
+
|
|
629
|
+
# Build parameter docs from PlanInfo
|
|
630
|
+
param_docs = {p.name: p.description for p in plan_info.parameters}
|
|
631
|
+
|
|
632
|
+
# Convert all parameters to parameter specs
|
|
633
|
+
param_specs = []
|
|
634
|
+
for p in plan_info.parameters:
|
|
635
|
+
# Skip *args and **kwargs
|
|
636
|
+
if p.kind in (
|
|
637
|
+
inspect.Parameter.VAR_POSITIONAL,
|
|
638
|
+
inspect.Parameter.VAR_KEYWORD,
|
|
639
|
+
):
|
|
640
|
+
continue
|
|
641
|
+
|
|
642
|
+
spec = self._build_param_spec(
|
|
643
|
+
name=p.name,
|
|
644
|
+
annotation=p.annotation,
|
|
645
|
+
default=p.default,
|
|
646
|
+
doc=param_docs.get(p.name),
|
|
647
|
+
func=plan_info.func,
|
|
648
|
+
)
|
|
649
|
+
param_specs.append(spec)
|
|
650
|
+
|
|
651
|
+
# Create root parameter group
|
|
652
|
+
self._root_param = Parameter.create(
|
|
653
|
+
name=plan_info.name,
|
|
654
|
+
type="group",
|
|
655
|
+
children=param_specs,
|
|
656
|
+
)
|
|
657
|
+
|
|
658
|
+
# Connect change signal
|
|
659
|
+
self._root_param.sigTreeStateChanged.connect(self._on_param_changed)
|
|
660
|
+
|
|
661
|
+
# Set in tree
|
|
662
|
+
self._param_tree.setParameters(self._root_param, showTop=False)
|
|
663
|
+
|
|
664
|
+
# Restore cached values if we've seen this plan before
|
|
665
|
+
cached = self._values_cache.get(plan_info.name)
|
|
666
|
+
if cached:
|
|
667
|
+
self.set_values(cached)
|
|
668
|
+
|
|
669
|
+
self._reset_btn.setEnabled(True)
|
|
670
|
+
self._edit_btn.setEnabled(True)
|
|
671
|
+
self._run_btn.setEnabled(True)
|
|
672
|
+
|
|
673
|
+
logger.debug(f"Configured plan: {plan_info.name} with {len(param_specs)} params")
|
|
674
|
+
|
|
675
|
+
def clear(self) -> None:
|
|
676
|
+
"""Clear the current plan configuration."""
|
|
677
|
+
self._plan = None
|
|
678
|
+
self._root_param = None
|
|
679
|
+
self._header_label.setText("No plan selected")
|
|
680
|
+
self._desc_label.setText("")
|
|
681
|
+
|
|
682
|
+
if self._param_tree is not None:
|
|
683
|
+
self._param_tree.clear()
|
|
684
|
+
|
|
685
|
+
self._reset_btn.setEnabled(False)
|
|
686
|
+
self._edit_btn.setEnabled(False)
|
|
687
|
+
self._run_btn.setEnabled(False)
|
|
688
|
+
|
|
689
|
+
def get_kwargs(self) -> dict[str, Any]:
|
|
690
|
+
"""Get current parameter values as kwargs.
|
|
691
|
+
|
|
692
|
+
Returns:
|
|
693
|
+
Dictionary of parameter name to value.
|
|
694
|
+
"""
|
|
695
|
+
kwargs = {}
|
|
696
|
+
|
|
697
|
+
if self._root_param is not None:
|
|
698
|
+
for child in self._root_param.children():
|
|
699
|
+
value = child.value()
|
|
700
|
+
# Skip empty values for optional params
|
|
701
|
+
if value is None:
|
|
702
|
+
continue
|
|
703
|
+
if isinstance(value, str) and value == "":
|
|
704
|
+
continue
|
|
705
|
+
if isinstance(value, list) and len(value) == 0:
|
|
706
|
+
continue
|
|
707
|
+
kwargs[child.name()] = value
|
|
708
|
+
|
|
709
|
+
return kwargs
|
|
710
|
+
|
|
711
|
+
def set_values(self, values: dict[str, Any]) -> None:
|
|
712
|
+
"""Set parameter values.
|
|
713
|
+
|
|
714
|
+
Args:
|
|
715
|
+
values: Dictionary of parameter name to value.
|
|
716
|
+
"""
|
|
717
|
+
if self._root_param is None:
|
|
718
|
+
return
|
|
719
|
+
|
|
720
|
+
for name, value in values.items():
|
|
721
|
+
child = self._root_param.child(name)
|
|
722
|
+
if child is not None:
|
|
723
|
+
try:
|
|
724
|
+
child.setValue(value)
|
|
725
|
+
except Exception as e:
|
|
726
|
+
logger.warning(f"Failed to set {name}={value}: {e}")
|
|
727
|
+
|
|
728
|
+
def validate(self) -> tuple[bool, list[str]]:
|
|
729
|
+
"""Validate current parameter values.
|
|
730
|
+
|
|
731
|
+
Returns:
|
|
732
|
+
Tuple of (is_valid, list_of_errors).
|
|
733
|
+
"""
|
|
734
|
+
errors = []
|
|
735
|
+
|
|
736
|
+
if self._plan is None:
|
|
737
|
+
errors.append("No plan selected")
|
|
738
|
+
return False, errors
|
|
739
|
+
|
|
740
|
+
if self._root_param is None:
|
|
741
|
+
errors.append("Parameters not configured")
|
|
742
|
+
return False, errors
|
|
743
|
+
|
|
744
|
+
# Check required parameters
|
|
745
|
+
for param_info in self._plan.parameters:
|
|
746
|
+
if param_info.required:
|
|
747
|
+
child = self._root_param.child(param_info.name)
|
|
748
|
+
if child is None:
|
|
749
|
+
continue
|
|
750
|
+
|
|
751
|
+
value = child.value()
|
|
752
|
+
is_empty = (
|
|
753
|
+
value is None
|
|
754
|
+
or (isinstance(value, str) and value == "")
|
|
755
|
+
or (isinstance(value, list) and len(value) == 0)
|
|
756
|
+
)
|
|
757
|
+
if is_empty:
|
|
758
|
+
errors.append(f"Required parameter '{param_info.name}' is empty")
|
|
759
|
+
|
|
760
|
+
return len(errors) == 0, errors
|
|
761
|
+
|
|
762
|
+
@property
|
|
763
|
+
def current_plan(self) -> PlanInfo | None:
|
|
764
|
+
"""Get the currently configured plan."""
|
|
765
|
+
return self._plan
|
|
766
|
+
|
|
767
|
+
# === Slots ===
|
|
768
|
+
|
|
769
|
+
@Slot()
|
|
770
|
+
def _on_reset_clicked(self) -> None:
|
|
771
|
+
"""Handle reset button click."""
|
|
772
|
+
if self._plan is not None:
|
|
773
|
+
# Clear cached values so set_plan restores defaults
|
|
774
|
+
self._values_cache.pop(self._plan.name, None)
|
|
775
|
+
self.set_plan(self._plan)
|
|
776
|
+
|
|
777
|
+
def _get_plan_file_path(self) -> Path | None:
|
|
778
|
+
"""Get the file path for the current plan.
|
|
779
|
+
|
|
780
|
+
For user plans, retrieves from UserPlanService._loaded_plans.
|
|
781
|
+
For built-in plans, uses inspect.getfile() on the plan function.
|
|
782
|
+
|
|
783
|
+
Returns:
|
|
784
|
+
Path to the plan's source file, or None if not found.
|
|
785
|
+
"""
|
|
786
|
+
if self._plan is None:
|
|
787
|
+
return None
|
|
788
|
+
|
|
789
|
+
# Try user plans first
|
|
790
|
+
from lightfall.acquire.plans.user_plans import UserPlanService
|
|
791
|
+
|
|
792
|
+
service = UserPlanService.get_instance()
|
|
793
|
+
if self._plan.name in service._loaded_plans:
|
|
794
|
+
return service._loaded_plans[self._plan.name]
|
|
795
|
+
|
|
796
|
+
# Fall back to inspect for built-in plans
|
|
797
|
+
try:
|
|
798
|
+
return Path(inspect.getfile(self._plan.func))
|
|
799
|
+
except (TypeError, OSError):
|
|
800
|
+
return None
|
|
801
|
+
|
|
802
|
+
@Slot()
|
|
803
|
+
def _on_edit_clicked(self) -> None:
|
|
804
|
+
"""Open the plan's source file in the configured external editor."""
|
|
805
|
+
from lightfall.ui.preferences.manager import PreferencesManager
|
|
806
|
+
from lightfall.ui.toast import ToastManager
|
|
807
|
+
|
|
808
|
+
if self._plan is None:
|
|
809
|
+
return
|
|
810
|
+
|
|
811
|
+
# Get file path for the plan
|
|
812
|
+
file_path = self._get_plan_file_path()
|
|
813
|
+
if file_path is None:
|
|
814
|
+
toast = ToastManager.get_instance()
|
|
815
|
+
toast.error("Cannot Edit", f"Could not locate source file for plan '{self._plan.name}'")
|
|
816
|
+
return
|
|
817
|
+
|
|
818
|
+
# Get configured editor from preferences
|
|
819
|
+
prefs = PreferencesManager.get_instance()
|
|
820
|
+
editor_str = prefs.get("code_editor", "vscode")
|
|
821
|
+
editor = get_editor_from_string(editor_str)
|
|
822
|
+
|
|
823
|
+
if editor is None:
|
|
824
|
+
editor = CodeEditor.VSCODE # Fallback
|
|
825
|
+
|
|
826
|
+
# Open file at line 1
|
|
827
|
+
success = open_in_editor(str(file_path), 1, editor)
|
|
828
|
+
if not success:
|
|
829
|
+
toast = ToastManager.get_instance()
|
|
830
|
+
toast.error("Editor Error", f"Failed to open '{file_path.name}' in {editor.value}")
|
|
831
|
+
|
|
832
|
+
@Slot()
|
|
833
|
+
def _on_run_clicked(self) -> None:
|
|
834
|
+
"""Handle run button click."""
|
|
835
|
+
if self._plan is None:
|
|
836
|
+
return
|
|
837
|
+
|
|
838
|
+
is_valid, errors = self.validate()
|
|
839
|
+
if not is_valid:
|
|
840
|
+
logger.warning(f"Validation failed: {errors}")
|
|
841
|
+
from lightfall.ui.toast import ToastManager
|
|
842
|
+
toast = ToastManager.get_instance()
|
|
843
|
+
toast.warning("Missing Parameters", "\n".join(errors))
|
|
844
|
+
return
|
|
845
|
+
|
|
846
|
+
kwargs = self.get_kwargs()
|
|
847
|
+
self.run_requested.emit(self._plan, kwargs)
|
|
848
|
+
logger.info(f"Run requested: {self._plan.name} with {kwargs}")
|
|
849
|
+
|
|
850
|
+
@Slot(object, object)
|
|
851
|
+
def _on_param_changed(self, param: Parameter, changes: list) -> None:
|
|
852
|
+
"""Handle parameter value changes.
|
|
853
|
+
|
|
854
|
+
Args:
|
|
855
|
+
param: The root parameter.
|
|
856
|
+
changes: List of changes.
|
|
857
|
+
"""
|
|
858
|
+
self.values_changed.emit(self.get_kwargs())
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
class PlanExecutionWidget(QWidget):
|
|
862
|
+
"""Combined widget for plan selection, configuration, and execution.
|
|
863
|
+
|
|
864
|
+
Combines PlanSelectorWidget and PlanConfigWidget with a Run button
|
|
865
|
+
that executes the plan on the RunEngine.
|
|
866
|
+
|
|
867
|
+
Example:
|
|
868
|
+
>>> from lightfall.acquire import get_run_engine
|
|
869
|
+
>>> from lightfall.acquire.plans import get_registry
|
|
870
|
+
>>> widget = PlanExecutionWidget()
|
|
871
|
+
>>> widget.set_registry(get_registry())
|
|
872
|
+
>>> widget.set_run_engine(get_run_engine())
|
|
873
|
+
"""
|
|
874
|
+
|
|
875
|
+
plan_started = Signal(str) # plan name
|
|
876
|
+
plan_finished = Signal(str, str) # plan name, exit_status
|
|
877
|
+
|
|
878
|
+
def __init__(self, parent: QWidget | None = None) -> None:
|
|
879
|
+
"""Initialize the execution widget.
|
|
880
|
+
|
|
881
|
+
Args:
|
|
882
|
+
parent: Optional parent widget.
|
|
883
|
+
"""
|
|
884
|
+
super().__init__(parent)
|
|
885
|
+
self._re = None
|
|
886
|
+
self._setup_ui()
|
|
887
|
+
|
|
888
|
+
def _setup_ui(self) -> None:
|
|
889
|
+
"""Set up the user interface."""
|
|
890
|
+
from lightfall.ui.widgets.plan_selector import PlanSelectorWidget
|
|
891
|
+
|
|
892
|
+
layout = QHBoxLayout(self)
|
|
893
|
+
|
|
894
|
+
# Plan selector on left
|
|
895
|
+
self._selector = PlanSelectorWidget()
|
|
896
|
+
self._selector.plan_selected.connect(self._on_plan_selected)
|
|
897
|
+
layout.addWidget(self._selector, 1)
|
|
898
|
+
|
|
899
|
+
# Config on right
|
|
900
|
+
self._config = PlanConfigWidget()
|
|
901
|
+
self._config.run_requested.connect(self._on_run_requested)
|
|
902
|
+
layout.addWidget(self._config, 1)
|
|
903
|
+
|
|
904
|
+
def set_registry(self, registry) -> None:
|
|
905
|
+
"""Set the plan registry.
|
|
906
|
+
|
|
907
|
+
Args:
|
|
908
|
+
registry: PlanRegistry instance.
|
|
909
|
+
"""
|
|
910
|
+
self._selector.set_registry(registry)
|
|
911
|
+
|
|
912
|
+
def set_run_engine(self, re) -> None:
|
|
913
|
+
"""Set the RunEngine for execution.
|
|
914
|
+
|
|
915
|
+
Args:
|
|
916
|
+
re: QRunEngine instance.
|
|
917
|
+
"""
|
|
918
|
+
self._re = re
|
|
919
|
+
|
|
920
|
+
@Slot(object)
|
|
921
|
+
def _on_plan_selected(self, plan_info: PlanInfo) -> None:
|
|
922
|
+
"""Handle plan selection.
|
|
923
|
+
|
|
924
|
+
Args:
|
|
925
|
+
plan_info: Selected plan.
|
|
926
|
+
"""
|
|
927
|
+
self._config.set_plan(plan_info)
|
|
928
|
+
|
|
929
|
+
@Slot(object, dict)
|
|
930
|
+
def _on_run_requested(self, plan_info: PlanInfo, kwargs: dict) -> None:
|
|
931
|
+
"""Handle run request.
|
|
932
|
+
|
|
933
|
+
Args:
|
|
934
|
+
plan_info: Plan to run.
|
|
935
|
+
kwargs: Parameter values.
|
|
936
|
+
"""
|
|
937
|
+
if self._re is None:
|
|
938
|
+
logger.error("No RunEngine configured")
|
|
939
|
+
return
|
|
940
|
+
|
|
941
|
+
# TODO: Resolve device names to actual devices from catalog
|
|
942
|
+
# For now, just pass kwargs directly
|
|
943
|
+
|
|
944
|
+
try:
|
|
945
|
+
# Create the plan generator
|
|
946
|
+
plan = plan_info.func(**kwargs)
|
|
947
|
+
|
|
948
|
+
# Submit to RunEngine
|
|
949
|
+
self._re(plan)
|
|
950
|
+
self.plan_started.emit(plan_info.name)
|
|
951
|
+
|
|
952
|
+
logger.info(f"Submitted plan: {plan_info.name}")
|
|
953
|
+
except Exception as e:
|
|
954
|
+
logger.error(f"Failed to run plan {plan_info.name}: {e}")
|