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,379 @@
|
|
|
1
|
+
"""Status bar manager for NCS.
|
|
2
|
+
|
|
3
|
+
Manages the lifecycle of status bar indicator plugins, including
|
|
4
|
+
loading, positioning, and cleanup.
|
|
5
|
+
|
|
6
|
+
All plugin widgets render into a single manager-owned container that
|
|
7
|
+
spans the full width of the ``QStatusBar``. Inside the container, a
|
|
8
|
+
``QHBoxLayout`` holds the "left"-positioned plugins, then a stretch,
|
|
9
|
+
then the "right"/"permanent" plugins. Because the statusbar has only
|
|
10
|
+
one child widget there are no Qt per-item separator notches, and the
|
|
11
|
+
size grip is disabled so the far-right notch goes away too.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from typing import TYPE_CHECKING, Any
|
|
17
|
+
|
|
18
|
+
from PySide6.QtWidgets import QHBoxLayout, QSizePolicy, QSpacerItem, QStatusBar, QWidget
|
|
19
|
+
|
|
20
|
+
from lightfall.utils.logging import logger
|
|
21
|
+
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from lightfall.plugins.info import PluginInfo
|
|
24
|
+
from lightfall.plugins.loader import PluginLoader
|
|
25
|
+
from lightfall.plugins.statusbar_plugin import StatusBarPlugin
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# Spacing between adjacent status bar entries (pixels). Small enough to
|
|
29
|
+
# read as related items, large enough to distinguish them without a glyph.
|
|
30
|
+
ITEM_SPACING_PX = 4
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class StatusBarManager:
|
|
34
|
+
"""Manages status bar indicator plugins.
|
|
35
|
+
|
|
36
|
+
The StatusBarManager handles:
|
|
37
|
+
- Loading plugins from the PluginRegistry
|
|
38
|
+
- Subscribing to PluginLoader signals for dynamic plugin loading
|
|
39
|
+
- Rendering plugin widgets inside a single full-width container so
|
|
40
|
+
Qt's per-item separator notches never appear, and disabling the
|
|
41
|
+
size grip so there's no notch on the far right either
|
|
42
|
+
- Connecting/disconnecting signal handlers
|
|
43
|
+
- Reacting to per-plugin visibility changes
|
|
44
|
+
- Cleanup on shutdown
|
|
45
|
+
|
|
46
|
+
Plugins are positioned by priority (lower = further left). The
|
|
47
|
+
``position`` metadata field decides which side of the central
|
|
48
|
+
stretch they sit on: "left" anchors to the left edge, "right" or
|
|
49
|
+
"permanent" anchors to the right edge.
|
|
50
|
+
|
|
51
|
+
Example:
|
|
52
|
+
>>> statusbar = QStatusBar()
|
|
53
|
+
>>> manager = StatusBarManager(statusbar, parent)
|
|
54
|
+
>>> manager.load_plugins()
|
|
55
|
+
>>> # Later, on cleanup:
|
|
56
|
+
>>> manager.cleanup()
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
def __init__(
|
|
60
|
+
self,
|
|
61
|
+
statusbar: QStatusBar,
|
|
62
|
+
parent: QWidget | None = None,
|
|
63
|
+
) -> None:
|
|
64
|
+
"""Initialize the status bar manager.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
statusbar: The QStatusBar to manage.
|
|
68
|
+
parent: Parent widget (typically the main window).
|
|
69
|
+
"""
|
|
70
|
+
self._statusbar = statusbar
|
|
71
|
+
self._parent = parent
|
|
72
|
+
self._plugins: dict[str, StatusBarPlugin] = {}
|
|
73
|
+
self._widgets: dict[str, QWidget] = {}
|
|
74
|
+
self._sides: dict[str, str] = {} # plugin_id -> "left" | "right"
|
|
75
|
+
self._loader: PluginLoader | None = None
|
|
76
|
+
|
|
77
|
+
# Quench the far-right size-grip notch.
|
|
78
|
+
self._statusbar.setSizeGripEnabled(False)
|
|
79
|
+
|
|
80
|
+
# A single container that spans the whole statusbar. With only one
|
|
81
|
+
# child, the statusbar's per-item frame style never has a chance
|
|
82
|
+
# to draw a notch between items, and there's no left/right boundary
|
|
83
|
+
# frame either.
|
|
84
|
+
self._container = QWidget(self._statusbar)
|
|
85
|
+
self._layout = QHBoxLayout(self._container)
|
|
86
|
+
self._layout.setContentsMargins(0, 0, 0, 0)
|
|
87
|
+
self._layout.setSpacing(ITEM_SPACING_PX)
|
|
88
|
+
# Stretch=1 makes the container fill the full statusbar width so
|
|
89
|
+
# the right-side plugins anchor to the actual right edge.
|
|
90
|
+
self._statusbar.addWidget(self._container, 1)
|
|
91
|
+
|
|
92
|
+
# Center stretch separating left and right plugin groups. Tracks
|
|
93
|
+
# its layout index so insertions on either side stay sorted.
|
|
94
|
+
self._stretch = QSpacerItem(
|
|
95
|
+
0, 0, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum
|
|
96
|
+
)
|
|
97
|
+
self._layout.addSpacerItem(self._stretch)
|
|
98
|
+
|
|
99
|
+
# ------------------------------------------------------------------
|
|
100
|
+
# Helpers
|
|
101
|
+
# ------------------------------------------------------------------
|
|
102
|
+
|
|
103
|
+
def _stretch_index(self) -> int:
|
|
104
|
+
"""Current layout index of the center stretch spacer.
|
|
105
|
+
|
|
106
|
+
We can't store a fixed index because inserts on either side shift
|
|
107
|
+
it; ``indexOf`` is O(n) but n is tiny.
|
|
108
|
+
"""
|
|
109
|
+
return self._layout.indexOf(self._stretch)
|
|
110
|
+
|
|
111
|
+
@staticmethod
|
|
112
|
+
def _side_for(plugin: StatusBarPlugin) -> str:
|
|
113
|
+
"""Map metadata.position to a side key."""
|
|
114
|
+
return "left" if plugin.metadata.position == "left" else "right"
|
|
115
|
+
|
|
116
|
+
def _insert_index(
|
|
117
|
+
self, side: str, priority: int, exclude_id: str | None = None
|
|
118
|
+
) -> int:
|
|
119
|
+
"""Find the layout index to insert a new plugin so the side stays sorted.
|
|
120
|
+
|
|
121
|
+
Lower priority sorts further left within each side. ``exclude_id``
|
|
122
|
+
skips the plugin being inserted if it has already been recorded
|
|
123
|
+
in :attr:`_plugins` / :attr:`_sides`.
|
|
124
|
+
"""
|
|
125
|
+
stretch_idx = self._stretch_index()
|
|
126
|
+
# Count peers on the same side with priority <= ours.
|
|
127
|
+
peers_before = 0
|
|
128
|
+
for pid, sd in self._sides.items():
|
|
129
|
+
if sd != side or pid == exclude_id or pid not in self._plugins:
|
|
130
|
+
continue
|
|
131
|
+
if self._plugins[pid].metadata.priority <= priority:
|
|
132
|
+
peers_before += 1
|
|
133
|
+
if side == "left":
|
|
134
|
+
# Left plugins live in [0, stretch_idx). Place after the peers.
|
|
135
|
+
return peers_before
|
|
136
|
+
# Right plugins live in (stretch_idx, end). Place after the peers.
|
|
137
|
+
return stretch_idx + 1 + peers_before
|
|
138
|
+
|
|
139
|
+
# ------------------------------------------------------------------
|
|
140
|
+
# Loading
|
|
141
|
+
# ------------------------------------------------------------------
|
|
142
|
+
|
|
143
|
+
def load_plugins(self) -> int:
|
|
144
|
+
"""Load status bar plugins from the registry and subscribe to future loads.
|
|
145
|
+
|
|
146
|
+
Discovers all registered statusbar plugins that are already loaded,
|
|
147
|
+
creates their widgets, and adds them to the status bar. Also subscribes
|
|
148
|
+
to the PluginLoader's plugin_loaded signal to handle plugins that load
|
|
149
|
+
later in the background.
|
|
150
|
+
|
|
151
|
+
Returns:
|
|
152
|
+
Number of plugins successfully loaded (already-loaded plugins only).
|
|
153
|
+
"""
|
|
154
|
+
from lightfall.core import LFApplication
|
|
155
|
+
from lightfall.plugins.loader import PluginLoader
|
|
156
|
+
from lightfall.plugins.registry import PluginRegistry
|
|
157
|
+
|
|
158
|
+
app = LFApplication.get_instance()
|
|
159
|
+
services = app.services
|
|
160
|
+
|
|
161
|
+
try:
|
|
162
|
+
self._loader = services.get(PluginLoader)
|
|
163
|
+
self._loader.plugin_loaded.connect(self._on_plugin_loaded)
|
|
164
|
+
logger.debug("Subscribed to PluginLoader.plugin_loaded signal")
|
|
165
|
+
except Exception:
|
|
166
|
+
logger.warning("PluginLoader not available, dynamic loading disabled")
|
|
167
|
+
|
|
168
|
+
try:
|
|
169
|
+
registry = services.get(PluginRegistry)
|
|
170
|
+
except Exception:
|
|
171
|
+
logger.warning("PluginRegistry not available, no status bar plugins loaded")
|
|
172
|
+
return 0
|
|
173
|
+
|
|
174
|
+
loaded = 0
|
|
175
|
+
|
|
176
|
+
plugin_infos = registry.get_by_type("statusbar")
|
|
177
|
+
|
|
178
|
+
sorted_infos = sorted(
|
|
179
|
+
plugin_infos,
|
|
180
|
+
key=lambda info: getattr(
|
|
181
|
+
getattr(info.instance, "metadata", None),
|
|
182
|
+
"priority",
|
|
183
|
+
100,
|
|
184
|
+
)
|
|
185
|
+
if info.instance
|
|
186
|
+
else 100,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
for info in sorted_infos:
|
|
190
|
+
if info.instance is None:
|
|
191
|
+
logger.debug(
|
|
192
|
+
"Statusbar plugin {} not yet instantiated, will load via observer",
|
|
193
|
+
info.unique_id,
|
|
194
|
+
)
|
|
195
|
+
continue
|
|
196
|
+
|
|
197
|
+
plugin = info.instance
|
|
198
|
+
if self.add_plugin(plugin):
|
|
199
|
+
loaded += 1
|
|
200
|
+
|
|
201
|
+
logger.info("Loaded {} status bar plugins (more may load dynamically)", loaded)
|
|
202
|
+
return loaded
|
|
203
|
+
|
|
204
|
+
def _on_plugin_loaded(self, plugin_info: PluginInfo) -> None:
|
|
205
|
+
"""Handle plugin_loaded signal from PluginLoader."""
|
|
206
|
+
if plugin_info.type_name != "statusbar":
|
|
207
|
+
return
|
|
208
|
+
|
|
209
|
+
if plugin_info.instance is None:
|
|
210
|
+
logger.warning(
|
|
211
|
+
"Statusbar plugin {} has no instance, skipping",
|
|
212
|
+
plugin_info.unique_id,
|
|
213
|
+
)
|
|
214
|
+
return
|
|
215
|
+
|
|
216
|
+
plugin_id = plugin_info.instance.metadata.id
|
|
217
|
+
if plugin_id in self._plugins:
|
|
218
|
+
logger.debug("Statusbar plugin {} already added", plugin_id)
|
|
219
|
+
return
|
|
220
|
+
|
|
221
|
+
logger.debug("Adding dynamically loaded statusbar plugin: {}", plugin_id)
|
|
222
|
+
if self.add_plugin(plugin_info.instance):
|
|
223
|
+
logger.info("Dynamically loaded status bar plugin: {}", plugin_id)
|
|
224
|
+
|
|
225
|
+
# ------------------------------------------------------------------
|
|
226
|
+
# Add / remove
|
|
227
|
+
# ------------------------------------------------------------------
|
|
228
|
+
|
|
229
|
+
def add_plugin(self, plugin: StatusBarPlugin) -> bool:
|
|
230
|
+
"""Add a plugin to the status bar.
|
|
231
|
+
|
|
232
|
+
Creates the widget, connects signals, and inserts it into the
|
|
233
|
+
container at the position dictated by side + priority.
|
|
234
|
+
|
|
235
|
+
Args:
|
|
236
|
+
plugin: The StatusBarPlugin instance.
|
|
237
|
+
|
|
238
|
+
Returns:
|
|
239
|
+
True if successfully added.
|
|
240
|
+
"""
|
|
241
|
+
plugin_id = plugin.metadata.id
|
|
242
|
+
|
|
243
|
+
if plugin_id in self._plugins:
|
|
244
|
+
logger.warning("Plugin {} already added to status bar", plugin_id)
|
|
245
|
+
return False
|
|
246
|
+
|
|
247
|
+
try:
|
|
248
|
+
side = self._side_for(plugin)
|
|
249
|
+
|
|
250
|
+
# Track BEFORE create so _insert_index sees the new plugin's
|
|
251
|
+
# bucket consistently if anything calls back during create.
|
|
252
|
+
self._plugins[plugin_id] = plugin
|
|
253
|
+
self._sides[plugin_id] = side
|
|
254
|
+
|
|
255
|
+
widget = plugin.create_widget(self._container)
|
|
256
|
+
# Backward-compat: custom create_widget overrides that don't
|
|
257
|
+
# populate self._widget themselves still get tracked here.
|
|
258
|
+
if plugin.widget is None:
|
|
259
|
+
plugin._widget = widget
|
|
260
|
+
|
|
261
|
+
widget.setVisible(plugin.is_visible)
|
|
262
|
+
|
|
263
|
+
insert_idx = self._insert_index(
|
|
264
|
+
side, plugin.metadata.priority, exclude_id=plugin_id
|
|
265
|
+
)
|
|
266
|
+
self._layout.insertWidget(insert_idx, widget)
|
|
267
|
+
self._widgets[plugin_id] = widget
|
|
268
|
+
|
|
269
|
+
try:
|
|
270
|
+
plugin.visibility_changed.connect(self._on_visibility_changed)
|
|
271
|
+
except (AttributeError, RuntimeError):
|
|
272
|
+
pass
|
|
273
|
+
|
|
274
|
+
plugin.connect_signals()
|
|
275
|
+
plugin.update()
|
|
276
|
+
|
|
277
|
+
logger.debug(
|
|
278
|
+
"Added status bar plugin: {} (priority={}, side={})",
|
|
279
|
+
plugin_id,
|
|
280
|
+
plugin.metadata.priority,
|
|
281
|
+
side,
|
|
282
|
+
)
|
|
283
|
+
return True
|
|
284
|
+
|
|
285
|
+
except Exception as e:
|
|
286
|
+
self._plugins.pop(plugin_id, None)
|
|
287
|
+
self._sides.pop(plugin_id, None)
|
|
288
|
+
self._widgets.pop(plugin_id, None)
|
|
289
|
+
logger.error("Failed to add status bar plugin {}: {}", plugin_id, e)
|
|
290
|
+
return False
|
|
291
|
+
|
|
292
|
+
def remove_plugin(self, plugin_id: str) -> bool:
|
|
293
|
+
"""Remove a plugin from the status bar.
|
|
294
|
+
|
|
295
|
+
Disconnects signals and removes the widget.
|
|
296
|
+
|
|
297
|
+
Args:
|
|
298
|
+
plugin_id: The plugin identifier.
|
|
299
|
+
|
|
300
|
+
Returns:
|
|
301
|
+
True if successfully removed.
|
|
302
|
+
"""
|
|
303
|
+
plugin = self._plugins.pop(plugin_id, None)
|
|
304
|
+
widget = self._widgets.pop(plugin_id, None)
|
|
305
|
+
self._sides.pop(plugin_id, None)
|
|
306
|
+
|
|
307
|
+
if plugin is None:
|
|
308
|
+
return False
|
|
309
|
+
|
|
310
|
+
try:
|
|
311
|
+
try:
|
|
312
|
+
plugin.visibility_changed.disconnect(self._on_visibility_changed)
|
|
313
|
+
except (AttributeError, RuntimeError, TypeError):
|
|
314
|
+
pass
|
|
315
|
+
|
|
316
|
+
plugin.disconnect_signals()
|
|
317
|
+
|
|
318
|
+
if widget is not None:
|
|
319
|
+
self._layout.removeWidget(widget)
|
|
320
|
+
widget.setParent(None)
|
|
321
|
+
widget.deleteLater()
|
|
322
|
+
|
|
323
|
+
logger.debug("Removed status bar plugin: {}", plugin_id)
|
|
324
|
+
return True
|
|
325
|
+
|
|
326
|
+
except Exception as e:
|
|
327
|
+
logger.error("Error removing status bar plugin {}: {}", plugin_id, e)
|
|
328
|
+
return False
|
|
329
|
+
|
|
330
|
+
def _on_visibility_changed(self, _visible: bool) -> None:
|
|
331
|
+
"""Plugin visibility toggled.
|
|
332
|
+
|
|
333
|
+
``QHBoxLayout`` collapses hidden widgets automatically (size
|
|
334
|
+
policy does not retain space when hidden), so the container
|
|
335
|
+
reflows without any manual work. Hook kept for future extension.
|
|
336
|
+
"""
|
|
337
|
+
|
|
338
|
+
# ------------------------------------------------------------------
|
|
339
|
+
# Lifecycle / introspection
|
|
340
|
+
# ------------------------------------------------------------------
|
|
341
|
+
|
|
342
|
+
def cleanup(self) -> None:
|
|
343
|
+
"""Clean up all plugins and disconnect signals.
|
|
344
|
+
|
|
345
|
+
Should be called when the main window is closing.
|
|
346
|
+
"""
|
|
347
|
+
if self._loader is not None:
|
|
348
|
+
try:
|
|
349
|
+
self._loader.plugin_loaded.disconnect(self._on_plugin_loaded)
|
|
350
|
+
logger.debug("Disconnected from PluginLoader.plugin_loaded signal")
|
|
351
|
+
except (RuntimeError, TypeError):
|
|
352
|
+
pass
|
|
353
|
+
self._loader = None
|
|
354
|
+
|
|
355
|
+
for plugin_id in list(self._plugins.keys()):
|
|
356
|
+
self.remove_plugin(plugin_id)
|
|
357
|
+
|
|
358
|
+
logger.debug("Status bar manager cleanup complete")
|
|
359
|
+
|
|
360
|
+
def get_plugin(self, plugin_id: str) -> StatusBarPlugin | None:
|
|
361
|
+
"""Get a plugin by ID."""
|
|
362
|
+
return self._plugins.get(plugin_id)
|
|
363
|
+
|
|
364
|
+
def list_plugins(self) -> list[str]:
|
|
365
|
+
"""List all loaded plugin IDs."""
|
|
366
|
+
return list(self._plugins.keys())
|
|
367
|
+
|
|
368
|
+
def get_introspection_data(self) -> dict[str, Any]:
|
|
369
|
+
"""Get introspection data for MCP tools."""
|
|
370
|
+
return {
|
|
371
|
+
"plugin_count": len(self._plugins),
|
|
372
|
+
"plugins": [
|
|
373
|
+
plugin.get_introspection_data()
|
|
374
|
+
for plugin in sorted(
|
|
375
|
+
self._plugins.values(),
|
|
376
|
+
key=lambda p: p.metadata.priority,
|
|
377
|
+
)
|
|
378
|
+
],
|
|
379
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Built-in status bar plugins for NCS.
|
|
2
|
+
|
|
3
|
+
Provides the default status bar indicators:
|
|
4
|
+
- UserStatusPlugin: Shows current user
|
|
5
|
+
- AuthStatusPlugin: Shows authentication state
|
|
6
|
+
- ConnectionStatusPlugin: Shows online/offline status
|
|
7
|
+
- TiledStatusPlugin: Shows Tiled connection state
|
|
8
|
+
- ALSBeamStatusPlugin: Shows ALS synchrotron beam status
|
|
9
|
+
- ThreadStatusPlugin: Shows background task progress
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from lightfall.ui.statusbar.plugins.als_beam_status import ALSBeamStatusPlugin
|
|
15
|
+
from lightfall.ui.statusbar.plugins.auth_status import AuthStatusPlugin
|
|
16
|
+
from lightfall.ui.statusbar.plugins.connection_status import ConnectionStatusPlugin
|
|
17
|
+
from lightfall.ui.statusbar.plugins.thread_status import ThreadStatusPlugin
|
|
18
|
+
from lightfall.ui.statusbar.plugins.tiled_status import TiledStatusPlugin
|
|
19
|
+
from lightfall.ui.statusbar.plugins.user_status import UserStatusPlugin
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"UserStatusPlugin",
|
|
23
|
+
"AuthStatusPlugin",
|
|
24
|
+
"ConnectionStatusPlugin",
|
|
25
|
+
"TiledStatusPlugin",
|
|
26
|
+
"ALSBeamStatusPlugin",
|
|
27
|
+
"ThreadStatusPlugin",
|
|
28
|
+
]
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"""ALS beam status plugin for NCS status bar.
|
|
2
|
+
|
|
3
|
+
Displays real-time ALS synchrotron beam current, lifetime, and availability.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import TYPE_CHECKING, Any, ClassVar
|
|
9
|
+
|
|
10
|
+
from PySide6.QtCore import QUrl, Slot
|
|
11
|
+
from PySide6.QtGui import QDesktopServices
|
|
12
|
+
|
|
13
|
+
from lightfall.plugins.statusbar_plugin import StatusBarPlugin, StatusBarPluginMetadata
|
|
14
|
+
from lightfall.ui.theme import ThemeManager
|
|
15
|
+
from lightfall.ui.toast import ToastManager
|
|
16
|
+
from lightfall.utils.logging import logger
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from lightfall.services.als_beam_status import ALSBeamData, ALSBeamStatusService
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ALSBeamStatusPlugin(StatusBarPlugin):
|
|
23
|
+
"""Status bar plugin showing ALS beam status.
|
|
24
|
+
|
|
25
|
+
Displays beam current, lifetime, and availability with theme-aware coloring:
|
|
26
|
+
- success: Beam available (shutters open)
|
|
27
|
+
- error: Beam unavailable (shutters closed)
|
|
28
|
+
- text_secondary: Offline/disconnected from API
|
|
29
|
+
|
|
30
|
+
Clicking opens the ALS beam status page.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
metadata: ClassVar[StatusBarPluginMetadata] = StatusBarPluginMetadata(
|
|
34
|
+
id="lightfall.statusbar.als_beam",
|
|
35
|
+
name="ALS Beam Status",
|
|
36
|
+
description="Shows ALS synchrotron beam current and status",
|
|
37
|
+
priority=45,
|
|
38
|
+
position="permanent",
|
|
39
|
+
tooltip="ALS beam status - click for details",
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
BEAM_STATUS_URL = "https://als.lbl.gov/beam-status/"
|
|
43
|
+
|
|
44
|
+
def __init__(self) -> None:
|
|
45
|
+
"""Initialize the ALS beam status plugin."""
|
|
46
|
+
super().__init__()
|
|
47
|
+
self._service: ALSBeamStatusService | None = None
|
|
48
|
+
self._last_beam_available: bool | None = None
|
|
49
|
+
self._theme_manager: ThemeManager | None = None
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def name(self) -> str:
|
|
53
|
+
"""Plugin name."""
|
|
54
|
+
return "als_beam_status"
|
|
55
|
+
|
|
56
|
+
def on_clicked(self) -> None:
|
|
57
|
+
"""Open the ALS beam status page in the default browser."""
|
|
58
|
+
QDesktopServices.openUrl(QUrl(self.BEAM_STATUS_URL))
|
|
59
|
+
|
|
60
|
+
def update(self) -> None:
|
|
61
|
+
"""Update the button with current beam status."""
|
|
62
|
+
if self._theme_manager is None:
|
|
63
|
+
self._theme_manager = ThemeManager.get_instance()
|
|
64
|
+
|
|
65
|
+
try:
|
|
66
|
+
from lightfall.services.als_beam_status import ALSBeamStatusService
|
|
67
|
+
|
|
68
|
+
service = ALSBeamStatusService.get_instance()
|
|
69
|
+
self._service = service
|
|
70
|
+
|
|
71
|
+
if not service.is_polling:
|
|
72
|
+
service.start_polling()
|
|
73
|
+
|
|
74
|
+
if not service.is_connected:
|
|
75
|
+
self._update_display_offline()
|
|
76
|
+
elif service.current_data is not None:
|
|
77
|
+
self._update_display_data(service.current_data)
|
|
78
|
+
else:
|
|
79
|
+
self._update_display_offline()
|
|
80
|
+
|
|
81
|
+
except Exception as e:
|
|
82
|
+
logger.debug("Could not get ALS beam status: {}", e)
|
|
83
|
+
self._update_display_offline()
|
|
84
|
+
|
|
85
|
+
def connect_signals(self) -> None:
|
|
86
|
+
"""Connect to beam status service signals."""
|
|
87
|
+
if self._theme_manager is None:
|
|
88
|
+
self._theme_manager = ThemeManager.get_instance()
|
|
89
|
+
self._theme_manager.colors_changed.connect(self.update)
|
|
90
|
+
|
|
91
|
+
try:
|
|
92
|
+
from lightfall.services.als_beam_status import ALSBeamStatusService
|
|
93
|
+
|
|
94
|
+
service = ALSBeamStatusService.get_instance()
|
|
95
|
+
self._service = service
|
|
96
|
+
service.status_changed.connect(self._on_status_changed)
|
|
97
|
+
service.connection_changed.connect(self._on_connection_changed)
|
|
98
|
+
|
|
99
|
+
except Exception as e:
|
|
100
|
+
logger.debug("Could not connect to ALSBeamStatusService: {}", e)
|
|
101
|
+
|
|
102
|
+
def disconnect_signals(self) -> None:
|
|
103
|
+
"""Disconnect from service signals."""
|
|
104
|
+
if self._service is not None:
|
|
105
|
+
try:
|
|
106
|
+
self._service.status_changed.disconnect(self._on_status_changed)
|
|
107
|
+
self._service.connection_changed.disconnect(self._on_connection_changed)
|
|
108
|
+
except RuntimeError:
|
|
109
|
+
pass
|
|
110
|
+
|
|
111
|
+
if self._theme_manager is not None:
|
|
112
|
+
try:
|
|
113
|
+
self._theme_manager.colors_changed.disconnect(self.update)
|
|
114
|
+
except RuntimeError:
|
|
115
|
+
pass
|
|
116
|
+
|
|
117
|
+
@Slot(object)
|
|
118
|
+
def _on_status_changed(self, data: ALSBeamData) -> None:
|
|
119
|
+
"""Handle beam status update."""
|
|
120
|
+
self._update_display_data(data)
|
|
121
|
+
|
|
122
|
+
@Slot(bool)
|
|
123
|
+
def _on_connection_changed(self, connected: bool) -> None:
|
|
124
|
+
"""Handle connection state change."""
|
|
125
|
+
if not connected:
|
|
126
|
+
self._update_display_offline()
|
|
127
|
+
else:
|
|
128
|
+
self.update()
|
|
129
|
+
|
|
130
|
+
def _update_display_data(self, data: ALSBeamData) -> None:
|
|
131
|
+
"""Update display with beam data; toast on availability change."""
|
|
132
|
+
if (
|
|
133
|
+
self._last_beam_available is not None
|
|
134
|
+
and data.beam_available != self._last_beam_available
|
|
135
|
+
):
|
|
136
|
+
self._notify_status_change(data.beam_available)
|
|
137
|
+
self._last_beam_available = data.beam_available
|
|
138
|
+
|
|
139
|
+
current_str = f"{data.beam_current:.1f} mA"
|
|
140
|
+
lifetime_str = f"{data.lifetime:.1f}h"
|
|
141
|
+
status_str = "Available" if data.beam_available else "Closed"
|
|
142
|
+
|
|
143
|
+
if self._theme_manager is None:
|
|
144
|
+
self._theme_manager = ThemeManager.get_instance()
|
|
145
|
+
colors = self._theme_manager.colors
|
|
146
|
+
color = colors.success if data.beam_available else colors.error
|
|
147
|
+
|
|
148
|
+
self.set_text(f"{current_str} | {lifetime_str} | {status_str}")
|
|
149
|
+
self.set_color(color)
|
|
150
|
+
self.set_tooltip(self._build_tooltip(data))
|
|
151
|
+
|
|
152
|
+
def _notify_status_change(self, beam_available: bool) -> None:
|
|
153
|
+
"""Show a toast notification when ring status changes."""
|
|
154
|
+
toast = ToastManager.get_instance()
|
|
155
|
+
link = f'<a href="{self.BEAM_STATUS_URL}">Beam Status</a>'
|
|
156
|
+
|
|
157
|
+
if beam_available:
|
|
158
|
+
toast.success(
|
|
159
|
+
"ALS Ring Open",
|
|
160
|
+
f"Beam is now available · {link}",
|
|
161
|
+
duration=10000,
|
|
162
|
+
)
|
|
163
|
+
else:
|
|
164
|
+
toast.warning(
|
|
165
|
+
"ALS Ring Closed",
|
|
166
|
+
f"Beam is no longer available · {link}",
|
|
167
|
+
duration=10000,
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
def _update_display_offline(self) -> None:
|
|
171
|
+
"""Update display for offline/error state."""
|
|
172
|
+
if self._theme_manager is None:
|
|
173
|
+
self._theme_manager = ThemeManager.get_instance()
|
|
174
|
+
|
|
175
|
+
self.set_text("Offline")
|
|
176
|
+
self.set_color(self._theme_manager.colors.text_secondary)
|
|
177
|
+
|
|
178
|
+
error_msg = ""
|
|
179
|
+
if self._service and self._service.last_error:
|
|
180
|
+
error_msg = f"\nError: {self._service.last_error}"
|
|
181
|
+
self.set_tooltip(f"ALS beam status unavailable{error_msg}")
|
|
182
|
+
|
|
183
|
+
def _build_tooltip(self, data: ALSBeamData) -> str:
|
|
184
|
+
"""Build detailed tooltip from beam data."""
|
|
185
|
+
lines = [
|
|
186
|
+
"ALS Beam Status",
|
|
187
|
+
"─" * 25,
|
|
188
|
+
f"Current: {data.beam_current:.1f} mA",
|
|
189
|
+
f"Energy: {data.beam_energy:.2f} GeV",
|
|
190
|
+
f"Lifetime: {data.lifetime:.1f} hours",
|
|
191
|
+
f"Status: {'Available' if data.beam_available else 'Shutters Closed'}",
|
|
192
|
+
"",
|
|
193
|
+
f"X RMS: {data.x_rms:.1f} μm",
|
|
194
|
+
f"Y RMS: {data.y_rms:.1f} μm",
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
if data.comment:
|
|
198
|
+
lines.extend(["", "Operations:", data.comment])
|
|
199
|
+
|
|
200
|
+
if data.timestamp:
|
|
201
|
+
lines.extend(["", f"Updated: {data.timestamp.strftime('%H:%M:%S')}"])
|
|
202
|
+
|
|
203
|
+
return "\n".join(lines)
|
|
204
|
+
|
|
205
|
+
def get_introspection_data(self) -> dict[str, Any]:
|
|
206
|
+
"""Get introspection data for MCP tools."""
|
|
207
|
+
data = super().get_introspection_data()
|
|
208
|
+
|
|
209
|
+
try:
|
|
210
|
+
from lightfall.services.als_beam_status import ALSBeamStatusService
|
|
211
|
+
|
|
212
|
+
service = ALSBeamStatusService.get_instance()
|
|
213
|
+
data.update(service.get_introspection_data())
|
|
214
|
+
|
|
215
|
+
except Exception:
|
|
216
|
+
data["als_beam_connected"] = False
|
|
217
|
+
|
|
218
|
+
return data
|