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,170 @@
|
|
|
1
|
+
"""OphydLineEdit — text input for ophyd signal values."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Any, ClassVar
|
|
5
|
+
|
|
6
|
+
from PySide6.QtCore import Property, Signal, Slot
|
|
7
|
+
from PySide6.QtWidgets import QHBoxLayout, QLineEdit, QWidget
|
|
8
|
+
|
|
9
|
+
from lightfall.epics.widgets.ophyd_base import OphydWidget
|
|
10
|
+
from lightfall.epics.widgets.style import WidgetStyles
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class OphydLineEdit(OphydWidget):
|
|
14
|
+
widget_type: ClassVar[str] = "OphydLineEdit"
|
|
15
|
+
widget_description: ClassVar[str] = "Text input for ophyd signal values"
|
|
16
|
+
|
|
17
|
+
editing_finished = Signal()
|
|
18
|
+
value_written = Signal(object)
|
|
19
|
+
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
signal: Any = None,
|
|
23
|
+
parent: QWidget | None = None,
|
|
24
|
+
precision: int = 4,
|
|
25
|
+
show_units: bool = True,
|
|
26
|
+
write_on_enter: bool = True,
|
|
27
|
+
write_on_focus_out: bool = False,
|
|
28
|
+
readonly: bool = False,
|
|
29
|
+
) -> None:
|
|
30
|
+
self._precision = precision
|
|
31
|
+
self._write_on_enter = write_on_enter
|
|
32
|
+
self._write_on_focus_out = write_on_focus_out
|
|
33
|
+
self._modified = False
|
|
34
|
+
|
|
35
|
+
super().__init__(signal, parent, readonly=readonly, show_units=show_units)
|
|
36
|
+
|
|
37
|
+
self._layout = QHBoxLayout(self)
|
|
38
|
+
self._layout.setContentsMargins(0, 0, 0, 0)
|
|
39
|
+
|
|
40
|
+
self._line_edit = QLineEdit()
|
|
41
|
+
self._layout.addWidget(self._line_edit)
|
|
42
|
+
self._layout.addWidget(self._ensure_units_label())
|
|
43
|
+
|
|
44
|
+
self._line_edit.textChanged.connect(self._on_text_changed)
|
|
45
|
+
self._line_edit.returnPressed.connect(self._on_return_pressed)
|
|
46
|
+
self._line_edit.editingFinished.connect(self._on_editing_finished)
|
|
47
|
+
|
|
48
|
+
self._update_readonly_state()
|
|
49
|
+
|
|
50
|
+
@Property(int)
|
|
51
|
+
def precision(self) -> int:
|
|
52
|
+
return self._precision
|
|
53
|
+
|
|
54
|
+
@precision.setter
|
|
55
|
+
def precision(self, value: int) -> None:
|
|
56
|
+
self._precision = value
|
|
57
|
+
self._update_display()
|
|
58
|
+
|
|
59
|
+
@Slot()
|
|
60
|
+
def _apply_value_update(self) -> None:
|
|
61
|
+
# See OphydWidget._apply_value_update — same dead-wrapper guard, repeated
|
|
62
|
+
# here because this override touches self._line_edit before super().
|
|
63
|
+
from lightfall.utils.crash_diagnostics import _is_valid
|
|
64
|
+
if not _is_valid(self) or not _is_valid(self._line_edit):
|
|
65
|
+
return
|
|
66
|
+
if self._modified and self._value is not None:
|
|
67
|
+
try:
|
|
68
|
+
if self._get_widget_value() == self._value:
|
|
69
|
+
self._modified = False
|
|
70
|
+
self._update_modified_style()
|
|
71
|
+
except (ValueError, TypeError):
|
|
72
|
+
pass
|
|
73
|
+
super()._apply_value_update()
|
|
74
|
+
|
|
75
|
+
def _update_display(self) -> None:
|
|
76
|
+
if self._modified:
|
|
77
|
+
return
|
|
78
|
+
if self._value is None:
|
|
79
|
+
self._line_edit.setText("")
|
|
80
|
+
return
|
|
81
|
+
text = self._format_value(self._value)
|
|
82
|
+
self._line_edit.blockSignals(True)
|
|
83
|
+
self._line_edit.setText(text)
|
|
84
|
+
self._line_edit.blockSignals(False)
|
|
85
|
+
|
|
86
|
+
def text(self) -> str:
|
|
87
|
+
"""Return the current text from the inner QLineEdit."""
|
|
88
|
+
return self._line_edit.text()
|
|
89
|
+
|
|
90
|
+
def _get_widget_value(self) -> Any:
|
|
91
|
+
text = self._line_edit.text().strip()
|
|
92
|
+
if self._value is not None:
|
|
93
|
+
try:
|
|
94
|
+
# Check int before float (int is a subclass of numbers but
|
|
95
|
+
# we want to preserve the distinction)
|
|
96
|
+
if isinstance(self._value, int) and not isinstance(self._value, bool):
|
|
97
|
+
return int(text)
|
|
98
|
+
elif isinstance(self._value, float):
|
|
99
|
+
return float(text)
|
|
100
|
+
else:
|
|
101
|
+
# Try numeric conversion for numpy-like types
|
|
102
|
+
float(self._value) # test if original was numeric
|
|
103
|
+
return float(text)
|
|
104
|
+
except (ValueError, TypeError):
|
|
105
|
+
pass
|
|
106
|
+
return text
|
|
107
|
+
|
|
108
|
+
def _set_widget_value(self, value: Any) -> None:
|
|
109
|
+
self._value = value
|
|
110
|
+
self._modified = False
|
|
111
|
+
self._update_display()
|
|
112
|
+
|
|
113
|
+
def _format_value(self, value: Any) -> str:
|
|
114
|
+
if isinstance(value, float):
|
|
115
|
+
return f"{value:.{self._precision}f}"
|
|
116
|
+
if isinstance(value, int):
|
|
117
|
+
return str(value)
|
|
118
|
+
# Fallback: try numeric conversion (catches residual numpy types)
|
|
119
|
+
try:
|
|
120
|
+
return f"{float(value):.{self._precision}f}"
|
|
121
|
+
except (ValueError, TypeError):
|
|
122
|
+
return str(value)
|
|
123
|
+
|
|
124
|
+
def _update_readonly_state(self) -> None:
|
|
125
|
+
self._line_edit.setReadOnly(self._readonly or not self._connected)
|
|
126
|
+
|
|
127
|
+
@Slot()
|
|
128
|
+
def _on_text_changed(self) -> None:
|
|
129
|
+
self._modified = True
|
|
130
|
+
self._update_modified_style()
|
|
131
|
+
|
|
132
|
+
@Slot()
|
|
133
|
+
def _on_return_pressed(self) -> None:
|
|
134
|
+
if self._write_on_enter and self._modified:
|
|
135
|
+
self._write_current_value()
|
|
136
|
+
|
|
137
|
+
@Slot()
|
|
138
|
+
def _on_editing_finished(self) -> None:
|
|
139
|
+
self.editing_finished.emit()
|
|
140
|
+
if self._write_on_focus_out and self._modified:
|
|
141
|
+
self._write_current_value()
|
|
142
|
+
|
|
143
|
+
def _write_current_value(self) -> None:
|
|
144
|
+
if not self._connected or self._readonly:
|
|
145
|
+
return
|
|
146
|
+
try:
|
|
147
|
+
value = self._get_widget_value()
|
|
148
|
+
self.write_value(value)
|
|
149
|
+
self._modified = False
|
|
150
|
+
self._update_modified_style()
|
|
151
|
+
self.value_written.emit(value)
|
|
152
|
+
except Exception:
|
|
153
|
+
self._modified = False
|
|
154
|
+
self._update_display()
|
|
155
|
+
|
|
156
|
+
def _update_modified_style(self) -> None:
|
|
157
|
+
if self._modified:
|
|
158
|
+
self._line_edit.setStyleSheet(WidgetStyles.modified())
|
|
159
|
+
else:
|
|
160
|
+
self._line_edit.setStyleSheet("")
|
|
161
|
+
|
|
162
|
+
def _get_specific_introspection_data(self) -> dict[str, Any]:
|
|
163
|
+
return {
|
|
164
|
+
"precision": self._precision,
|
|
165
|
+
"write_on_enter": self._write_on_enter,
|
|
166
|
+
"write_on_focus_out": self._write_on_focus_out,
|
|
167
|
+
"current_text": self._line_edit.text(),
|
|
168
|
+
"modified": self._modified,
|
|
169
|
+
"editable": not self._readonly and self._connected,
|
|
170
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# src/lightfall/epics/widgets/ophyd_spinbox.py
|
|
2
|
+
"""OphydSpinBox — numeric spin box for ophyd 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 QDoubleSpinBox, QHBoxLayout, QWidget
|
|
9
|
+
|
|
10
|
+
from lightfall.epics.widgets.ophyd_base import OphydWidget
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class OphydSpinBox(OphydWidget):
|
|
14
|
+
widget_type: ClassVar[str] = "OphydSpinBox"
|
|
15
|
+
widget_description: ClassVar[str] = "Spin box for numeric ophyd signal values"
|
|
16
|
+
|
|
17
|
+
value_written = Signal(object)
|
|
18
|
+
|
|
19
|
+
def __init__(
|
|
20
|
+
self,
|
|
21
|
+
signal: Any = None,
|
|
22
|
+
parent: QWidget | None = None,
|
|
23
|
+
minimum: float = -1e6,
|
|
24
|
+
maximum: float = 1e6,
|
|
25
|
+
decimals: int = 1,
|
|
26
|
+
write_on_change: bool = True,
|
|
27
|
+
readonly: bool = False,
|
|
28
|
+
show_units: bool = True,
|
|
29
|
+
) -> None:
|
|
30
|
+
self._write_on_change = write_on_change
|
|
31
|
+
self._updating_from_signal = False
|
|
32
|
+
|
|
33
|
+
super().__init__(signal, parent, readonly=readonly, show_units=show_units)
|
|
34
|
+
|
|
35
|
+
self._layout = QHBoxLayout(self)
|
|
36
|
+
self._layout.setContentsMargins(0, 0, 0, 0)
|
|
37
|
+
|
|
38
|
+
self._spinbox = QDoubleSpinBox()
|
|
39
|
+
self._spinbox.setMinimum(minimum)
|
|
40
|
+
self._spinbox.setMaximum(maximum)
|
|
41
|
+
self._spinbox.setDecimals(decimals)
|
|
42
|
+
self._layout.addWidget(self._spinbox)
|
|
43
|
+
self._layout.addWidget(self._ensure_units_label())
|
|
44
|
+
|
|
45
|
+
self._spinbox.valueChanged.connect(self._on_value_changed)
|
|
46
|
+
|
|
47
|
+
self._update_readonly_state()
|
|
48
|
+
|
|
49
|
+
def _update_display(self) -> None:
|
|
50
|
+
if self._value is None:
|
|
51
|
+
return
|
|
52
|
+
self._updating_from_signal = True
|
|
53
|
+
try:
|
|
54
|
+
self._spinbox.setValue(float(self._value))
|
|
55
|
+
except (ValueError, TypeError):
|
|
56
|
+
pass
|
|
57
|
+
finally:
|
|
58
|
+
self._updating_from_signal = False
|
|
59
|
+
|
|
60
|
+
def _get_widget_value(self) -> float:
|
|
61
|
+
return self._spinbox.value()
|
|
62
|
+
|
|
63
|
+
def _set_widget_value(self, value: Any) -> None:
|
|
64
|
+
self._value = value
|
|
65
|
+
self._update_display()
|
|
66
|
+
|
|
67
|
+
def _update_readonly_state(self) -> None:
|
|
68
|
+
self._spinbox.setReadOnly(self._readonly or not self._connected)
|
|
69
|
+
|
|
70
|
+
@Slot(float)
|
|
71
|
+
def _on_value_changed(self, value: float) -> None:
|
|
72
|
+
if self._updating_from_signal:
|
|
73
|
+
return
|
|
74
|
+
if self._write_on_change and self._connected and not self._readonly:
|
|
75
|
+
try:
|
|
76
|
+
self.write_value(value)
|
|
77
|
+
self.value_written.emit(value)
|
|
78
|
+
except Exception:
|
|
79
|
+
self._update_display()
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PVSlider widget - slider for numeric PV values.
|
|
3
|
+
|
|
4
|
+
Provides visual analog control with configurable range and precision.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any, ClassVar
|
|
10
|
+
|
|
11
|
+
from PySide6.QtCore import Property, Qt, Signal, Slot
|
|
12
|
+
from PySide6.QtWidgets import QHBoxLayout, QLabel, QSlider, QWidget
|
|
13
|
+
|
|
14
|
+
from lightfall.epics.widgets.base import EpicsWidget
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class PVSlider(EpicsWidget):
|
|
18
|
+
"""
|
|
19
|
+
A slider widget for numeric EPICS PV values.
|
|
20
|
+
|
|
21
|
+
Features:
|
|
22
|
+
- Horizontal or vertical orientation
|
|
23
|
+
- Auto-configures range from PV limits
|
|
24
|
+
- Optional value display label
|
|
25
|
+
- Configurable write behavior (on release or continuous)
|
|
26
|
+
|
|
27
|
+
Attributes:
|
|
28
|
+
minimum: Minimum slider value.
|
|
29
|
+
maximum: Maximum slider value.
|
|
30
|
+
show_value: Whether to display current value as text.
|
|
31
|
+
write_on_release: If True, only write when slider is released.
|
|
32
|
+
orientation: Qt.Horizontal or Qt.Vertical.
|
|
33
|
+
|
|
34
|
+
Signals:
|
|
35
|
+
slider_moved: Emitted when slider position changes.
|
|
36
|
+
value_written: Emitted after value is written to PV.
|
|
37
|
+
|
|
38
|
+
Example:
|
|
39
|
+
>>> slider = PVSlider("MY:SETPOINT")
|
|
40
|
+
>>> slider.minimum = 0.0
|
|
41
|
+
>>> slider.maximum = 100.0
|
|
42
|
+
>>> slider.show_value = True
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
widget_type: ClassVar[str] = "PVSlider"
|
|
46
|
+
widget_description: ClassVar[str] = "Slider for analog PV control with range limits"
|
|
47
|
+
|
|
48
|
+
slider_moved = Signal(float)
|
|
49
|
+
value_written = Signal(object)
|
|
50
|
+
|
|
51
|
+
# Slider uses integers internally; we scale by this factor for precision
|
|
52
|
+
_SCALE_FACTOR = 1000
|
|
53
|
+
|
|
54
|
+
def __init__(
|
|
55
|
+
self,
|
|
56
|
+
pv_name: str = "",
|
|
57
|
+
parent: QWidget | None = None,
|
|
58
|
+
minimum: float = 0.0,
|
|
59
|
+
maximum: float = 100.0,
|
|
60
|
+
show_value: bool = True,
|
|
61
|
+
write_on_release: bool = True,
|
|
62
|
+
orientation: Qt.Orientation = Qt.Orientation.Horizontal,
|
|
63
|
+
) -> None:
|
|
64
|
+
"""
|
|
65
|
+
Initialize the PV slider.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
pv_name: The EPICS PV name to connect to.
|
|
69
|
+
parent: Optional Qt parent widget.
|
|
70
|
+
minimum: Minimum value.
|
|
71
|
+
maximum: Maximum value.
|
|
72
|
+
show_value: Whether to show value as text.
|
|
73
|
+
write_on_release: Only write when slider is released.
|
|
74
|
+
orientation: Horizontal or Vertical orientation.
|
|
75
|
+
"""
|
|
76
|
+
self._minimum = minimum
|
|
77
|
+
self._maximum = maximum
|
|
78
|
+
self._show_value = show_value
|
|
79
|
+
self._write_on_release = write_on_release
|
|
80
|
+
self._orientation = orientation
|
|
81
|
+
self._precision: int | None = None
|
|
82
|
+
self._units: str = ""
|
|
83
|
+
self._updating_from_pv = False
|
|
84
|
+
self._pending_write = False
|
|
85
|
+
|
|
86
|
+
super().__init__(pv_name, parent, readonly=False)
|
|
87
|
+
|
|
88
|
+
# Create layout
|
|
89
|
+
self._layout = QHBoxLayout(self)
|
|
90
|
+
self._layout.setContentsMargins(0, 0, 0, 0)
|
|
91
|
+
|
|
92
|
+
# Create slider
|
|
93
|
+
self._slider = QSlider(orientation)
|
|
94
|
+
self._slider.setObjectName("slider")
|
|
95
|
+
self._update_slider_range()
|
|
96
|
+
self._layout.addWidget(self._slider)
|
|
97
|
+
|
|
98
|
+
# Create value label
|
|
99
|
+
self._value_label = QLabel()
|
|
100
|
+
self._value_label.setObjectName("value_label")
|
|
101
|
+
self._value_label.setMinimumWidth(60)
|
|
102
|
+
self._layout.addWidget(self._value_label)
|
|
103
|
+
self._value_label.setVisible(show_value)
|
|
104
|
+
|
|
105
|
+
# Connect signals
|
|
106
|
+
self._slider.valueChanged.connect(self._on_slider_changed)
|
|
107
|
+
self._slider.sliderReleased.connect(self._on_slider_released)
|
|
108
|
+
|
|
109
|
+
# Properties
|
|
110
|
+
|
|
111
|
+
@Property(float)
|
|
112
|
+
def minimum(self) -> float:
|
|
113
|
+
"""Minimum slider value."""
|
|
114
|
+
return self._minimum
|
|
115
|
+
|
|
116
|
+
@minimum.setter
|
|
117
|
+
def minimum(self, value: float) -> None:
|
|
118
|
+
self._minimum = value
|
|
119
|
+
self._update_slider_range()
|
|
120
|
+
|
|
121
|
+
@Property(float)
|
|
122
|
+
def maximum(self) -> float:
|
|
123
|
+
"""Maximum slider value."""
|
|
124
|
+
return self._maximum
|
|
125
|
+
|
|
126
|
+
@maximum.setter
|
|
127
|
+
def maximum(self, value: float) -> None:
|
|
128
|
+
self._maximum = value
|
|
129
|
+
self._update_slider_range()
|
|
130
|
+
|
|
131
|
+
@Property(bool)
|
|
132
|
+
def show_value(self) -> bool:
|
|
133
|
+
"""Whether to display the current value as text."""
|
|
134
|
+
return self._show_value
|
|
135
|
+
|
|
136
|
+
@show_value.setter
|
|
137
|
+
def show_value(self, value: bool) -> None:
|
|
138
|
+
self._show_value = value
|
|
139
|
+
self._value_label.setVisible(value)
|
|
140
|
+
|
|
141
|
+
@Property(bool)
|
|
142
|
+
def write_on_release(self) -> bool:
|
|
143
|
+
"""Whether to only write value when slider is released."""
|
|
144
|
+
return self._write_on_release
|
|
145
|
+
|
|
146
|
+
@write_on_release.setter
|
|
147
|
+
def write_on_release(self, value: bool) -> None:
|
|
148
|
+
self._write_on_release = value
|
|
149
|
+
|
|
150
|
+
# Private methods
|
|
151
|
+
|
|
152
|
+
def _update_slider_range(self) -> None:
|
|
153
|
+
"""Update the internal slider range based on min/max values."""
|
|
154
|
+
self._slider.setMinimum(int(self._minimum * self._SCALE_FACTOR))
|
|
155
|
+
self._slider.setMaximum(int(self._maximum * self._SCALE_FACTOR))
|
|
156
|
+
|
|
157
|
+
def _slider_to_value(self, slider_value: int) -> float:
|
|
158
|
+
"""Convert internal slider value to actual value."""
|
|
159
|
+
return slider_value / self._SCALE_FACTOR
|
|
160
|
+
|
|
161
|
+
def _value_to_slider(self, value: float) -> int:
|
|
162
|
+
"""Convert actual value to internal slider value."""
|
|
163
|
+
return int(value * self._SCALE_FACTOR)
|
|
164
|
+
|
|
165
|
+
def _format_value(self, value: float) -> str:
|
|
166
|
+
"""Format value for display in label."""
|
|
167
|
+
prec = self._precision if self._precision is not None else 2
|
|
168
|
+
text = f"{value:.{prec}f}"
|
|
169
|
+
if self._units:
|
|
170
|
+
text += f" {self._units}"
|
|
171
|
+
return text
|
|
172
|
+
|
|
173
|
+
# Implementation of abstract methods
|
|
174
|
+
|
|
175
|
+
def _update_display(self) -> None:
|
|
176
|
+
"""Update the slider position from the current PV value."""
|
|
177
|
+
if self._value is None:
|
|
178
|
+
return
|
|
179
|
+
|
|
180
|
+
self._updating_from_pv = True
|
|
181
|
+
try:
|
|
182
|
+
value = float(self._value)
|
|
183
|
+
# Clamp to range
|
|
184
|
+
value = max(self._minimum, min(self._maximum, value))
|
|
185
|
+
self._slider.setValue(self._value_to_slider(value))
|
|
186
|
+
self._value_label.setText(self._format_value(value))
|
|
187
|
+
except (ValueError, TypeError):
|
|
188
|
+
pass
|
|
189
|
+
finally:
|
|
190
|
+
self._updating_from_pv = False
|
|
191
|
+
|
|
192
|
+
def _get_widget_value(self) -> float:
|
|
193
|
+
"""Get the current slider value."""
|
|
194
|
+
return self._slider_to_value(self._slider.value())
|
|
195
|
+
|
|
196
|
+
def _set_widget_value(self, value: Any) -> None:
|
|
197
|
+
"""Set the slider position."""
|
|
198
|
+
self._value = value
|
|
199
|
+
self._update_display()
|
|
200
|
+
|
|
201
|
+
def _update_readonly_state(self) -> None:
|
|
202
|
+
"""Update slider enabled state based on readonly property."""
|
|
203
|
+
self._slider.setEnabled(not self._readonly and self._connected)
|
|
204
|
+
|
|
205
|
+
# Event handlers
|
|
206
|
+
|
|
207
|
+
@Slot(int)
|
|
208
|
+
def _on_slider_changed(self, slider_value: int) -> None:
|
|
209
|
+
"""Handle slider value change."""
|
|
210
|
+
if self._updating_from_pv:
|
|
211
|
+
return
|
|
212
|
+
|
|
213
|
+
value = self._slider_to_value(slider_value)
|
|
214
|
+
self._value_label.setText(self._format_value(value))
|
|
215
|
+
self.slider_moved.emit(value)
|
|
216
|
+
|
|
217
|
+
if self._write_on_release:
|
|
218
|
+
self._pending_write = True
|
|
219
|
+
elif self._connected and not self._readonly:
|
|
220
|
+
self._write_to_pv(value)
|
|
221
|
+
|
|
222
|
+
@Slot()
|
|
223
|
+
def _on_slider_released(self) -> None:
|
|
224
|
+
"""Handle slider release."""
|
|
225
|
+
if self._pending_write and self._connected and not self._readonly:
|
|
226
|
+
value = self._get_widget_value()
|
|
227
|
+
self._write_to_pv(value)
|
|
228
|
+
self._pending_write = False
|
|
229
|
+
|
|
230
|
+
def _write_to_pv(self, value: float) -> None:
|
|
231
|
+
"""Write a value to the PV."""
|
|
232
|
+
try:
|
|
233
|
+
self.write_value(value)
|
|
234
|
+
self.value_written.emit(value)
|
|
235
|
+
except Exception:
|
|
236
|
+
# Revert on error
|
|
237
|
+
self._update_display()
|
|
238
|
+
|
|
239
|
+
def _on_pv_metadata_changed(self, metadata: dict[str, Any]) -> None:
|
|
240
|
+
"""Handle metadata changes to update range and precision."""
|
|
241
|
+
super()._on_pv_metadata_changed(metadata)
|
|
242
|
+
|
|
243
|
+
# Update range from control limits
|
|
244
|
+
if "lower_limit" in metadata:
|
|
245
|
+
self._minimum = float(metadata["lower_limit"])
|
|
246
|
+
if "upper_limit" in metadata:
|
|
247
|
+
self._maximum = float(metadata["upper_limit"])
|
|
248
|
+
self._update_slider_range()
|
|
249
|
+
|
|
250
|
+
# Store precision and units
|
|
251
|
+
if "precision" in metadata:
|
|
252
|
+
self._precision = int(metadata["precision"])
|
|
253
|
+
if "units" in metadata:
|
|
254
|
+
self._units = metadata["units"]
|
|
255
|
+
|
|
256
|
+
# Re-display with new formatting
|
|
257
|
+
self._update_display()
|
|
258
|
+
|
|
259
|
+
def _get_specific_introspection_data(self) -> dict[str, Any]:
|
|
260
|
+
"""Get slider-specific introspection data."""
|
|
261
|
+
return {
|
|
262
|
+
"minimum": self._minimum,
|
|
263
|
+
"maximum": self._maximum,
|
|
264
|
+
"current_position": self._get_widget_value(),
|
|
265
|
+
"show_value": self._show_value,
|
|
266
|
+
"displayed_value": self._value_label.text(),
|
|
267
|
+
"write_on_release": self._write_on_release,
|
|
268
|
+
"orientation": "horizontal" if self._orientation == Qt.Orientation.Horizontal else "vertical",
|
|
269
|
+
"precision": self._precision,
|
|
270
|
+
"units": self._units,
|
|
271
|
+
"editable": not self._readonly and self._connected,
|
|
272
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""StatusIndicator -- small circular status dot for connection/alarm state."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from PySide6.QtWidgets import QFrame, QWidget
|
|
5
|
+
|
|
6
|
+
# Fallback colors used when ThemeManager isn't reachable (early init or
|
|
7
|
+
# headless contexts). These match LIGHT_COLORS from lightfall.ui.theme.
|
|
8
|
+
_FALLBACK = {
|
|
9
|
+
"off": "#6b7280",
|
|
10
|
+
"on": "#16a34a",
|
|
11
|
+
"warning": "#d97706",
|
|
12
|
+
"error": "#dc2626",
|
|
13
|
+
"disconnected": "#dc2626",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _state_colors() -> dict[str, str]:
|
|
18
|
+
"""Resolve state -> hex from the active ThemeManager.
|
|
19
|
+
|
|
20
|
+
Pulls the *vivid* status colors (success/warning/error) rather than the
|
|
21
|
+
background-tint variants in ``lightfall.epics.widgets.style`` so the dot
|
|
22
|
+
reads clearly on both light and dark themes.
|
|
23
|
+
"""
|
|
24
|
+
try:
|
|
25
|
+
from lightfall.ui.theme import ThemeManager
|
|
26
|
+
|
|
27
|
+
c = ThemeManager.get_instance().colors
|
|
28
|
+
return {
|
|
29
|
+
"off": c.text_secondary,
|
|
30
|
+
"on": c.success,
|
|
31
|
+
"warning": c.warning,
|
|
32
|
+
"error": c.error,
|
|
33
|
+
"disconnected": c.disconnected or c.error,
|
|
34
|
+
}
|
|
35
|
+
except Exception:
|
|
36
|
+
return dict(_FALLBACK)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class StatusIndicator(QFrame):
|
|
40
|
+
"""A small circular status indicator.
|
|
41
|
+
|
|
42
|
+
States: 'off', 'on', 'warning', 'error', 'disconnected'.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __init__(self, size: int = 14, parent: QWidget | None = None) -> None:
|
|
46
|
+
super().__init__(parent)
|
|
47
|
+
self.setFixedSize(size, size)
|
|
48
|
+
self._state = "off"
|
|
49
|
+
self._radius = size // 2
|
|
50
|
+
self._update_style()
|
|
51
|
+
self._connect_theme_signal()
|
|
52
|
+
|
|
53
|
+
def set_state(self, state: str) -> None:
|
|
54
|
+
"""Set indicator state: 'off', 'on', 'warning', 'error', 'disconnected'."""
|
|
55
|
+
self._state = state
|
|
56
|
+
self._update_style()
|
|
57
|
+
|
|
58
|
+
def set_connected(self, connected: bool) -> None:
|
|
59
|
+
"""Set connected/disconnected state."""
|
|
60
|
+
self.set_state("on" if connected else "error")
|
|
61
|
+
|
|
62
|
+
def set_color(self, color: str) -> None:
|
|
63
|
+
"""Set a custom color directly (bypasses theme resolution)."""
|
|
64
|
+
self.setStyleSheet(f"""
|
|
65
|
+
QFrame {{
|
|
66
|
+
background-color: {color};
|
|
67
|
+
border-radius: {self._radius}px;
|
|
68
|
+
border: 1px solid #333;
|
|
69
|
+
}}
|
|
70
|
+
""")
|
|
71
|
+
|
|
72
|
+
def _update_style(self) -> None:
|
|
73
|
+
colors = _state_colors()
|
|
74
|
+
color = colors.get(self._state, colors["off"])
|
|
75
|
+
self.setStyleSheet(f"""
|
|
76
|
+
QFrame {{
|
|
77
|
+
background-color: {color};
|
|
78
|
+
border-radius: {self._radius}px;
|
|
79
|
+
border: 1px solid #333;
|
|
80
|
+
}}
|
|
81
|
+
""")
|
|
82
|
+
|
|
83
|
+
def _connect_theme_signal(self) -> None:
|
|
84
|
+
try:
|
|
85
|
+
from lightfall.ui.theme import ThemeManager
|
|
86
|
+
|
|
87
|
+
ThemeManager.get_instance().colors_changed.connect(self._update_style)
|
|
88
|
+
except Exception:
|
|
89
|
+
pass
|
|
90
|
+
|
|
91
|
+
def closeEvent(self, event) -> None: # type: ignore[override]
|
|
92
|
+
try:
|
|
93
|
+
from lightfall.ui.theme import ThemeManager
|
|
94
|
+
|
|
95
|
+
ThemeManager.get_instance().colors_changed.disconnect(self._update_style)
|
|
96
|
+
except Exception:
|
|
97
|
+
pass
|
|
98
|
+
super().closeEvent(event)
|