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,301 @@
|
|
|
1
|
+
"""Local override of ``bluesky_tiled_plugins.TiledWriter`` that builds the
|
|
2
|
+
SQL appendable-table schema from the bluesky descriptor's ``data_keys``
|
|
3
|
+
instead of inferring it from ``pyarrow.Table.from_pylist(data_cache)``.
|
|
4
|
+
|
|
5
|
+
Why this exists
|
|
6
|
+
---------------
|
|
7
|
+
|
|
8
|
+
The upstream writer (``bluesky_tiled_plugins.writing.tiled_writer._RunWriter._write_internal_data``)
|
|
9
|
+
materialises the SQL table at first-flush time with a schema inferred
|
|
10
|
+
from whatever ``pyarrow`` decided each column should be, given the
|
|
11
|
+
sample of rows in the first batch. Every subsequent batch is then cast
|
|
12
|
+
to that frozen schema by ``tiled.adapters.sql.append_partition``::
|
|
13
|
+
|
|
14
|
+
table = table.cast(self.structure().arrow_schema_decoded)
|
|
15
|
+
|
|
16
|
+
If the first batch happens to contain integer-looking values for a
|
|
17
|
+
column whose actual stream dtype is float (e.g. a motor at the
|
|
18
|
+
literally-integer ``start`` position emitted before any float-valued
|
|
19
|
+
intermediate position), pyarrow infers ``int64``, and a later
|
|
20
|
+
``-4.5`` raises ``ArrowInvalid: Float value … was truncated converting
|
|
21
|
+
to int64``. Stamina retries 10x, the writer's ``stop`` never reaches
|
|
22
|
+
``update_metadata({"stop": ...})``, and the run on Tiled is left
|
|
23
|
+
``exit_status: "unknown", stop_time: null``.
|
|
24
|
+
|
|
25
|
+
bluesky descriptors already carry ``data_keys[name]["dtype_numpy"]``
|
|
26
|
+
(the upstream code itself populates that field at
|
|
27
|
+
``tiled_writer.RunNormalizer.descriptor`` lines 466-471). Those types
|
|
28
|
+
are authoritative; the writer simply doesn't consult them when building
|
|
29
|
+
the table schema. This subclass closes that gap.
|
|
30
|
+
|
|
31
|
+
This is a workaround until upstream accepts a fix. When updating
|
|
32
|
+
bluesky_tiled_plugins, re-check
|
|
33
|
+
``_RunWriter._write_internal_data`` for upstream changes.
|
|
34
|
+
|
|
35
|
+
Pinned-against version: bluesky_tiled_plugins as of 2026-05.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
from __future__ import annotations
|
|
39
|
+
|
|
40
|
+
import collections.abc
|
|
41
|
+
import copy
|
|
42
|
+
import math
|
|
43
|
+
from typing import Any
|
|
44
|
+
|
|
45
|
+
import numpy
|
|
46
|
+
import pyarrow
|
|
47
|
+
from bluesky_tiled_plugins.writing.tiled_writer import (
|
|
48
|
+
BATCH_SIZE,
|
|
49
|
+
)
|
|
50
|
+
from bluesky_tiled_plugins.writing.tiled_writer import (
|
|
51
|
+
TiledWriter as _UpstreamTiledWriter,
|
|
52
|
+
)
|
|
53
|
+
from bluesky_tiled_plugins.writing.tiled_writer import (
|
|
54
|
+
_RunWriter as _UpstreamRunWriter,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
from lightfall.utils.logging import logger
|
|
58
|
+
|
|
59
|
+
# JSON's exact-integer range. Values outside it are not safe to store: Tiled's
|
|
60
|
+
# PostgreSQL catalog keeps numbers in ``jsonb`` losslessly, but the wire
|
|
61
|
+
# encoders that read them back (msgpack by default, orjson for JSON) are bound
|
|
62
|
+
# to 64 bits, so an oversized integer 500s on read.
|
|
63
|
+
_JSON_INT_MIN = 1 - 2**53
|
|
64
|
+
_JSON_INT_MAX = 2**53 - 1
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def safe_truncate_json_overflow(data: Any) -> Any:
|
|
68
|
+
"""Recursively clamp numbers into the JSON/msgpack-safe integer range.
|
|
69
|
+
|
|
70
|
+
Drop-in replacement for ``bluesky_tiled_plugins``'
|
|
71
|
+
``truncate_json_overflow`` that closes two defects which let un-encodable
|
|
72
|
+
values reach Tiled's catalog and then 500 on every metadata read:
|
|
73
|
+
|
|
74
|
+
* Upstream clamps ``+/-inf`` to the float ``1.7976e308``. That value's
|
|
75
|
+
integer expansion is ~309 digits, so once PostgreSQL stores it as a
|
|
76
|
+
``jsonb`` ``numeric`` and a client reads it back as a Python ``int``,
|
|
77
|
+
neither msgpack nor orjson can encode it. We clamp non-finite and
|
|
78
|
+
out-of-range floats into ``+/-(2**53-1)`` instead (matching how the
|
|
79
|
+
integer path already behaves). Triggered in practice by unbounded EPICS
|
|
80
|
+
axes whose ``*_ctrl_limit`` reads as ``+/-inf``.
|
|
81
|
+
* Upstream only inspects Python ``int``/``float``, so ``numpy`` integer
|
|
82
|
+
scalars (common in ophyd ``configuration`` readings) pass through
|
|
83
|
+
untouched. We coerce ``numpy`` scalars via ``.item()`` first.
|
|
84
|
+
|
|
85
|
+
``NaN`` becomes ``None`` (JSON has no NaN and orjson rejects it); ``bool``
|
|
86
|
+
is preserved; strings, ``None`` and in-range numbers pass through unchanged.
|
|
87
|
+
"""
|
|
88
|
+
if isinstance(data, numpy.generic):
|
|
89
|
+
# numpy scalar -> native Python scalar so the checks below apply
|
|
90
|
+
data = data.item()
|
|
91
|
+
|
|
92
|
+
if isinstance(data, collections.abc.Mapping):
|
|
93
|
+
return {k: safe_truncate_json_overflow(v) for k, v in data.items()}
|
|
94
|
+
if isinstance(data, (list, tuple)):
|
|
95
|
+
return [safe_truncate_json_overflow(item) for item in data]
|
|
96
|
+
|
|
97
|
+
# bool is a subclass of int; never coerce True/False into numbers
|
|
98
|
+
if isinstance(data, bool):
|
|
99
|
+
return data
|
|
100
|
+
|
|
101
|
+
if isinstance(data, int):
|
|
102
|
+
return max(min(data, _JSON_INT_MAX), _JSON_INT_MIN)
|
|
103
|
+
|
|
104
|
+
if isinstance(data, float):
|
|
105
|
+
if math.isnan(data):
|
|
106
|
+
return None
|
|
107
|
+
if not (_JSON_INT_MIN <= data <= _JSON_INT_MAX):
|
|
108
|
+
# Covers +/-inf and any finite magnitude past the safe range.
|
|
109
|
+
return float(max(min(data, _JSON_INT_MAX), _JSON_INT_MIN))
|
|
110
|
+
return data
|
|
111
|
+
|
|
112
|
+
return data
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _install_overflow_patch() -> None:
|
|
116
|
+
"""Point the upstream writer at :func:`safe_truncate_json_overflow`.
|
|
117
|
+
|
|
118
|
+
The inherited ``_RunWriter.descriptor`` / ``start`` / ``stop`` sanitize
|
|
119
|
+
their metadata by calling ``truncate_json_overflow`` resolved from the
|
|
120
|
+
``bluesky_tiled_plugins.writing.tiled_writer`` module namespace, so
|
|
121
|
+
rebinding it there fixes the descriptor ``data_keys`` (where the oversized
|
|
122
|
+
ctrl-limits live) without reimplementing those handlers. Idempotent.
|
|
123
|
+
"""
|
|
124
|
+
import bluesky_tiled_plugins.writing.tiled_writer as _tw
|
|
125
|
+
|
|
126
|
+
if getattr(_tw.truncate_json_overflow, "_lightfall_overflow_safe", False):
|
|
127
|
+
return
|
|
128
|
+
safe_truncate_json_overflow._lightfall_overflow_safe = True # type: ignore[attr-defined]
|
|
129
|
+
_tw.truncate_json_overflow = safe_truncate_json_overflow
|
|
130
|
+
logger.debug(
|
|
131
|
+
"Installed safe truncate_json_overflow on bluesky_tiled_plugins writer"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
_install_overflow_patch()
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _override_schema_from_data_keys(
|
|
139
|
+
inferred_schema: pyarrow.Schema,
|
|
140
|
+
data_keys: dict[str, Any],
|
|
141
|
+
) -> pyarrow.Schema:
|
|
142
|
+
"""Return a copy of ``inferred_schema`` with each field's type replaced by
|
|
143
|
+
the type declared in ``data_keys[field.name]["dtype_numpy"]`` when present.
|
|
144
|
+
|
|
145
|
+
Columns absent from ``data_keys`` (``seq_num``, ``time``, ``ts_*``) keep
|
|
146
|
+
their inferred types. Null and list-of-null columns get the upstream
|
|
147
|
+
string-fallback treatment so empty event streams don't error out.
|
|
148
|
+
"""
|
|
149
|
+
schema = copy.copy(inferred_schema)
|
|
150
|
+
for i, field in enumerate(inferred_schema):
|
|
151
|
+
# Upstream's null-type fallbacks (preserved verbatim — empty columns
|
|
152
|
+
# would otherwise serialize to a Tiled-incompatible all-null type).
|
|
153
|
+
if pyarrow.types.is_null(field.type):
|
|
154
|
+
schema = schema.set(i, field.with_type(pyarrow.string()))
|
|
155
|
+
continue
|
|
156
|
+
if pyarrow.types.is_list(field.type) and pyarrow.types.is_null(
|
|
157
|
+
field.type.value_type
|
|
158
|
+
):
|
|
159
|
+
schema = schema.set(
|
|
160
|
+
i, field.with_type(pyarrow.list_(pyarrow.string()))
|
|
161
|
+
)
|
|
162
|
+
continue
|
|
163
|
+
|
|
164
|
+
col_meta = data_keys.get(field.name)
|
|
165
|
+
if not col_meta:
|
|
166
|
+
continue
|
|
167
|
+
dtype_numpy = col_meta.get("dtype_numpy")
|
|
168
|
+
if not dtype_numpy:
|
|
169
|
+
continue
|
|
170
|
+
|
|
171
|
+
try:
|
|
172
|
+
declared = pyarrow.from_numpy_dtype(numpy.dtype(dtype_numpy))
|
|
173
|
+
except (ValueError, TypeError):
|
|
174
|
+
# Unrecognised dtype string — leave the inferred type alone
|
|
175
|
+
# rather than guess. Logged at debug because some descriptor
|
|
176
|
+
# specs use exotic dtype strings the writer just doesn't model.
|
|
177
|
+
logger.debug(
|
|
178
|
+
"tiled_writer_patch: unrecognised dtype_numpy={!r} for column "
|
|
179
|
+
"{!r}; falling back to inferred type {!s}",
|
|
180
|
+
dtype_numpy, field.name, field.type,
|
|
181
|
+
)
|
|
182
|
+
continue
|
|
183
|
+
|
|
184
|
+
if declared != field.type:
|
|
185
|
+
schema = schema.set(i, field.with_type(declared))
|
|
186
|
+
return schema
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
class _DescribedSchemaRunWriter(_UpstreamRunWriter):
|
|
190
|
+
"""``_RunWriter`` whose internal-table schema honours descriptor dtypes."""
|
|
191
|
+
|
|
192
|
+
def _write_internal_data(
|
|
193
|
+
self,
|
|
194
|
+
data_cache: list[dict[str, Any]],
|
|
195
|
+
desc_node: Any,
|
|
196
|
+
) -> None:
|
|
197
|
+
# Reimplements upstream `_RunWriter._write_internal_data` byte-for-byte
|
|
198
|
+
# except the schema-construction block. Keep this method aligned with
|
|
199
|
+
# upstream when bluesky_tiled_plugins updates.
|
|
200
|
+
desc_name = desc_node.item["id"]
|
|
201
|
+
|
|
202
|
+
# 1. Internal *array* data (zarr) — delegate would be cleaner, but
|
|
203
|
+
# upstream packs everything in one method. Replicate verbatim.
|
|
204
|
+
for key in self._int_array_keys[desc_name]:
|
|
205
|
+
arr_lst = [row.pop(key) for row in data_cache if key in row]
|
|
206
|
+
|
|
207
|
+
min_len, max_len = (
|
|
208
|
+
min(len(row) for row in arr_lst),
|
|
209
|
+
max(len(row) for row in arr_lst),
|
|
210
|
+
)
|
|
211
|
+
if min_len != max_len:
|
|
212
|
+
arr_lst = [
|
|
213
|
+
row + [numpy.nan] * (max_len - len(row)) for row in arr_lst
|
|
214
|
+
]
|
|
215
|
+
msg = (
|
|
216
|
+
f"Array lengths for key '{key}' in stream '{desc_name}' "
|
|
217
|
+
f"are not consistent: min={min_len}, max={max_len}; "
|
|
218
|
+
f"the arrays are padded with NaNs."
|
|
219
|
+
)
|
|
220
|
+
logger.warning(msg)
|
|
221
|
+
self.notes.append(msg)
|
|
222
|
+
|
|
223
|
+
if not (arr_client := self._internal_arrays.get(f"{desc_name}/{key}")):
|
|
224
|
+
metadata = safe_truncate_json_overflow(self.data_keys.get(key, {}))
|
|
225
|
+
arr_client = desc_node.write_array(
|
|
226
|
+
numpy.array(arr_lst),
|
|
227
|
+
key=key,
|
|
228
|
+
metadata=metadata,
|
|
229
|
+
dims=("time", "dim_1"),
|
|
230
|
+
access_tags=self.access_tags,
|
|
231
|
+
)
|
|
232
|
+
self._internal_arrays[f"{desc_name}/{key}"] = arr_client
|
|
233
|
+
self.notes.append(
|
|
234
|
+
f"Internal array data for '{key}' in stream "
|
|
235
|
+
f"'{desc_name}' written as zarr."
|
|
236
|
+
)
|
|
237
|
+
else:
|
|
238
|
+
arr_client.patch(
|
|
239
|
+
numpy.array(arr_lst),
|
|
240
|
+
offset=arr_client.shape[:1],
|
|
241
|
+
extend=True,
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
# 2. Internal *tabular* data — schema construction is the part that
|
|
245
|
+
# diverges from upstream.
|
|
246
|
+
if not (table := pyarrow.Table.from_pylist(data_cache)):
|
|
247
|
+
return
|
|
248
|
+
|
|
249
|
+
if not (df_client := self._internal_tables.get(desc_name)):
|
|
250
|
+
metadata = {
|
|
251
|
+
k: v for k, v in self.data_keys.items() if k in table.column_names
|
|
252
|
+
}
|
|
253
|
+
metadata = safe_truncate_json_overflow(metadata)
|
|
254
|
+
schema = _override_schema_from_data_keys(table.schema, self.data_keys)
|
|
255
|
+
df_client = desc_node.create_appendable_table(
|
|
256
|
+
schema=schema,
|
|
257
|
+
key="internal",
|
|
258
|
+
metadata=metadata,
|
|
259
|
+
access_tags=self.access_tags,
|
|
260
|
+
)
|
|
261
|
+
self._internal_tables[desc_name] = df_client
|
|
262
|
+
|
|
263
|
+
df_client.append_partition(0, table)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
class TiledWriter(_UpstreamTiledWriter):
|
|
267
|
+
"""``TiledWriter`` that uses ``_DescribedSchemaRunWriter`` per run.
|
|
268
|
+
|
|
269
|
+
Drop-in replacement for ``bluesky_tiled_plugins.TiledWriter`` — the only
|
|
270
|
+
behavioural delta is the schema-from-descriptor construction inside
|
|
271
|
+
``_write_internal_data``. All other knobs (``batch_size``,
|
|
272
|
+
``max_array_size``, ``backup_directory``, ``patches``, ``validate``)
|
|
273
|
+
behave identically.
|
|
274
|
+
"""
|
|
275
|
+
|
|
276
|
+
def _factory(self, name: str, doc: dict[str, Any]) -> tuple[list[Any], list[Any]]:
|
|
277
|
+
# Mirrors upstream `TiledWriter._factory` but instantiates our
|
|
278
|
+
# subclass. Keep aligned with upstream.
|
|
279
|
+
from bluesky_tiled_plugins.writing._json_writer import JSONLinesWriter
|
|
280
|
+
from bluesky_tiled_plugins.writing.tiled_writer import _ConditionalBackup
|
|
281
|
+
|
|
282
|
+
cb = run_writer = _DescribedSchemaRunWriter(
|
|
283
|
+
self.client,
|
|
284
|
+
batch_size=self._batch_size,
|
|
285
|
+
max_array_size=self._max_array_size,
|
|
286
|
+
validate=self._validate,
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
if self._normalizer:
|
|
290
|
+
cb = self._normalizer(
|
|
291
|
+
patches=self.patches, spec_to_mimetype=self.spec_to_mimetype
|
|
292
|
+
)
|
|
293
|
+
cb.subscribe(run_writer)
|
|
294
|
+
|
|
295
|
+
if self.backup_directory:
|
|
296
|
+
cb = _ConditionalBackup(cb, [JSONLinesWriter(self.backup_directory)])
|
|
297
|
+
|
|
298
|
+
return [cb], []
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
__all__ = ["TiledWriter", "BATCH_SIZE"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""User-scoped settings (server-backed) for Lightfall."""
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Pure helpers shared across UI code that displays lightfall-logbook image
|
|
2
|
+
artifacts (profile picture, fragment images, etc.).
|
|
3
|
+
|
|
4
|
+
Keep this module dependency-free of QWidget — it must be safe to import
|
|
5
|
+
from worker threads.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import TYPE_CHECKING
|
|
10
|
+
|
|
11
|
+
from PySide6.QtGui import QImage
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from lightfall.settings.user_settings_client import UserSettingsClient
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _fetch_qimage(client: UserSettingsClient, image_id: str) -> QImage:
|
|
18
|
+
"""Download `image_id` via `client` and decode the bytes into a QImage.
|
|
19
|
+
|
|
20
|
+
Designed to run on a worker thread; the returned QImage is
|
|
21
|
+
thread-safe to pass back to the GUI thread (do the QPixmap
|
|
22
|
+
conversion there).
|
|
23
|
+
|
|
24
|
+
Returns a null QImage (image.isNull() == True) on any decode
|
|
25
|
+
failure. HTTP failures propagate as UserSettingsError.
|
|
26
|
+
"""
|
|
27
|
+
data, _content_type = client.download_image(image_id)
|
|
28
|
+
image = QImage()
|
|
29
|
+
image.loadFromData(data)
|
|
30
|
+
return image
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"""Sync HTTP client for the lightfall-logbook /logbook/settings endpoints.
|
|
2
|
+
|
|
3
|
+
Used for user-scoped settings that must follow a user across machines
|
|
4
|
+
(profile picture, future user-level prefs). Local-only preferences
|
|
5
|
+
continue to live in PreferencesManager.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import threading
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
import httpx
|
|
13
|
+
|
|
14
|
+
from lightfall.auth.service_key_auth import ServiceKeyAuth
|
|
15
|
+
from lightfall.logbook.url import get_logbook_base_url
|
|
16
|
+
from lightfall.utils.logging import logger
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
from socksio.exceptions import SOCKSError as _SOCKSError
|
|
20
|
+
except ImportError: # pragma: no cover
|
|
21
|
+
class _SOCKSError(Exception): # type: ignore[no-redef]
|
|
22
|
+
"""Stand-in so the except clauses still parse if socksio isn't installed."""
|
|
23
|
+
|
|
24
|
+
# Transport-level errors that httpx/httpcore don't always wrap.
|
|
25
|
+
# A wedged SOCKS tunnel raises socksio.SOCKSError ("Malformed reply") straight
|
|
26
|
+
# through the call stack instead of as httpx.ProxyError, so we catch both.
|
|
27
|
+
_TRANSPORT_ERRORS: tuple[type[BaseException], ...] = (httpx.HTTPError, _SOCKSError)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _format_transport_error(operation: str, exc: BaseException) -> str:
|
|
31
|
+
if isinstance(exc, (_SOCKSError, httpx.ProxyError)):
|
|
32
|
+
return (
|
|
33
|
+
f"{operation} failed: proxy error ({exc}). "
|
|
34
|
+
f"Check that the SSH tunnel on localhost:1080 is healthy."
|
|
35
|
+
)
|
|
36
|
+
return f"{operation} failed: {exc}"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
_DEFAULT_TIMEOUT = 10.0
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class UserSettingsError(Exception):
|
|
43
|
+
"""Raised on non-2xx response or network failure for set/delete."""
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class UserSettingsClient:
|
|
47
|
+
"""Singleton client for /logbook/settings."""
|
|
48
|
+
|
|
49
|
+
_instance: UserSettingsClient | None = None
|
|
50
|
+
_lock = threading.Lock()
|
|
51
|
+
|
|
52
|
+
def __init__(self, base_url: str | None = None) -> None:
|
|
53
|
+
# base_url=None means "resolve from prefs at call time". This matters
|
|
54
|
+
# because UserSettingsClient is constructed during PreferencesManager
|
|
55
|
+
# bootstrap (manager.py: UserPortableBackend(UserSettingsClient.get_instance())),
|
|
56
|
+
# so a pref read at __init__ time recurses back through a half-built
|
|
57
|
+
# PreferencesManager and silently falls back to DEFAULT_LOGBOOK_URL.
|
|
58
|
+
self._explicit_base_url: str | None = (
|
|
59
|
+
base_url.rstrip("/") if base_url else None
|
|
60
|
+
)
|
|
61
|
+
self._auth = ServiceKeyAuth("logbook")
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def _base_url(self) -> str:
|
|
65
|
+
if self._explicit_base_url is not None:
|
|
66
|
+
return self._explicit_base_url
|
|
67
|
+
return get_logbook_base_url().rstrip("/")
|
|
68
|
+
|
|
69
|
+
# ── Singleton plumbing ───────────────────────────────────────────────
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def init(cls, base_url: str | None = None) -> None:
|
|
73
|
+
"""Initialize the singleton. base_url=None defers URL resolution
|
|
74
|
+
to each request, so the user's logbook_url preference is picked up
|
|
75
|
+
even when this client is constructed before PreferencesManager is
|
|
76
|
+
fully initialised."""
|
|
77
|
+
with cls._lock:
|
|
78
|
+
cls._instance = cls(base_url)
|
|
79
|
+
logger.info(
|
|
80
|
+
"UserSettingsClient initialised (base_url={})",
|
|
81
|
+
base_url or "<lazy from prefs>",
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
@classmethod
|
|
85
|
+
def get_instance(cls) -> UserSettingsClient:
|
|
86
|
+
if cls._instance is None:
|
|
87
|
+
cls.init() # lazy default-init
|
|
88
|
+
assert cls._instance is not None
|
|
89
|
+
return cls._instance
|
|
90
|
+
|
|
91
|
+
@classmethod
|
|
92
|
+
def reset(cls) -> None:
|
|
93
|
+
with cls._lock:
|
|
94
|
+
cls._instance = None
|
|
95
|
+
|
|
96
|
+
# ── Helpers ──────────────────────────────────────────────────────────
|
|
97
|
+
|
|
98
|
+
def _client(self) -> httpx.Client:
|
|
99
|
+
client_kwargs: dict[str, Any] = {
|
|
100
|
+
"base_url": self._base_url,
|
|
101
|
+
"timeout": _DEFAULT_TIMEOUT,
|
|
102
|
+
"auth": self._auth,
|
|
103
|
+
}
|
|
104
|
+
try:
|
|
105
|
+
from lightfall.ui.preferences.proxy_settings import ProxySettingsProvider
|
|
106
|
+
proxy_url = ProxySettingsProvider.should_use_proxy_for_url(self._base_url)
|
|
107
|
+
if proxy_url:
|
|
108
|
+
client_kwargs["proxy"] = proxy_url
|
|
109
|
+
logger.debug("UserSettingsClient using proxy: {}", proxy_url)
|
|
110
|
+
except Exception:
|
|
111
|
+
pass
|
|
112
|
+
return httpx.Client(**client_kwargs)
|
|
113
|
+
|
|
114
|
+
@staticmethod
|
|
115
|
+
def _bl(beamline: str | None) -> str:
|
|
116
|
+
return beamline if beamline is not None else ""
|
|
117
|
+
|
|
118
|
+
# ── Read API ─────────────────────────────────────────────────────────
|
|
119
|
+
|
|
120
|
+
def get(
|
|
121
|
+
self,
|
|
122
|
+
key: str,
|
|
123
|
+
default: Any = None,
|
|
124
|
+
*,
|
|
125
|
+
beamline: str | None = None,
|
|
126
|
+
) -> Any:
|
|
127
|
+
"""Get a single setting value. Returns default on 404/connection error."""
|
|
128
|
+
try:
|
|
129
|
+
with self._client() as c:
|
|
130
|
+
r = c.get(
|
|
131
|
+
f"/logbook/settings/{key}",
|
|
132
|
+
params={"beamline": self._bl(beamline)},
|
|
133
|
+
)
|
|
134
|
+
if r.status_code == 404:
|
|
135
|
+
return default
|
|
136
|
+
r.raise_for_status()
|
|
137
|
+
return r.json()["value"]
|
|
138
|
+
except (*_TRANSPORT_ERRORS, KeyError) as e:
|
|
139
|
+
logger.debug("UserSettingsClient.get({!r}) failed: {}", key, e)
|
|
140
|
+
return default
|
|
141
|
+
|
|
142
|
+
def get_all(self, *, beamline: str | None = None) -> dict[str, Any]:
|
|
143
|
+
"""Return {key: value, ...} for the current user in this scope.
|
|
144
|
+
|
|
145
|
+
Returns empty dict on connection error (graceful degradation)."""
|
|
146
|
+
try:
|
|
147
|
+
with self._client() as c:
|
|
148
|
+
r = c.get(
|
|
149
|
+
"/logbook/settings",
|
|
150
|
+
params={"beamline": self._bl(beamline)},
|
|
151
|
+
)
|
|
152
|
+
r.raise_for_status()
|
|
153
|
+
return r.json()
|
|
154
|
+
except _TRANSPORT_ERRORS as e:
|
|
155
|
+
logger.debug("UserSettingsClient.get_all failed: {}", e)
|
|
156
|
+
return {}
|
|
157
|
+
|
|
158
|
+
# ── Write API ────────────────────────────────────────────────────────
|
|
159
|
+
|
|
160
|
+
def set(
|
|
161
|
+
self,
|
|
162
|
+
key: str,
|
|
163
|
+
value: Any,
|
|
164
|
+
*,
|
|
165
|
+
beamline: str | None = None,
|
|
166
|
+
) -> None:
|
|
167
|
+
"""Upsert a setting. Raises UserSettingsError on failure."""
|
|
168
|
+
body = {"value": value, "beamline": self._bl(beamline)}
|
|
169
|
+
try:
|
|
170
|
+
with self._client() as c:
|
|
171
|
+
r = c.put(f"/logbook/settings/{key}", json=body)
|
|
172
|
+
r.raise_for_status()
|
|
173
|
+
except _TRANSPORT_ERRORS as e:
|
|
174
|
+
raise UserSettingsError(
|
|
175
|
+
_format_transport_error(f"Set setting {key!r}", e)
|
|
176
|
+
) from e
|
|
177
|
+
|
|
178
|
+
def delete(self, key: str, *, beamline: str | None = None) -> None:
|
|
179
|
+
"""Delete a setting. Idempotent — 404 is treated as success.
|
|
180
|
+
Raises UserSettingsError on any other failure."""
|
|
181
|
+
try:
|
|
182
|
+
with self._client() as c:
|
|
183
|
+
r = c.delete(
|
|
184
|
+
f"/logbook/settings/{key}",
|
|
185
|
+
params={"beamline": self._bl(beamline)},
|
|
186
|
+
)
|
|
187
|
+
if r.status_code == 404:
|
|
188
|
+
return # already gone, treat as success
|
|
189
|
+
r.raise_for_status()
|
|
190
|
+
except _TRANSPORT_ERRORS as e:
|
|
191
|
+
raise UserSettingsError(
|
|
192
|
+
_format_transport_error(f"Delete setting {key!r}", e)
|
|
193
|
+
) from e
|
|
194
|
+
|
|
195
|
+
# ── Image helpers ────────────────────────────────────────────────────
|
|
196
|
+
|
|
197
|
+
def upload_image(self, data: bytes, mime_type: str) -> str:
|
|
198
|
+
"""POST bytes to /logbook/images, return image_id."""
|
|
199
|
+
try:
|
|
200
|
+
with self._client() as c:
|
|
201
|
+
r = c.post(
|
|
202
|
+
"/logbook/images",
|
|
203
|
+
files={"file": ("image", data, mime_type)},
|
|
204
|
+
)
|
|
205
|
+
r.raise_for_status()
|
|
206
|
+
return r.json()["image_id"]
|
|
207
|
+
except KeyError as e:
|
|
208
|
+
raise UserSettingsError(
|
|
209
|
+
f"Image upload failed: malformed response (missing {e})"
|
|
210
|
+
) from e
|
|
211
|
+
except _TRANSPORT_ERRORS as e:
|
|
212
|
+
raise UserSettingsError(_format_transport_error("Image upload", e)) from e
|
|
213
|
+
|
|
214
|
+
def download_image(self, image_id: str) -> tuple[bytes, str]:
|
|
215
|
+
"""GET /logbook/images/{id}; return (bytes, content_type).
|
|
216
|
+
|
|
217
|
+
Used by clients that want raw image bytes (e.g., a worker thread
|
|
218
|
+
decoding into a QImage)."""
|
|
219
|
+
try:
|
|
220
|
+
with self._client() as c:
|
|
221
|
+
r = c.get(f"/logbook/images/{image_id}")
|
|
222
|
+
r.raise_for_status()
|
|
223
|
+
return r.content, r.headers.get("content-type", "")
|
|
224
|
+
except _TRANSPORT_ERRORS as e:
|
|
225
|
+
raise UserSettingsError(
|
|
226
|
+
_format_transport_error(f"Image download for {image_id!r}", e)
|
|
227
|
+
) from e
|
|
228
|
+
|
|
229
|
+
def image_url(self, image_id: str) -> str:
|
|
230
|
+
"""Build the absolute URL for an image (e.g., for QPixmap loaders
|
|
231
|
+
that handle their own auth)."""
|
|
232
|
+
return f"{self._base_url}/logbook/images/{image_id}"
|
lightfall/ui/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""User interface components for Lightfall.
|
|
2
|
+
|
|
3
|
+
This package provides:
|
|
4
|
+
- Main window and common UI components
|
|
5
|
+
- Theme management
|
|
6
|
+
- Panel system with progressive disclosure
|
|
7
|
+
- Preferences management
|
|
8
|
+
- Toast notifications
|
|
9
|
+
- Login dialog
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
def __getattr__(name):
|
|
13
|
+
if name == "LoginDialog":
|
|
14
|
+
from lightfall.ui.dialogs import LoginDialog
|
|
15
|
+
return LoginDialog
|
|
16
|
+
if name == "LFMainWindow":
|
|
17
|
+
from lightfall.ui.mainwindow import LFMainWindow
|
|
18
|
+
return LFMainWindow
|
|
19
|
+
if name == "ToastManager":
|
|
20
|
+
from lightfall.ui.toast import ToastManager
|
|
21
|
+
return ToastManager
|
|
22
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"LoginDialog",
|
|
26
|
+
"LFMainWindow",
|
|
27
|
+
"ToastManager",
|
|
28
|
+
]
|