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,469 @@
|
|
|
1
|
+
"""Base class for ophyd signal widgets.
|
|
2
|
+
|
|
3
|
+
Parallel to EpicsWidget (which wraps caproto PVs), this base class
|
|
4
|
+
wraps ophyd signals -- providing subscription, thread-safe UI updates,
|
|
5
|
+
and a uniform interface for widgets that control ophyd devices.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import inspect
|
|
10
|
+
from abc import abstractmethod
|
|
11
|
+
from typing import Any, ClassVar
|
|
12
|
+
|
|
13
|
+
from PySide6.QtCore import Property, QEvent, QTimer, Signal, Slot
|
|
14
|
+
from PySide6.QtWidgets import QLabel, QWidget
|
|
15
|
+
|
|
16
|
+
from lightfall.epics.widgets.style import WidgetStyles
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class OphydWidget(QWidget):
|
|
20
|
+
"""Abstract base class for widgets bound to ophyd signals.
|
|
21
|
+
|
|
22
|
+
This class provides:
|
|
23
|
+
- Automatic signal subscription management
|
|
24
|
+
- Thread-safe UI updates via invoke_in_main_thread
|
|
25
|
+
- Polling fallback if subscription fails
|
|
26
|
+
- Consistent styling for connection states
|
|
27
|
+
- Introspection API matching EpicsWidget
|
|
28
|
+
|
|
29
|
+
Subclasses must implement:
|
|
30
|
+
- _update_display(): Update the widget from the current value
|
|
31
|
+
- _get_widget_value(): Get the current value from the widget UI
|
|
32
|
+
- _set_widget_value(): Set the widget to display a specific value
|
|
33
|
+
|
|
34
|
+
Signals:
|
|
35
|
+
value_changed: Emitted when the displayed value changes.
|
|
36
|
+
connection_changed: Emitted when connection state changes.
|
|
37
|
+
|
|
38
|
+
Class Attributes:
|
|
39
|
+
widget_type: A human-readable type name for introspection.
|
|
40
|
+
widget_description: A description of what this widget does.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
widget_type: ClassVar[str] = "OphydWidget"
|
|
44
|
+
widget_description: ClassVar[str] = "Base class for ophyd signal widgets"
|
|
45
|
+
|
|
46
|
+
value_changed = Signal(object)
|
|
47
|
+
connection_changed = Signal(bool)
|
|
48
|
+
|
|
49
|
+
def __init__(
|
|
50
|
+
self,
|
|
51
|
+
signal: Any = None,
|
|
52
|
+
parent: QWidget | None = None,
|
|
53
|
+
readonly: bool = False,
|
|
54
|
+
show_units: bool = True,
|
|
55
|
+
) -> None:
|
|
56
|
+
super().__init__(parent)
|
|
57
|
+
self._signal: Any = None
|
|
58
|
+
self._sub_id: int | None = None
|
|
59
|
+
self._readonly = readonly
|
|
60
|
+
self._value: Any = None
|
|
61
|
+
self._connected = False
|
|
62
|
+
self._poll_timer: QTimer | None = None
|
|
63
|
+
|
|
64
|
+
# Units display — the QLabel is lazily created; subclasses call
|
|
65
|
+
# ``_ensure_units_label()`` and add the returned widget to their
|
|
66
|
+
# own layout if they want units shown alongside the value.
|
|
67
|
+
self._show_units = show_units
|
|
68
|
+
self._units: str = ""
|
|
69
|
+
self._units_label: QLabel | None = None
|
|
70
|
+
|
|
71
|
+
# Apply base styling
|
|
72
|
+
self._update_connection_style()
|
|
73
|
+
|
|
74
|
+
if signal is not None:
|
|
75
|
+
self.signal = signal
|
|
76
|
+
|
|
77
|
+
# -- Qt Properties --------------------------------------------------------
|
|
78
|
+
|
|
79
|
+
@Property(bool)
|
|
80
|
+
def readonly(self) -> bool:
|
|
81
|
+
"""Whether this widget is read-only."""
|
|
82
|
+
return self._readonly
|
|
83
|
+
|
|
84
|
+
@readonly.setter
|
|
85
|
+
def readonly(self, value: bool) -> None:
|
|
86
|
+
self._readonly = value
|
|
87
|
+
self._update_readonly_state()
|
|
88
|
+
|
|
89
|
+
@Property(bool, notify=connection_changed)
|
|
90
|
+
def connected(self) -> bool:
|
|
91
|
+
"""Whether the signal is currently connected."""
|
|
92
|
+
return self._connected
|
|
93
|
+
|
|
94
|
+
@Property(bool)
|
|
95
|
+
def show_units(self) -> bool:
|
|
96
|
+
"""Whether to display units next to the value."""
|
|
97
|
+
return self._show_units
|
|
98
|
+
|
|
99
|
+
@show_units.setter
|
|
100
|
+
def show_units(self, value: bool) -> None:
|
|
101
|
+
self._show_units = value
|
|
102
|
+
if self._units_label is not None:
|
|
103
|
+
self._units_label.setVisible(value and bool(self._units))
|
|
104
|
+
|
|
105
|
+
def _ensure_units_label(self) -> QLabel:
|
|
106
|
+
"""Return the units QLabel, creating it on first access.
|
|
107
|
+
|
|
108
|
+
Subclasses call this during layout construction and add the
|
|
109
|
+
returned label to their own layout. The label is created hidden
|
|
110
|
+
and becomes visible once a non-empty units string is fetched.
|
|
111
|
+
"""
|
|
112
|
+
if self._units_label is None:
|
|
113
|
+
self._units_label = QLabel()
|
|
114
|
+
self._units_label.setObjectName("units_label")
|
|
115
|
+
self._units_label.setVisible(False)
|
|
116
|
+
return self._units_label
|
|
117
|
+
|
|
118
|
+
# -- Signal binding -------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
@property
|
|
121
|
+
def signal(self) -> Any:
|
|
122
|
+
"""The ophyd signal this widget is bound to."""
|
|
123
|
+
return self._signal
|
|
124
|
+
|
|
125
|
+
@signal.setter
|
|
126
|
+
def signal(self, sig: Any) -> None:
|
|
127
|
+
self._disconnect_signal()
|
|
128
|
+
self._signal = sig
|
|
129
|
+
self.setToolTip(self._signal_display_name(sig))
|
|
130
|
+
if sig is not None:
|
|
131
|
+
self._connect_signal()
|
|
132
|
+
|
|
133
|
+
@staticmethod
|
|
134
|
+
def _signal_display_name(sig: Any) -> str:
|
|
135
|
+
"""Return the PV name for an EPICS-backed signal, falling back to the
|
|
136
|
+
ophyd dotted name for simulated/soft signals that have no PV.
|
|
137
|
+
"""
|
|
138
|
+
if sig is None:
|
|
139
|
+
return ""
|
|
140
|
+
pvname = getattr(sig, "pvname", None)
|
|
141
|
+
if isinstance(pvname, str) and pvname:
|
|
142
|
+
return pvname
|
|
143
|
+
# ``source`` is defined on every ophyd Signal — for EPICS it is
|
|
144
|
+
# ``PV:<pvname>``; for sim signals it is ``SIM:<name>`` etc.
|
|
145
|
+
source = getattr(sig, "source", None)
|
|
146
|
+
if isinstance(source, str) and source:
|
|
147
|
+
return source[3:] if source.startswith("PV:") else source
|
|
148
|
+
name = getattr(sig, "name", "")
|
|
149
|
+
return name if isinstance(name, str) else ""
|
|
150
|
+
|
|
151
|
+
# -- Tooltip forwarding ---------------------------------------------------
|
|
152
|
+
#
|
|
153
|
+
# Qt shows a widget's tooltip only when that specific widget is hovered;
|
|
154
|
+
# children (the inner QLabel, QLineEdit, QDoubleSpinBox...) sit on top
|
|
155
|
+
# and do NOT reliably propagate ToolTip events up to us. We install
|
|
156
|
+
# ourselves as an event filter on every child so that any ToolTip event
|
|
157
|
+
# on a child whose own tooltip is empty is answered with our PV tooltip.
|
|
158
|
+
|
|
159
|
+
def childEvent(self, event: Any) -> None:
|
|
160
|
+
super().childEvent(event)
|
|
161
|
+
if event.type() == QEvent.Type.ChildAdded:
|
|
162
|
+
child = event.child()
|
|
163
|
+
if isinstance(child, QWidget):
|
|
164
|
+
child.installEventFilter(self)
|
|
165
|
+
|
|
166
|
+
def eventFilter(self, obj: Any, event: Any) -> bool:
|
|
167
|
+
if (
|
|
168
|
+
event.type() == QEvent.Type.ToolTip
|
|
169
|
+
and isinstance(obj, QWidget)
|
|
170
|
+
and obj is not self
|
|
171
|
+
and not obj.toolTip()
|
|
172
|
+
):
|
|
173
|
+
tip = self.toolTip()
|
|
174
|
+
if tip:
|
|
175
|
+
from PySide6.QtWidgets import QToolTip
|
|
176
|
+
|
|
177
|
+
try:
|
|
178
|
+
pos = event.globalPos()
|
|
179
|
+
except AttributeError:
|
|
180
|
+
pos = event.globalPosition().toPoint()
|
|
181
|
+
QToolTip.showText(pos, tip, obj)
|
|
182
|
+
return True
|
|
183
|
+
return super().eventFilter(obj, event)
|
|
184
|
+
|
|
185
|
+
def _connect_signal(self) -> None:
|
|
186
|
+
"""Subscribe to the ophyd signal and read the initial value."""
|
|
187
|
+
if self._signal is None:
|
|
188
|
+
return
|
|
189
|
+
|
|
190
|
+
# Determine connection state
|
|
191
|
+
if hasattr(self._signal, "connected"):
|
|
192
|
+
self._connected = bool(self._signal.connected)
|
|
193
|
+
else:
|
|
194
|
+
self._connected = True
|
|
195
|
+
self._update_connection_style()
|
|
196
|
+
self._update_readonly_state()
|
|
197
|
+
self.connection_changed.emit(self._connected)
|
|
198
|
+
|
|
199
|
+
# Subscribe for value updates
|
|
200
|
+
try:
|
|
201
|
+
self._sub_id = self._signal.subscribe(self._on_signal_value)
|
|
202
|
+
except Exception:
|
|
203
|
+
self._start_polling()
|
|
204
|
+
|
|
205
|
+
# Read current value
|
|
206
|
+
self._read_initial_value()
|
|
207
|
+
|
|
208
|
+
# Pull engineering units from the signal (best-effort)
|
|
209
|
+
self._fetch_units()
|
|
210
|
+
|
|
211
|
+
def _fetch_units(self) -> None:
|
|
212
|
+
"""Extract engineering units from the ophyd signal.
|
|
213
|
+
|
|
214
|
+
Checks ``signal.metadata["units"]`` first, then falls back to
|
|
215
|
+
``signal.describe()`` which some signal types populate lazily.
|
|
216
|
+
The result is stored in ``self._units`` and applied to
|
|
217
|
+
``self._units_label`` if a subclass has created one.
|
|
218
|
+
"""
|
|
219
|
+
if self._signal is None:
|
|
220
|
+
return
|
|
221
|
+
units = ""
|
|
222
|
+
try:
|
|
223
|
+
meta = getattr(self._signal, "metadata", None)
|
|
224
|
+
if isinstance(meta, dict):
|
|
225
|
+
units = meta.get("units", "") or ""
|
|
226
|
+
if not units and hasattr(self._signal, "describe"):
|
|
227
|
+
desc = self._signal.describe()
|
|
228
|
+
if inspect.isawaitable(desc):
|
|
229
|
+
desc = None
|
|
230
|
+
if desc:
|
|
231
|
+
for _key, info in desc.items():
|
|
232
|
+
if isinstance(info, dict):
|
|
233
|
+
units = info.get("units", "") or ""
|
|
234
|
+
if units:
|
|
235
|
+
break
|
|
236
|
+
except Exception:
|
|
237
|
+
units = ""
|
|
238
|
+
self._units = units
|
|
239
|
+
if self._units_label is not None:
|
|
240
|
+
self._units_label.setText(units)
|
|
241
|
+
self._units_label.setVisible(self._show_units and bool(units))
|
|
242
|
+
|
|
243
|
+
def _disconnect_signal(self) -> None:
|
|
244
|
+
"""Unsubscribe and release the ophyd signal."""
|
|
245
|
+
self._stop_polling()
|
|
246
|
+
if self._signal is not None and self._sub_id is not None:
|
|
247
|
+
try:
|
|
248
|
+
self._signal.unsubscribe(self._sub_id)
|
|
249
|
+
except Exception:
|
|
250
|
+
pass
|
|
251
|
+
self._sub_id = None
|
|
252
|
+
self._signal = None
|
|
253
|
+
self._connected = False
|
|
254
|
+
self._update_connection_style()
|
|
255
|
+
self._update_readonly_state()
|
|
256
|
+
|
|
257
|
+
# Clear units display so it doesn't stick around after rebinding.
|
|
258
|
+
self._units = ""
|
|
259
|
+
if self._units_label is not None:
|
|
260
|
+
self._units_label.setText("")
|
|
261
|
+
self._units_label.setVisible(False)
|
|
262
|
+
|
|
263
|
+
# -- Value updates --------------------------------------------------------
|
|
264
|
+
|
|
265
|
+
@staticmethod
|
|
266
|
+
def _coerce_scalar(value: Any) -> Any:
|
|
267
|
+
"""Extract a Python scalar from numpy/array-like/namedtuple values.
|
|
268
|
+
|
|
269
|
+
Ophyd callbacks and ``.get()`` can deliver numpy scalars,
|
|
270
|
+
single-element arrays, or named tuples (e.g. SynGaussTuple).
|
|
271
|
+
Coerce them to plain Python types so that ``isinstance`` checks
|
|
272
|
+
and ``str()`` behave predictably in downstream formatting.
|
|
273
|
+
"""
|
|
274
|
+
if value is None:
|
|
275
|
+
return None
|
|
276
|
+
|
|
277
|
+
# Named tuples from simulated devices (e.g. SynGaussTuple) —
|
|
278
|
+
# extract the first field which holds the actual value.
|
|
279
|
+
if hasattr(value, "_fields") and value._fields:
|
|
280
|
+
value = getattr(value, value._fields[0])
|
|
281
|
+
|
|
282
|
+
# bytes from EPICS string PVs → decode
|
|
283
|
+
if isinstance(value, bytes):
|
|
284
|
+
return value.decode("utf-8", errors="replace")
|
|
285
|
+
|
|
286
|
+
# Single-element sequences → extract scalar
|
|
287
|
+
if hasattr(value, "__len__") and not isinstance(value, str):
|
|
288
|
+
try:
|
|
289
|
+
if len(value) == 1:
|
|
290
|
+
value = value[0]
|
|
291
|
+
except TypeError:
|
|
292
|
+
# 0-d numpy array: ndim == 0, has __len__ but len() raises
|
|
293
|
+
pass
|
|
294
|
+
|
|
295
|
+
# numpy scalar → native Python type
|
|
296
|
+
if hasattr(value, "item"):
|
|
297
|
+
try:
|
|
298
|
+
value = value.item()
|
|
299
|
+
except (ValueError, AttributeError):
|
|
300
|
+
pass
|
|
301
|
+
|
|
302
|
+
return value
|
|
303
|
+
|
|
304
|
+
def _on_signal_value(self, value: Any = None, **kwargs: Any) -> None:
|
|
305
|
+
"""Ophyd subscription callback -- runs on a background thread."""
|
|
306
|
+
from lightfall.utils.threads import invoke_in_main_thread
|
|
307
|
+
|
|
308
|
+
self._value = self._coerce_scalar(value)
|
|
309
|
+
invoke_in_main_thread(self._apply_value_update)
|
|
310
|
+
|
|
311
|
+
@Slot()
|
|
312
|
+
def _apply_value_update(self) -> None:
|
|
313
|
+
"""Apply the latest value on the Qt main thread."""
|
|
314
|
+
# A queued _InvokeEvent can outlive the underlying C++ widget (e.g. parent
|
|
315
|
+
# destroyed between post and dispatch), keeping this Python wrapper alive
|
|
316
|
+
# while child widgets touched by _update_display() are already gone.
|
|
317
|
+
from lightfall.utils.crash_diagnostics import _is_valid
|
|
318
|
+
if not _is_valid(self):
|
|
319
|
+
return
|
|
320
|
+
self._update_display()
|
|
321
|
+
self.value_changed.emit(self._value)
|
|
322
|
+
|
|
323
|
+
def _read_initial_value(self) -> None:
|
|
324
|
+
"""Read the current signal value synchronously."""
|
|
325
|
+
if self._signal is None:
|
|
326
|
+
return
|
|
327
|
+
try:
|
|
328
|
+
val = self._signal.get()
|
|
329
|
+
if inspect.isawaitable(val):
|
|
330
|
+
return # async signals are not read synchronously
|
|
331
|
+
self._value = self._coerce_scalar(val)
|
|
332
|
+
self._update_display()
|
|
333
|
+
self.value_changed.emit(self._value)
|
|
334
|
+
except Exception:
|
|
335
|
+
pass
|
|
336
|
+
|
|
337
|
+
# -- Polling fallback -----------------------------------------------------
|
|
338
|
+
|
|
339
|
+
def _start_polling(self) -> None:
|
|
340
|
+
"""Start a 500 ms poll timer (fallback when subscribe fails)."""
|
|
341
|
+
if self._poll_timer is None:
|
|
342
|
+
self._poll_timer = QTimer(self)
|
|
343
|
+
self._poll_timer.timeout.connect(self._poll_value)
|
|
344
|
+
self._poll_timer.start(500)
|
|
345
|
+
|
|
346
|
+
def _stop_polling(self) -> None:
|
|
347
|
+
"""Stop the poll timer if running."""
|
|
348
|
+
if self._poll_timer is not None:
|
|
349
|
+
self._poll_timer.stop()
|
|
350
|
+
|
|
351
|
+
@Slot()
|
|
352
|
+
def _poll_value(self) -> None:
|
|
353
|
+
"""Timer callback: re-read the signal value."""
|
|
354
|
+
self._read_initial_value()
|
|
355
|
+
|
|
356
|
+
# -- Writing --------------------------------------------------------------
|
|
357
|
+
|
|
358
|
+
def write_value(self, value: Any | None = None) -> None:
|
|
359
|
+
"""Write a value to the ophyd signal.
|
|
360
|
+
|
|
361
|
+
Args:
|
|
362
|
+
value: The value to write. If None, uses the current widget value.
|
|
363
|
+
|
|
364
|
+
Raises:
|
|
365
|
+
RuntimeError: If the widget is readonly or signal is not connected.
|
|
366
|
+
"""
|
|
367
|
+
if self._readonly:
|
|
368
|
+
raise RuntimeError("Widget is readonly")
|
|
369
|
+
if self._signal is None or not self._connected:
|
|
370
|
+
raise RuntimeError("Signal is not connected")
|
|
371
|
+
|
|
372
|
+
if value is None:
|
|
373
|
+
value = self._get_widget_value()
|
|
374
|
+
|
|
375
|
+
if hasattr(self._signal, "put"):
|
|
376
|
+
result = self._signal.put(value)
|
|
377
|
+
if inspect.isawaitable(result):
|
|
378
|
+
import asyncio
|
|
379
|
+
import threading
|
|
380
|
+
|
|
381
|
+
def _run() -> None:
|
|
382
|
+
loop = asyncio.new_event_loop()
|
|
383
|
+
try:
|
|
384
|
+
loop.run_until_complete(result)
|
|
385
|
+
finally:
|
|
386
|
+
loop.close()
|
|
387
|
+
|
|
388
|
+
threading.Thread(target=_run, daemon=True).start()
|
|
389
|
+
elif hasattr(self._signal, "set"):
|
|
390
|
+
self._signal.set(value)
|
|
391
|
+
|
|
392
|
+
# -- Styling --------------------------------------------------------------
|
|
393
|
+
|
|
394
|
+
def _update_connection_style(self) -> None:
|
|
395
|
+
"""Update widget styling based on connection state."""
|
|
396
|
+
if self._connected:
|
|
397
|
+
self.setStyleSheet(WidgetStyles.connected())
|
|
398
|
+
else:
|
|
399
|
+
self.setStyleSheet(WidgetStyles.disconnected())
|
|
400
|
+
|
|
401
|
+
def _update_readonly_state(self) -> None:
|
|
402
|
+
"""Update widget state for readonly changes. Override in subclasses."""
|
|
403
|
+
pass
|
|
404
|
+
|
|
405
|
+
# -- Abstract interface ---------------------------------------------------
|
|
406
|
+
|
|
407
|
+
@abstractmethod
|
|
408
|
+
def _update_display(self) -> None:
|
|
409
|
+
"""Update the widget display to reflect the current signal value."""
|
|
410
|
+
pass
|
|
411
|
+
|
|
412
|
+
@abstractmethod
|
|
413
|
+
def _get_widget_value(self) -> Any:
|
|
414
|
+
"""Get the current value from the widget's UI."""
|
|
415
|
+
pass
|
|
416
|
+
|
|
417
|
+
@abstractmethod
|
|
418
|
+
def _set_widget_value(self, value: Any) -> None:
|
|
419
|
+
"""Set the widget's UI to display a specific value."""
|
|
420
|
+
pass
|
|
421
|
+
|
|
422
|
+
# -- Introspection --------------------------------------------------------
|
|
423
|
+
|
|
424
|
+
def get_introspection_data(self) -> dict[str, Any]:
|
|
425
|
+
"""Get comprehensive introspection data for this widget."""
|
|
426
|
+
data = {
|
|
427
|
+
"widget_type": self.widget_type,
|
|
428
|
+
"widget_description": self.widget_description,
|
|
429
|
+
"object_name": self.objectName(),
|
|
430
|
+
"class_name": self.__class__.__name__,
|
|
431
|
+
"signal_name": getattr(self._signal, "name", None),
|
|
432
|
+
"connected": self._connected,
|
|
433
|
+
"current_value": self._value,
|
|
434
|
+
"value_type": type(self._value).__name__ if self._value is not None else None,
|
|
435
|
+
"units": self._units,
|
|
436
|
+
"show_units": self._show_units,
|
|
437
|
+
"readonly": self._readonly,
|
|
438
|
+
"enabled": self.isEnabled(),
|
|
439
|
+
"visible": self.isVisible(),
|
|
440
|
+
"geometry": {
|
|
441
|
+
"x": self.x(),
|
|
442
|
+
"y": self.y(),
|
|
443
|
+
"width": self.width(),
|
|
444
|
+
"height": self.height(),
|
|
445
|
+
},
|
|
446
|
+
}
|
|
447
|
+
data.update(self._get_specific_introspection_data())
|
|
448
|
+
return data
|
|
449
|
+
|
|
450
|
+
def _get_specific_introspection_data(self) -> dict[str, Any]:
|
|
451
|
+
"""Override in subclasses for widget-specific introspection."""
|
|
452
|
+
return {}
|
|
453
|
+
|
|
454
|
+
@classmethod
|
|
455
|
+
def get_class_introspection_data(cls) -> dict[str, Any]:
|
|
456
|
+
"""Get class-level introspection data."""
|
|
457
|
+
return {
|
|
458
|
+
"widget_type": cls.widget_type,
|
|
459
|
+
"widget_description": cls.widget_description,
|
|
460
|
+
"class_name": cls.__name__,
|
|
461
|
+
"module": cls.__module__,
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
# -- Lifecycle ------------------------------------------------------------
|
|
465
|
+
|
|
466
|
+
def closeEvent(self, event: Any) -> None:
|
|
467
|
+
"""Clean up signal subscription on close."""
|
|
468
|
+
self._disconnect_signal()
|
|
469
|
+
super().closeEvent(event)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# src/lightfall/epics/widgets/ophyd_combobox.py
|
|
2
|
+
"""OphydComboBox — dropdown for ophyd enum signal values."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, ClassVar
|
|
6
|
+
|
|
7
|
+
from PySide6.QtCore import Signal, Slot
|
|
8
|
+
from PySide6.QtWidgets import QComboBox, QHBoxLayout, QWidget
|
|
9
|
+
|
|
10
|
+
from lightfall.epics.widgets.ophyd_base import OphydWidget
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class OphydComboBox(OphydWidget):
|
|
14
|
+
widget_type: ClassVar[str] = "OphydComboBox"
|
|
15
|
+
widget_description: ClassVar[str] = "Dropdown for ophyd enum signal values"
|
|
16
|
+
|
|
17
|
+
selection_changed = Signal(int, str)
|
|
18
|
+
value_written = Signal(object)
|
|
19
|
+
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
signal: Any = None,
|
|
23
|
+
parent: QWidget | None = None,
|
|
24
|
+
write_on_change: bool = True,
|
|
25
|
+
readonly: bool = False,
|
|
26
|
+
show_units: bool = True,
|
|
27
|
+
) -> None:
|
|
28
|
+
self._write_on_change = write_on_change
|
|
29
|
+
self._updating_from_signal = False
|
|
30
|
+
|
|
31
|
+
super().__init__(signal, parent, readonly=readonly, show_units=show_units)
|
|
32
|
+
|
|
33
|
+
self._layout = QHBoxLayout(self)
|
|
34
|
+
self._layout.setContentsMargins(0, 0, 0, 0)
|
|
35
|
+
|
|
36
|
+
self._combo = QComboBox()
|
|
37
|
+
self._layout.addWidget(self._combo)
|
|
38
|
+
self._layout.addWidget(self._ensure_units_label())
|
|
39
|
+
|
|
40
|
+
self._combo.currentIndexChanged.connect(self._on_index_changed)
|
|
41
|
+
|
|
42
|
+
self._update_readonly_state()
|
|
43
|
+
|
|
44
|
+
def set_items(self, items: list[str]) -> None:
|
|
45
|
+
self._combo.clear()
|
|
46
|
+
for i, text in enumerate(items):
|
|
47
|
+
self._combo.addItem(text, i)
|
|
48
|
+
|
|
49
|
+
def _update_display(self) -> None:
|
|
50
|
+
if self._value is None:
|
|
51
|
+
return
|
|
52
|
+
self._updating_from_signal = True
|
|
53
|
+
try:
|
|
54
|
+
index = int(self._value)
|
|
55
|
+
if 0 <= index < self._combo.count():
|
|
56
|
+
self._combo.setCurrentIndex(index)
|
|
57
|
+
except (ValueError, TypeError):
|
|
58
|
+
text = str(self._value)
|
|
59
|
+
index = self._combo.findText(text)
|
|
60
|
+
if index >= 0:
|
|
61
|
+
self._combo.setCurrentIndex(index)
|
|
62
|
+
finally:
|
|
63
|
+
self._updating_from_signal = False
|
|
64
|
+
|
|
65
|
+
def _get_widget_value(self) -> Any:
|
|
66
|
+
return self._combo.currentIndex()
|
|
67
|
+
|
|
68
|
+
def _set_widget_value(self, value: Any) -> None:
|
|
69
|
+
self._value = value
|
|
70
|
+
self._update_display()
|
|
71
|
+
|
|
72
|
+
def _update_readonly_state(self) -> None:
|
|
73
|
+
self._combo.setEnabled(not self._readonly and self._connected)
|
|
74
|
+
|
|
75
|
+
@Slot(int)
|
|
76
|
+
def _on_index_changed(self, index: int) -> None:
|
|
77
|
+
if self._updating_from_signal:
|
|
78
|
+
return
|
|
79
|
+
text = self._combo.currentText()
|
|
80
|
+
self.selection_changed.emit(index, text)
|
|
81
|
+
if self._write_on_change and self._connected and not self._readonly:
|
|
82
|
+
try:
|
|
83
|
+
self.write_value(index)
|
|
84
|
+
self.value_written.emit(index)
|
|
85
|
+
except Exception:
|
|
86
|
+
self._update_display()
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""OphydLabel — read-only display for ophyd signal values."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Any, ClassVar
|
|
5
|
+
|
|
6
|
+
from PySide6.QtWidgets import QHBoxLayout, QLabel, QWidget
|
|
7
|
+
|
|
8
|
+
from lightfall.epics.widgets.ophyd_base import OphydWidget
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class OphydLabel(OphydWidget):
|
|
12
|
+
widget_type: ClassVar[str] = "OphydLabel"
|
|
13
|
+
widget_description: ClassVar[str] = "Read-only label for ophyd signal values"
|
|
14
|
+
|
|
15
|
+
def __init__(
|
|
16
|
+
self,
|
|
17
|
+
signal: Any = None,
|
|
18
|
+
parent: QWidget | None = None,
|
|
19
|
+
precision: int = 4,
|
|
20
|
+
show_units: bool = True,
|
|
21
|
+
) -> None:
|
|
22
|
+
self._precision = precision
|
|
23
|
+
super().__init__(signal, parent, readonly=True, show_units=show_units)
|
|
24
|
+
|
|
25
|
+
self._layout = QHBoxLayout(self)
|
|
26
|
+
self._layout.setContentsMargins(0, 0, 0, 0)
|
|
27
|
+
|
|
28
|
+
self._value_label = QLabel("---")
|
|
29
|
+
self._layout.addWidget(self._value_label)
|
|
30
|
+
self._layout.addWidget(self._ensure_units_label())
|
|
31
|
+
|
|
32
|
+
def _update_display(self) -> None:
|
|
33
|
+
if self._value is None:
|
|
34
|
+
self._value_label.setText("---")
|
|
35
|
+
return
|
|
36
|
+
self._value_label.setText(self._format_value(self._value))
|
|
37
|
+
|
|
38
|
+
def _format_value(self, value: Any) -> str:
|
|
39
|
+
if isinstance(value, float):
|
|
40
|
+
return f"{value:.{self._precision}f}"
|
|
41
|
+
if isinstance(value, int):
|
|
42
|
+
return str(value)
|
|
43
|
+
# Fallback: try numeric conversion (catches residual numpy types)
|
|
44
|
+
try:
|
|
45
|
+
return f"{float(value):.{self._precision}f}"
|
|
46
|
+
except (ValueError, TypeError):
|
|
47
|
+
return str(value)
|
|
48
|
+
|
|
49
|
+
def _get_widget_value(self) -> Any:
|
|
50
|
+
return self._value
|
|
51
|
+
|
|
52
|
+
def _set_widget_value(self, value: Any) -> None:
|
|
53
|
+
self._value = value
|
|
54
|
+
self._update_display()
|