From ced8f72529233140a3edc3c27dc1ea121f0e81c1 Mon Sep 17 00:00:00 2001 From: x10sa Date: Mon, 2 Nov 2026 11:37:00 +0100 Subject: [PATCH 01/10] WIP: copy everything from aare bec proto --- pxii_bec/device_configs/pxii-devices.yaml | 8 +- pxii_bec/devices/__init__.py | 4 + pxii_bec/devices/aerotech.py | 43 ------ pxii_bec/devices/http.py | 178 ---------------------- pxii_bec/devices/smargopolo_smargon.py | 42 ----- pyproject.toml | 6 + tests/tests_devices/test_aerotech.py | 2 +- 7 files changed, 17 insertions(+), 266 deletions(-) delete mode 100644 pxii_bec/devices/aerotech.py delete mode 100644 pxii_bec/devices/http.py delete mode 100644 pxii_bec/devices/smargopolo_smargon.py diff --git a/pxii_bec/device_configs/pxii-devices.yaml b/pxii_bec/device_configs/pxii-devices.yaml index d653a2e..57171f7 100755 --- a/pxii_bec/device_configs/pxii-devices.yaml +++ b/pxii_bec/device_configs/pxii-devices.yaml @@ -51,9 +51,13 @@ aerotech: description: REST-based device which connects to AareScan and Aerotech - deviceClass: pxii_bec.devices.aerotech.Aerotech + deviceClass: pxii_bec.devices.Aerotech deviceConfig: prefix: http://mx-x10sa-queue-01:5234 + vel_u_deg_s: 5 + vel_x_mm_s: 0.1 + vel_y_mm_s: 0.1 + vel_z_mm_s: 0.1 deviceTags: - aerotech - motors @@ -1440,7 +1444,7 @@ sls_current: readoutPriority: monitored smargon: description: REST-based device which connects to Smargopolo - deviceClass: pxii_bec.devices.smargopolo_smargon.Smargon + deviceClass: pxii_bec.devices.Smargon deviceConfig: prefix: http://x10sa-smargopolo.psi.ch:3000 deviceTags: diff --git a/pxii_bec/devices/__init__.py b/pxii_bec/devices/__init__.py index e69de29..fb194d7 100644 --- a/pxii_bec/devices/__init__.py +++ b/pxii_bec/devices/__init__.py @@ -0,0 +1,4 @@ +from mx_bec.devices.aerotech import Aerotech +from mx_bec.devices.smargopolo_smargon import Smargon + +__all__ = ["Aerotech", "Smargon"] diff --git a/pxii_bec/devices/aerotech.py b/pxii_bec/devices/aerotech.py deleted file mode 100644 index 9bd38b0..0000000 --- a/pxii_bec/devices/aerotech.py +++ /dev/null @@ -1,43 +0,0 @@ -from ophyd import Component as Cpt - -from .http import TIMESTAMP_ID, HttpDeviceController, HttpDeviceSignal, HttpOphydDevice - - -class AerotechController(HttpDeviceController): - _readback_endpoint = "/status" - _target_endpoint = "/position" - - def __init__(self, *, prefix, **kwargs): - self._readbacks: dict[str, dict[str, float | bool]] = {} - super().__init__(prefix=prefix, **kwargs) - - def put(self, axis: str, val: float): - self._rest_post(body={axis: val}) - - def get_readback(self, axis_id: str) -> tuple[float, float] | None: - with self._readback_lock: - if axis_id not in self._readbacks or TIMESTAMP_ID not in self._readbacks: - return None - return self._readbacks.get(axis_id)["pos"], self._readbacks.get(TIMESTAMP_ID) # type: ignore - - -class Aerotech(HttpOphydDevice): - controller_class = AerotechController - - x = Cpt(HttpDeviceSignal, axis_identifier="x", tolerance=0.01) - y = Cpt(HttpDeviceSignal, axis_identifier="y", tolerance=0.01) - z = Cpt(HttpDeviceSignal, axis_identifier="z", tolerance=0.01) - u = Cpt(HttpDeviceSignal, axis_identifier="u", tolerance=0.01) - vel_u_deg_s = Cpt(HttpDeviceSignal, axis_identifier="vel_u_deg_s", tolerance=0.01) - - -def _test(): - a = Aerotech(name="aerotech", prefix="http://mx-x10sa-queue-01:5234") - a.wait_for_connection() - return a - - -if __name__ == "__main__": - aerotech = _test() - print(aerotech.read()) - aerotech.stop() diff --git a/pxii_bec/devices/http.py b/pxii_bec/devices/http.py deleted file mode 100644 index 38b612a..0000000 --- a/pxii_bec/devices/http.py +++ /dev/null @@ -1,178 +0,0 @@ -import time -from abc import ABC, abstractmethod -from threading import Event, RLock, Thread -from typing import Any - -from ophyd import OphydObject -from ophyd_devices import PSIDeviceBase -from ophyd_devices.utils.socket import SocketSignal -from requests import Response, Session - -TIMESTAMP_ID = "__timestamp" -_POLL_INTERVAL_SLOW = 0.1 - - -class HttpRestError(Exception): - """Error for rest calls from a HttpRestSignal.""" - - def __init__(self, resp: Response, *args: object, value: Any | None = None) -> None: - method, url = resp.request.method, resp.request.url - data = f"{str(value)} to " if value is not None else "" - super().__init__( - f"Could not {method} {data}{url}. Code: {resp.status_code}. Reason: {resp.reason}.", - *args, - ) - - -class HttpDeviceController(OphydObject, ABC): - """Controller to consolidate polling loops and other REST calls for devices which communicate - with HTTP REST interfaces""" - - _readback_endpoint: str - _target_endpoint: str - - def __init__(self, *, prefix, **kwargs): - self._readbacks: dict - self._session = Session() - self._prefix = prefix - self._targets = {} - self._signal_registry: set[str] = set() - self._readback_poll_interval: float = _POLL_INTERVAL_SLOW - - super().__init__(**kwargs) - self._setup_readback() - - def _setup_readback(self): - self._stop_monitor_readback_event = Event() - self._readback_lock = RLock() - self._monitor_readback_thread = Thread( - target=self._monitor, - args=[ - self._readback_endpoint, - self._stop_monitor_readback_event, - self._readback_lock, - self._readbacks, - ], - ) - - def manual_update(self): - self._update_reading(self._readback_endpoint, self._readback_lock, self._readbacks) - - def _update_reading(self, endpoint: str, lock: RLock, buffer: dict): - data = self._rest_get(endpoint) - timestamp = time.monotonic() - with lock: - buffer.update(data) - buffer["__timestamp"] = timestamp - - def _monitor(self, endpoint: str, event: Event, lock: RLock, buffer: dict): - while not event.is_set(): - self._update_reading(endpoint, lock, buffer) - time.sleep(self._readback_poll_interval) - - def _clean_monitor(self): - if self._monitor_readback_thread.is_alive(): - self._stop_monitor_readback_event.set() - self._monitor_readback_thread.join(timeout=2) - if self._monitor_readback_thread.is_alive(): - raise RuntimeError("Failed to clean up Aerotech monitor thread.") - - def register(self, axis_id: str): - self._signal_registry.add(axis_id) - - def _rest_get(self, endpoint): - resp = self._session.get(self._prefix + endpoint) - if not resp.ok: - raise HttpRestError(resp) - return resp.json() - - def _rest_put(self, params: dict | None = None, body: dict | None = None): - resp = self._session.put(self._prefix + self._target_endpoint, params=params, json=body) - if not resp.ok: - raise HttpRestError(resp, value=params) - - def _rest_post(self, params: dict | None = None, body: dict | None = None): - resp = self._session.post(self._prefix + self._target_endpoint, params=params, json=body) - if not resp.ok: - raise HttpRestError(resp, value=params) - - def start_monitor(self): - """Start or restart the automonitor thread.""" - self._clean_monitor() - self._setup_readback() - self._monitor_readback_thread.start() - - def monitor_stopped(self): - return not self._monitor_readback_thread.is_alive() - - def put(self, axis: str, val: float): - self._rest_put({axis: val}) - - @abstractmethod - def get_readback(self, axis_id: str) -> tuple[float, float] | None: - """Return a tuple (reading, timestamp) if the axis_id exists""" - - def stop(self): - # There doesn't appear to be a stop endpoint on the server - # Best effort: set the target to the current position - pass - # TODO: self._rest_put(self._readbacks) - - -class HttpDeviceSignal(SocketSignal): - """Ophyd signal which gets and puts to a REST API rather than EPICS PVs, mediated through the Aerotech - Controller""" - - def __init__(self, *args, axis_identifier: str, **kwargs): - super().__init__(*args, **kwargs) - controller: HttpDeviceController | None = getattr(self.root, "controller", None) - if controller is None: - raise TypeError("HttpDeviceSignal must be used in a device with a HttpDeviceController") - self._controller = controller - self._axis_id = axis_identifier - self._controller.register(self._axis_id) - - def _socket_get(self): # type: ignore - self._readback, self.metadata["timestamp"] = self._controller.get_readback( - self._axis_id - ) or (0.0, 0.0) - return self._readback - - def _socket_set(self, val: float): - self._controller.put(self._axis_id, val) - - def get(self, **kwargs): - if self._controller.monitor_stopped(): - self._controller.start_monitor() - return super().get(**kwargs) - - -class HttpOphydDevice(PSIDeviceBase): - controller_class: type[HttpDeviceController] - - def __init__( - self, - *, - name: str, - prefix: str = "", - scan_info=None, - device_manager=None, - **kwargs, - ): - self.controller = self.controller_class(prefix=prefix) - super().__init__( - name=name, - prefix=prefix, - scan_info=scan_info, - device_manager=device_manager, - **kwargs, - ) - - def wait_for_connection(self, **kwargs): # type: ignore - self.controller.start_monitor() - self.controller.manual_update() - return super().wait_for_connection(**kwargs) - - def stop(self, *, success: bool = False) -> None: - self.controller.stop() - return super().stop(success=success) diff --git a/pxii_bec/devices/smargopolo_smargon.py b/pxii_bec/devices/smargopolo_smargon.py deleted file mode 100644 index a7c4618..0000000 --- a/pxii_bec/devices/smargopolo_smargon.py +++ /dev/null @@ -1,42 +0,0 @@ -from ophyd import Component as Cpt -from ophyd_devices import PSIDeviceBase - -from .http import HttpDeviceController, HttpDeviceSignal, HttpOphydDevice - -_TIMESTAMP_ID = "__timestamp" -_POLL_INTERVAL_SLOW = 0.1 - - -class SmargonController(HttpDeviceController): - """Controller to consolidate polling loops and other REST calls for the smargon""" - - _readback_endpoint = "/readbackSCS" - _target_endpoint = "/targetSCS" - - def __init__(self, *, prefix, **kwargs): - self._readbacks: dict[str, float] = {} - super().__init__(prefix=prefix, **kwargs) - - def get_readback(self, axis_id: str) -> tuple[float, float] | None: - with self._readback_lock: - if axis_id not in self._readbacks or _TIMESTAMP_ID not in self._readbacks: - return None - return self._readbacks.get(axis_id), self._readbacks.get(_TIMESTAMP_ID) # type: ignore - - def put(self, axis: str, val: float): - self._rest_put(params={axis: val}) - - def stop(self): - # There doesn't appear to be a stop endpoint on the server - # Best effort: set the target to the current position - self._rest_put(params=self._readbacks) - - -class Smargon(HttpOphydDevice): - controller_class = SmargonController - - x = Cpt(HttpDeviceSignal, axis_identifier="SHX", tolerance=0.01) - y = Cpt(HttpDeviceSignal, axis_identifier="SHY", tolerance=0.01) - z = Cpt(HttpDeviceSignal, axis_identifier="SHZ", tolerance=0.01) - phi = Cpt(HttpDeviceSignal, axis_identifier="PHI", tolerance=0.01) - chi = Cpt(HttpDeviceSignal, axis_identifier="CHI", tolerance=0.01) diff --git a/pyproject.toml b/pyproject.toml index 2229991..eaec104 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,6 +59,12 @@ plugin_widgets_update = "pxii_bec.bec_widgets.auto_updates" [project.entry-points."bec.widgets.user_widgets"] plugin_widgets = "pxii_bec.bec_widgets.widgets" +[project.entry-points."bec.messages"] +plugin_scans = "pxii_bec.messages" + +[project.entry-points."bec.bl_states"] +plugin_scans = "pxii_bec.states" + [tool.hatch.build.targets.wheel] include = ["*"] diff --git a/tests/tests_devices/test_aerotech.py b/tests/tests_devices/test_aerotech.py index 49e2fc2..3cf76f5 100644 --- a/tests/tests_devices/test_aerotech.py +++ b/tests/tests_devices/test_aerotech.py @@ -30,7 +30,7 @@ class MockServer: @pytest.fixture def aerotech(): mock_server = MockServer() - from pxii_bec.devices.aerotech import Aerotech + from pxii_bec.devices import Aerotech s = Aerotech(name="aerotech", prefix="http://test-aerotech.psi.ch") s.controller._rest_get = mock_server.get -- 2.54.1 From 496cb9a62d58ea2825a6e9c1f22a389247ff58c6 Mon Sep 17 00:00:00 2001 From: x10sa Date: Mon, 2 Nov 2026 14:42:37 +0100 Subject: [PATCH 02/10] WIP start adding control widgets --- pxii_bec/bec_widgets/widgets/__init__.py | 3 + pxii_bec/bec_widgets/widgets/client.py | 11 ++++ .../bec_widgets/widgets/designer_plugins.py | 2 + pxii_bec/bec_widgets/widgets/imported.py | 4 ++ .../px_ii_actor_config_wiget.pyproject | 1 + .../px_ii_actor_config_wiget_plugin.py | 57 +++++++++++++++++++ .../register_px_ii_actor_config_wiget.py | 15 +++++ 7 files changed, 93 insertions(+) create mode 100644 pxii_bec/bec_widgets/widgets/imported.py create mode 100644 pxii_bec/bec_widgets/widgets/px_ii_actor_config_wiget.pyproject create mode 100644 pxii_bec/bec_widgets/widgets/px_ii_actor_config_wiget_plugin.py create mode 100644 pxii_bec/bec_widgets/widgets/register_px_ii_actor_config_wiget.py diff --git a/pxii_bec/bec_widgets/widgets/__init__.py b/pxii_bec/bec_widgets/widgets/__init__.py index e69de29..f91753b 100644 --- a/pxii_bec/bec_widgets/widgets/__init__.py +++ b/pxii_bec/bec_widgets/widgets/__init__.py @@ -0,0 +1,3 @@ +from mx_bec.bec_widgets.widgets.aare_bec.actors_config import MxActorConfigWidget + +__all__ = ["MxActorConfigWidget"] diff --git a/pxii_bec/bec_widgets/widgets/client.py b/pxii_bec/bec_widgets/widgets/client.py index 3d1e02c..6fab2ee 100644 --- a/pxii_bec/bec_widgets/widgets/client.py +++ b/pxii_bec/bec_widgets/widgets/client.py @@ -13,10 +13,21 @@ logger = bec_logger.logger _Widgets = { + "PxIIActorConfigWiget": "PxIIActorConfigWiget", "ScanHistory": "ScanHistory", } +class PxIIActorConfigWiget(RPCBase): + _IMPORT_MODULE = "pxii_bec.bec_widgets.widgets.imported" + + @rpc_call + def refresh(self): + """ + Reset the layout for currently loaded actors + """ + + class ScanHistory(RPCBase): _IMPORT_MODULE = "pxii_bec.bec_widgets.widgets.scan_history.scan_history" diff --git a/pxii_bec/bec_widgets/widgets/designer_plugins.py b/pxii_bec/bec_widgets/widgets/designer_plugins.py index e80b774..1fccac6 100644 --- a/pxii_bec/bec_widgets/widgets/designer_plugins.py +++ b/pxii_bec/bec_widgets/widgets/designer_plugins.py @@ -5,9 +5,11 @@ from __future__ import annotations # pylint: skip-file designer_plugins = { + "PxIIActorConfigWiget": ("pxii_bec.bec_widgets.widgets.imported", "PxIIActorConfigWiget"), "ScanHistory": ("pxii_bec.bec_widgets.widgets.scan_history.scan_history", "ScanHistory"), } widget_icons = { + "PxIIActorConfigWiget": "format_list_bulleted", "ScanHistory": "widgets", } diff --git a/pxii_bec/bec_widgets/widgets/imported.py b/pxii_bec/bec_widgets/widgets/imported.py new file mode 100644 index 0000000..60e64cf --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/imported.py @@ -0,0 +1,4 @@ +from mx_bec.bec_widgets.widgets.aare_bec.actors_config import MxActorConfigWidget + + +class PxIIActorConfigWiget(MxActorConfigWidget): ... diff --git a/pxii_bec/bec_widgets/widgets/px_ii_actor_config_wiget.pyproject b/pxii_bec/bec_widgets/widgets/px_ii_actor_config_wiget.pyproject new file mode 100644 index 0000000..4cbb48d --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/px_ii_actor_config_wiget.pyproject @@ -0,0 +1 @@ +{'files': ['imported.py']} \ No newline at end of file diff --git a/pxii_bec/bec_widgets/widgets/px_ii_actor_config_wiget_plugin.py b/pxii_bec/bec_widgets/widgets/px_ii_actor_config_wiget_plugin.py new file mode 100644 index 0000000..51b6960 --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/px_ii_actor_config_wiget_plugin.py @@ -0,0 +1,57 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +from qtpy.QtDesigner import QDesignerCustomWidgetInterface +from qtpy.QtWidgets import QWidget + +from bec_widgets.utils.bec_designer import designer_material_icon +from pxii_bec.bec_widgets.widgets.imported import PxIIActorConfigWiget + +DOM_XML = """ + + + + +""" + + +class PxIIActorConfigWigetPlugin(QDesignerCustomWidgetInterface): # pragma: no cover + def __init__(self): + super().__init__() + self._form_editor = None + + def createWidget(self, parent): + if parent is None: + return QWidget() + t = PxIIActorConfigWiget(parent) + return t + + def domXml(self): + return DOM_XML + + def group(self): + return "" + + def icon(self): + return designer_material_icon(PxIIActorConfigWiget.ICON_NAME) + + def includeFile(self): + return "px_ii_actor_config_wiget" + + def initialize(self, form_editor): + self._form_editor = form_editor + + def isContainer(self): + return False + + def isInitialized(self): + return self._form_editor is not None + + def name(self): + return "PxIIActorConfigWiget" + + def toolTip(self): + return "PxIIActorConfigWiget" + + def whatsThis(self): + return self.toolTip() diff --git a/pxii_bec/bec_widgets/widgets/register_px_ii_actor_config_wiget.py b/pxii_bec/bec_widgets/widgets/register_px_ii_actor_config_wiget.py new file mode 100644 index 0000000..00744c0 --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/register_px_ii_actor_config_wiget.py @@ -0,0 +1,15 @@ +def main(): # pragma: no cover + from qtpy import PYSIDE6 + + if not PYSIDE6: + print("PYSIDE6 is not available in the environment. Cannot patch designer.") + return + from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection + + from pxii_bec.bec_widgets.widgets.px_ii_actor_config_wiget_plugin import PxIIActorConfigWigetPlugin + + QPyDesignerCustomWidgetCollection.addCustomWidget(PxIIActorConfigWigetPlugin()) + + +if __name__ == "__main__": # pragma: no cover + main() -- 2.54.1 From 9c25894c2bc170ab2bd2de714055a632600be53b Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 3 Nov 2026 08:29:50 +0100 Subject: [PATCH 03/10] fix: export more devices --- pxii_bec/devices/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pxii_bec/devices/__init__.py b/pxii_bec/devices/__init__.py index fb194d7..95e8f8f 100644 --- a/pxii_bec/devices/__init__.py +++ b/pxii_bec/devices/__init__.py @@ -1,4 +1,6 @@ from mx_bec.devices.aerotech import Aerotech +from mx_bec.devices.sim_sample_changer import SimSampleChanger +from mx_bec.devices.sim_stages import SimAerotechStage, SimGoniometer from mx_bec.devices.smargopolo_smargon import Smargon -__all__ = ["Aerotech", "Smargon"] +__all__ = ["Aerotech", "SimAerotechStage", "SimGoniometer", "SimSampleChanger", "Smargon"] -- 2.54.1 From 029778cd668ad383b9e846e8a3abf6bc68e103e9 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 3 Nov 2026 08:51:16 +0100 Subject: [PATCH 04/10] fix: export messages --- pxii_bec/messages.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 pxii_bec/messages.py diff --git a/pxii_bec/messages.py b/pxii_bec/messages.py new file mode 100644 index 0000000..4975034 --- /dev/null +++ b/pxii_bec/messages.py @@ -0,0 +1,10 @@ +"""Message types of the MX plugins, re-exported from mx_bec so that BEC's message decoder can +find them through the `bec.messages` entry point registered by this package.""" + +from mx_bec.messages import ( + MXMeasurementSequenceMessage, + MXTaskExecutionMessage, + OpticalPredictionMessage, +) + +__all__ = ["MXMeasurementSequenceMessage", "MXTaskExecutionMessage", "OpticalPredictionMessage"] -- 2.54.1 From e87b019b57f4a746837caefa6ec1fe18ff33639b Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 3 Nov 2026 09:30:25 +0100 Subject: [PATCH 05/10] feat: add queue widget --- pxii_bec/bec_widgets/widgets/__init__.py | 3 +- pxii_bec/bec_widgets/widgets/client.py | 11 ++++ .../bec_widgets/widgets/designer_plugins.py | 2 + pxii_bec/bec_widgets/widgets/imported.py | 4 ++ .../widgets/px_ii_task_queue_widget.pyproject | 1 + .../widgets/px_ii_task_queue_widget_plugin.py | 57 +++++++++++++++++++ .../register_px_ii_task_queue_widget.py | 15 +++++ pxii_bec/messages.py | 8 ++- 8 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 pxii_bec/bec_widgets/widgets/px_ii_task_queue_widget.pyproject create mode 100644 pxii_bec/bec_widgets/widgets/px_ii_task_queue_widget_plugin.py create mode 100644 pxii_bec/bec_widgets/widgets/register_px_ii_task_queue_widget.py diff --git a/pxii_bec/bec_widgets/widgets/__init__.py b/pxii_bec/bec_widgets/widgets/__init__.py index f91753b..f670d94 100644 --- a/pxii_bec/bec_widgets/widgets/__init__.py +++ b/pxii_bec/bec_widgets/widgets/__init__.py @@ -1,3 +1,4 @@ from mx_bec.bec_widgets.widgets.aare_bec.actors_config import MxActorConfigWidget +from mx_bec.bec_widgets.widgets.aare_bec.task_queue import MxTaskQueueWidget -__all__ = ["MxActorConfigWidget"] +__all__ = ["MxActorConfigWidget", "MxTaskQueueWidget"] diff --git a/pxii_bec/bec_widgets/widgets/client.py b/pxii_bec/bec_widgets/widgets/client.py index 6fab2ee..c1d0216 100644 --- a/pxii_bec/bec_widgets/widgets/client.py +++ b/pxii_bec/bec_widgets/widgets/client.py @@ -14,6 +14,7 @@ logger = bec_logger.logger _Widgets = { "PxIIActorConfigWiget": "PxIIActorConfigWiget", + "PxIITaskQueueWidget": "PxIITaskQueueWidget", "ScanHistory": "ScanHistory", } @@ -28,6 +29,16 @@ class PxIIActorConfigWiget(RPCBase): """ +class PxIITaskQueueWidget(RPCBase): + _IMPORT_MODULE = "pxii_bec.bec_widgets.widgets.imported" + + @rpc_call + def refresh(self): + """ + Reload the queued tasks from Redis. + """ + + class ScanHistory(RPCBase): _IMPORT_MODULE = "pxii_bec.bec_widgets.widgets.scan_history.scan_history" diff --git a/pxii_bec/bec_widgets/widgets/designer_plugins.py b/pxii_bec/bec_widgets/widgets/designer_plugins.py index 1fccac6..162c451 100644 --- a/pxii_bec/bec_widgets/widgets/designer_plugins.py +++ b/pxii_bec/bec_widgets/widgets/designer_plugins.py @@ -6,10 +6,12 @@ from __future__ import annotations designer_plugins = { "PxIIActorConfigWiget": ("pxii_bec.bec_widgets.widgets.imported", "PxIIActorConfigWiget"), + "PxIITaskQueueWidget": ("pxii_bec.bec_widgets.widgets.imported", "PxIITaskQueueWidget"), "ScanHistory": ("pxii_bec.bec_widgets.widgets.scan_history.scan_history", "ScanHistory"), } widget_icons = { "PxIIActorConfigWiget": "format_list_bulleted", + "PxIITaskQueueWidget": "pending_actions", "ScanHistory": "widgets", } diff --git a/pxii_bec/bec_widgets/widgets/imported.py b/pxii_bec/bec_widgets/widgets/imported.py index 60e64cf..6c95f0a 100644 --- a/pxii_bec/bec_widgets/widgets/imported.py +++ b/pxii_bec/bec_widgets/widgets/imported.py @@ -1,4 +1,8 @@ from mx_bec.bec_widgets.widgets.aare_bec.actors_config import MxActorConfigWidget +from mx_bec.bec_widgets.widgets.aare_bec.task_queue import MxTaskQueueWidget class PxIIActorConfigWiget(MxActorConfigWidget): ... + + +class PxIITaskQueueWidget(MxTaskQueueWidget): ... diff --git a/pxii_bec/bec_widgets/widgets/px_ii_task_queue_widget.pyproject b/pxii_bec/bec_widgets/widgets/px_ii_task_queue_widget.pyproject new file mode 100644 index 0000000..4cbb48d --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/px_ii_task_queue_widget.pyproject @@ -0,0 +1 @@ +{'files': ['imported.py']} \ No newline at end of file diff --git a/pxii_bec/bec_widgets/widgets/px_ii_task_queue_widget_plugin.py b/pxii_bec/bec_widgets/widgets/px_ii_task_queue_widget_plugin.py new file mode 100644 index 0000000..52f293e --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/px_ii_task_queue_widget_plugin.py @@ -0,0 +1,57 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +from qtpy.QtDesigner import QDesignerCustomWidgetInterface +from qtpy.QtWidgets import QWidget + +from bec_widgets.utils.bec_designer import designer_material_icon +from pxii_bec.bec_widgets.widgets.imported import PxIITaskQueueWidget + +DOM_XML = """ + + + + +""" + + +class PxIITaskQueueWidgetPlugin(QDesignerCustomWidgetInterface): # pragma: no cover + def __init__(self): + super().__init__() + self._form_editor = None + + def createWidget(self, parent): + if parent is None: + return QWidget() + t = PxIITaskQueueWidget(parent) + return t + + def domXml(self): + return DOM_XML + + def group(self): + return "" + + def icon(self): + return designer_material_icon(PxIITaskQueueWidget.ICON_NAME) + + def includeFile(self): + return "px_ii_task_queue_widget" + + def initialize(self, form_editor): + self._form_editor = form_editor + + def isContainer(self): + return False + + def isInitialized(self): + return self._form_editor is not None + + def name(self): + return "PxIITaskQueueWidget" + + def toolTip(self): + return "PxIITaskQueueWidget" + + def whatsThis(self): + return self.toolTip() diff --git a/pxii_bec/bec_widgets/widgets/register_px_ii_task_queue_widget.py b/pxii_bec/bec_widgets/widgets/register_px_ii_task_queue_widget.py new file mode 100644 index 0000000..8e94f05 --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/register_px_ii_task_queue_widget.py @@ -0,0 +1,15 @@ +def main(): # pragma: no cover + from qtpy import PYSIDE6 + + if not PYSIDE6: + print("PYSIDE6 is not available in the environment. Cannot patch designer.") + return + from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection + + from pxii_bec.bec_widgets.widgets.px_ii_task_queue_widget_plugin import PxIITaskQueueWidgetPlugin + + QPyDesignerCustomWidgetCollection.addCustomWidget(PxIITaskQueueWidgetPlugin()) + + +if __name__ == "__main__": # pragma: no cover + main() diff --git a/pxii_bec/messages.py b/pxii_bec/messages.py index 4975034..faaeee5 100644 --- a/pxii_bec/messages.py +++ b/pxii_bec/messages.py @@ -4,7 +4,13 @@ find them through the `bec.messages` entry point registered by this package.""" from mx_bec.messages import ( MXMeasurementSequenceMessage, MXTaskExecutionMessage, + MXTaskQueueChangedMessage, OpticalPredictionMessage, ) -__all__ = ["MXMeasurementSequenceMessage", "MXTaskExecutionMessage", "OpticalPredictionMessage"] +__all__ = [ + "MXMeasurementSequenceMessage", + "MXTaskExecutionMessage", + "MXTaskQueueChangedMessage", + "OpticalPredictionMessage", +] -- 2.54.1 From c85bde6127970ff5be0516565ef9d4ec7c1f49b3 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 3 Nov 2026 09:38:25 +0100 Subject: [PATCH 06/10] feat: add task panel widget --- pxii_bec/bec_widgets/widgets/__init__.py | 3 +- pxii_bec/bec_widgets/widgets/client.py | 11 ++++ .../bec_widgets/widgets/designer_plugins.py | 2 + pxii_bec/bec_widgets/widgets/imported.py | 4 ++ .../widgets/px_ii_task_panel.pyproject | 1 + .../widgets/px_ii_task_panel_plugin.py | 57 +++++++++++++++++++ .../widgets/register_px_ii_task_panel.py | 15 +++++ 7 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 pxii_bec/bec_widgets/widgets/px_ii_task_panel.pyproject create mode 100644 pxii_bec/bec_widgets/widgets/px_ii_task_panel_plugin.py create mode 100644 pxii_bec/bec_widgets/widgets/register_px_ii_task_panel.py diff --git a/pxii_bec/bec_widgets/widgets/__init__.py b/pxii_bec/bec_widgets/widgets/__init__.py index f670d94..562ce61 100644 --- a/pxii_bec/bec_widgets/widgets/__init__.py +++ b/pxii_bec/bec_widgets/widgets/__init__.py @@ -1,4 +1,5 @@ from mx_bec.bec_widgets.widgets.aare_bec.actors_config import MxActorConfigWidget +from mx_bec.bec_widgets.widgets.aare_bec.task_panel import MxTaskPanel from mx_bec.bec_widgets.widgets.aare_bec.task_queue import MxTaskQueueWidget -__all__ = ["MxActorConfigWidget", "MxTaskQueueWidget"] +__all__ = ["MxActorConfigWidget", "MxTaskPanel", "MxTaskQueueWidget"] diff --git a/pxii_bec/bec_widgets/widgets/client.py b/pxii_bec/bec_widgets/widgets/client.py index c1d0216..c09931d 100644 --- a/pxii_bec/bec_widgets/widgets/client.py +++ b/pxii_bec/bec_widgets/widgets/client.py @@ -14,6 +14,7 @@ logger = bec_logger.logger _Widgets = { "PxIIActorConfigWiget": "PxIIActorConfigWiget", + "PxIITaskPanel": "PxIITaskPanel", "PxIITaskQueueWidget": "PxIITaskQueueWidget", "ScanHistory": "ScanHistory", } @@ -29,6 +30,16 @@ class PxIIActorConfigWiget(RPCBase): """ +class PxIITaskPanel(RPCBase): + _IMPORT_MODULE = "pxii_bec.bec_widgets.widgets.imported" + + @rpc_call + def request_task(self, name: "str", *args, **kwargs): + """ + Submit a task request to the AareBec service. + """ + + class PxIITaskQueueWidget(RPCBase): _IMPORT_MODULE = "pxii_bec.bec_widgets.widgets.imported" diff --git a/pxii_bec/bec_widgets/widgets/designer_plugins.py b/pxii_bec/bec_widgets/widgets/designer_plugins.py index 162c451..ec9f16c 100644 --- a/pxii_bec/bec_widgets/widgets/designer_plugins.py +++ b/pxii_bec/bec_widgets/widgets/designer_plugins.py @@ -6,12 +6,14 @@ from __future__ import annotations designer_plugins = { "PxIIActorConfigWiget": ("pxii_bec.bec_widgets.widgets.imported", "PxIIActorConfigWiget"), + "PxIITaskPanel": ("pxii_bec.bec_widgets.widgets.imported", "PxIITaskPanel"), "PxIITaskQueueWidget": ("pxii_bec.bec_widgets.widgets.imported", "PxIITaskQueueWidget"), "ScanHistory": ("pxii_bec.bec_widgets.widgets.scan_history.scan_history", "ScanHistory"), } widget_icons = { "PxIIActorConfigWiget": "format_list_bulleted", + "PxIITaskPanel": "play_arrow", "PxIITaskQueueWidget": "pending_actions", "ScanHistory": "widgets", } diff --git a/pxii_bec/bec_widgets/widgets/imported.py b/pxii_bec/bec_widgets/widgets/imported.py index 6c95f0a..c229118 100644 --- a/pxii_bec/bec_widgets/widgets/imported.py +++ b/pxii_bec/bec_widgets/widgets/imported.py @@ -1,4 +1,5 @@ from mx_bec.bec_widgets.widgets.aare_bec.actors_config import MxActorConfigWidget +from mx_bec.bec_widgets.widgets.aare_bec.task_panel import MxTaskPanel from mx_bec.bec_widgets.widgets.aare_bec.task_queue import MxTaskQueueWidget @@ -6,3 +7,6 @@ class PxIIActorConfigWiget(MxActorConfigWidget): ... class PxIITaskQueueWidget(MxTaskQueueWidget): ... + + +class PxIITaskPanel(MxTaskPanel): ... diff --git a/pxii_bec/bec_widgets/widgets/px_ii_task_panel.pyproject b/pxii_bec/bec_widgets/widgets/px_ii_task_panel.pyproject new file mode 100644 index 0000000..4cbb48d --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/px_ii_task_panel.pyproject @@ -0,0 +1 @@ +{'files': ['imported.py']} \ No newline at end of file diff --git a/pxii_bec/bec_widgets/widgets/px_ii_task_panel_plugin.py b/pxii_bec/bec_widgets/widgets/px_ii_task_panel_plugin.py new file mode 100644 index 0000000..ccbeadf --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/px_ii_task_panel_plugin.py @@ -0,0 +1,57 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +from qtpy.QtDesigner import QDesignerCustomWidgetInterface +from qtpy.QtWidgets import QWidget + +from bec_widgets.utils.bec_designer import designer_material_icon +from pxii_bec.bec_widgets.widgets.imported import PxIITaskPanel + +DOM_XML = """ + + + + +""" + + +class PxIITaskPanelPlugin(QDesignerCustomWidgetInterface): # pragma: no cover + def __init__(self): + super().__init__() + self._form_editor = None + + def createWidget(self, parent): + if parent is None: + return QWidget() + t = PxIITaskPanel(parent) + return t + + def domXml(self): + return DOM_XML + + def group(self): + return "" + + def icon(self): + return designer_material_icon(PxIITaskPanel.ICON_NAME) + + def includeFile(self): + return "px_ii_task_panel" + + def initialize(self, form_editor): + self._form_editor = form_editor + + def isContainer(self): + return False + + def isInitialized(self): + return self._form_editor is not None + + def name(self): + return "PxIITaskPanel" + + def toolTip(self): + return "PxIITaskPanel" + + def whatsThis(self): + return self.toolTip() diff --git a/pxii_bec/bec_widgets/widgets/register_px_ii_task_panel.py b/pxii_bec/bec_widgets/widgets/register_px_ii_task_panel.py new file mode 100644 index 0000000..e0b4e2b --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/register_px_ii_task_panel.py @@ -0,0 +1,15 @@ +def main(): # pragma: no cover + from qtpy import PYSIDE6 + + if not PYSIDE6: + print("PYSIDE6 is not available in the environment. Cannot patch designer.") + return + from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection + + from pxii_bec.bec_widgets.widgets.px_ii_task_panel_plugin import PxIITaskPanelPlugin + + QPyDesignerCustomWidgetCollection.addCustomWidget(PxIITaskPanelPlugin()) + + +if __name__ == "__main__": # pragma: no cover + main() -- 2.54.1 From abed6a7de6e90e6a3ca4d4228e65cd7af76507ff Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 3 Nov 2026 10:42:13 +0100 Subject: [PATCH 07/10] fix: add mx_bec dep --- .gitea/workflows/ci.yml | 34 +++++++- pyproject.toml | 2 +- tests/tests_devices/mock_smargopolo.py | 110 ------------------------- tests/tests_devices/test_aerotech.py | 72 ++++++++-------- tests/tests_devices/test_smargon.py | 57 +++++++------ 5 files changed, 105 insertions(+), 170 deletions(-) delete mode 100644 tests/tests_devices/mock_smargopolo.py diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 4cf457f..508accf 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -24,6 +24,11 @@ on: required: false type: string default: "main" + MX_BEC_REPO_BRANCH: + description: "Branch of the mx_bec core repo to install" + required: false + type: string + default: "main" PYTHON_VERSION: description: "Python version to use" required: false @@ -46,6 +51,29 @@ jobs: with: python-version: "${{ inputs.PYTHON_VERSION || '3.12' }}" + # Use the same-named branch of mx_bec if it exists (e.g. a feature developed in both repos), otherwise main. + - name: Resolve mx_bec branch + id: mx_bec + shell: bash + run: | + ref="${{ inputs.MX_BEC_REPO_BRANCH || github.head_ref || github.ref_name }}" + auth="$(printf 'x-access-token:%s' '${{ github.token }}' | base64 -w0)" + if git -c "http.extraheader=Authorization: Basic ${auth}" ls-remote --exit-code --heads \ + "${{ github.server_url }}/bec/mx_bec.git" "refs/heads/${ref}" >/dev/null; then + echo "Using mx_bec branch '${ref}'" + else + echo "mx_bec has no branch '${ref}', using main" + ref=main + fi + echo "ref=${ref}" >> "$GITHUB_OUTPUT" + + - name: Checkout MX BEC Repository + uses: actions/checkout@v4 + with: + repository: bec/mx_bec + ref: "${{ steps.mx_bec.outputs.ref }}" + path: ./mx_bec + - name: Checkout BEC Plugin Repository uses: actions/checkout@v4 with: @@ -94,8 +122,10 @@ jobs: uv pip install --system -e ./bec/bec_lib[dev] uv pip install --system -e ./bec/bec_ipython_client uv pip install --system -e ./bec/bec_server[dev] - uv pip install --system -e ./bec_widgets[dev,pyside6] - uv pip install --system -e ./pxii_bec[dev] + uv pip install --system -e ./bec_widgets[dev] + # MX-internal dependencies (aarecommon, aare_config, jfjoch_client, ...) come from gitea + uv pip install --system --extra-index-url https://gitea.psi.ch/api/packages/mx/pypi/simple/ -e ./mx_bec[dev] + uv pip install --system --extra-index-url https://gitea.psi.ch/api/packages/mx/pypi/simple/ -e ./pxii_bec[dev] - name: Run Tests with Coverage id: coverage diff --git a/pyproject.toml b/pyproject.toml index eaec104..b5d968d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ classifiers = [ "Programming Language :: Python :: 3", "Topic :: Scientific/Engineering", ] -dependencies = ["pandas~=2.0", "matplotlib"] +dependencies = ["mx_bec", "pandas~=2.0", "matplotlib"] [project.optional-dependencies] dev = [ diff --git a/tests/tests_devices/mock_smargopolo.py b/tests/tests_devices/mock_smargopolo.py deleted file mode 100644 index 466063e..0000000 --- a/tests/tests_devices/mock_smargopolo.py +++ /dev/null @@ -1,110 +0,0 @@ -"""A mock smargopolo REST interface with mock motoers, for testing devices against""" - -import asyncio -import random -import time -from contextlib import asynccontextmanager -from typing import Iterable - -import uvicorn -from fastapi import FastAPI, HTTPException, Query, Request -from pydantic import BaseModel - -AXES = ["SHX", "SHY", "SHZ", "PHI", "CHI"] - - -class Motor: - def __init__(self, velocity: float = 1.0): - self.position = 0.0 - self.target = 0.0 - self.velocity = velocity - self.moving = False - self._last_update = time.monotonic() - - def update(self): - now = time.monotonic() - dt = now - self._last_update - self._last_update = now - - if not self.moving: - return - - jitter_factor = random.random() * 0.05 - 0.025 # +- 2.5% jitter in step - distance = self.target - self.position - direction = 1 if distance > 0 else -1 - step = direction * self.velocity * dt - - if abs(step) >= abs(distance): - self.position = self.target + (step * jitter_factor) - self.moving = False - else: - self.position += step * (1 + jitter_factor) - - -motors: dict[str, Motor] = { - "SHX": Motor(velocity=3), - "SHY": Motor(velocity=2.5), - "SHZ": Motor(velocity=2), - "PHI": Motor(velocity=1.0), - "CHI": Motor(velocity=0.7), -} - - -class MoveRequest(BaseModel): - target: float - - -@asynccontextmanager -async def lifespan(app: FastAPI): - async def updater(): - while True: - for motor in motors.values(): - motor.update() - await asyncio.sleep(0.02) # 50 Hz update loop - - task = asyncio.create_task(updater()) - yield - task.cancel() - try: - await task - except asyncio.CancelledError: - pass - - -app = FastAPI(lifespan=lifespan) - - -def validate_axes(axes: Iterable[str] | None) -> list[str]: - if axes is None: - return AXES - for a in axes: - if a not in AXES: - raise HTTPException(status_code=404, detail=f"Unknown axis: {a}") - return list(axes) - - -@app.get("/readbackSCS") -async def readback_scs(axis: list[str] | None = Query(None)): - selected_axes = validate_axes(axis) - return {ax: motors[ax].position for ax in selected_axes} - - -@app.put("/targetSCS") -async def target_scs(req: Request): - targets = {ax: float(t) for ax, t in req.query_params.items()} - if targets is None: - return {} - - selected_axes = validate_axes(targets.keys()) - - for a in selected_axes: - motor = motors[a] - motor.update() - motor.target = targets[a] - motor.moving = True - - return {"targets": targets, "message": "Move started"} - - -if __name__ == "__main__": - uvicorn.run(app, host="0.0.0.0", port=8000, reload=False) diff --git a/tests/tests_devices/test_aerotech.py b/tests/tests_devices/test_aerotech.py index 3cf76f5..90475eb 100644 --- a/tests/tests_devices/test_aerotech.py +++ b/tests/tests_devices/test_aerotech.py @@ -1,58 +1,64 @@ +"""Smoke tests of the Aerotech device as re-exported by pxii_bec; the device itself is tested in +mx_bec.""" + from copy import copy from threading import RLock from unittest.mock import ANY import pytest +from mx_bec.devices.aerotech import Aerotech as MxAerotech + +from pxii_bec.devices import Aerotech + +AXES = ("x", "y", "z", "u") class MockServer: + """Just enough of the AareScan REST API for reading and moving axes.""" + def __init__(self) -> None: self.lock = RLock() - self.mock_data = { - "x": {"pos": 1.0}, - "y": {"pos": 1.0}, - "z": {"pos": 1.0}, - "u": {"pos": 1.0}, - "vel_u_deg_s": {"pos": 1.0}, - } + self.mock_data = {axis: {"pos": 1.0} for axis in AXES} def get(self, endpoint): with self.lock: return copy(self.mock_data) - def put(self, params: dict | None = None, body: dict | None = None): + def post(self, params: dict | None = None, body: dict | None = None, endpoint=None): with self.lock: assert body is not None - for k, v in body.items(): - self.mock_data[k]["pos"] = v + for axis, value in body.items(): + if axis in self.mock_data: # the body also carries the velocity parameter + self.mock_data[axis]["pos"] = value @pytest.fixture def aerotech(): mock_server = MockServer() - from pxii_bec.devices import Aerotech - - s = Aerotech(name="aerotech", prefix="http://test-aerotech.psi.ch") - s.controller._rest_get = mock_server.get - s.controller._rest_post = mock_server.put - yield s - s.controller._stop_monitor_readback_event.set() + device = Aerotech(name="aerotech", prefix="http://test-aerotech.psi.ch") + device.controller._rest_get = mock_server.get + device.controller._rest_post = mock_server.post + device.controller.validate = lambda endpoint, body: (True, "") + yield device + device.controller._stop_monitor_readback_event.set() + device.destroy() -class TestAerotech: - def test_aerotech_read(self, aerotech): - aerotech.wait_for_connection() - reading = aerotech.read() - assert dict(reading) == { - "aerotech_x": {"value": 1.0, "timestamp": ANY}, - "aerotech_y": {"value": 1.0, "timestamp": ANY}, - "aerotech_z": {"value": 1.0, "timestamp": ANY}, - "aerotech_u": {"value": 1.0, "timestamp": ANY}, - "aerotech_vel_u_deg_s": {"value": 1.0, "timestamp": ANY}, - } +def test_is_the_mx_bec_device(): + assert Aerotech is MxAerotech - def test_aerotech_set_with_status(self, aerotech): - aerotech.wait_for_connection() - st = aerotech.x.set(5.0) - st.wait(timeout=1) - assert aerotech.x.get() == 5.0 + +def test_aerotech_read(aerotech): + aerotech.wait_for_connection() + reading = dict(aerotech.read()) + # besides the axes, read() reports the valid/message state of the scan parameter groups + assert {k: v for k, v in reading.items() if k.removeprefix("aerotech_") in AXES} == { + f"aerotech_{axis}": {"value": 1.0, "timestamp": ANY} for axis in AXES + } + assert reading["aerotech_gridscan_config_valid"]["value"] is True + + +def test_aerotech_set_with_status(aerotech): + aerotech.wait_for_connection() + aerotech.x.set(5.0).wait(timeout=1) + assert aerotech.x.get() == 5.0 diff --git a/tests/tests_devices/test_smargon.py b/tests/tests_devices/test_smargon.py index fc14015..1b8f7bc 100644 --- a/tests/tests_devices/test_smargon.py +++ b/tests/tests_devices/test_smargon.py @@ -1,14 +1,24 @@ +"""Smoke tests of the Smargon device as re-exported by pxii_bec; the device itself is tested in +mx_bec against a mock smargopolo server.""" + from copy import copy from threading import RLock from unittest.mock import ANY import pytest +from mx_bec.devices.smargopolo_smargon import Smargon as MxSmargon + +from pxii_bec.devices import Smargon + +AXES = ("SHX", "SHY", "SHZ", "PHI", "CHI") class MockServer: + """Just enough of the smargopolo REST API for reading and moving axes.""" + def __init__(self) -> None: self.lock = RLock() - self.mock_data = {"SHX": 1.0, "SHY": 1.0, "SHZ": 1.0, "PHI": 1.0, "CHI": 1.0} + self.mock_data = {axis: 1.0 for axis in AXES} def get(self, endpoint): with self.lock: @@ -23,29 +33,28 @@ class MockServer: @pytest.fixture def smargon(): mock_server = MockServer() - from pxii_bec.devices.smargopolo_smargon import Smargon - - s = Smargon(name="smargon", prefix="http://test-smargopolo.psi.ch") - s.controller._rest_get = mock_server.get - s.controller._rest_put = mock_server.put - yield s - s.controller._stop_monitor_readback_event.set() + device = Smargon(name="smargon", prefix="http://test-smargopolo.psi.ch") + device.controller._rest_get = mock_server.get + device.controller._rest_put = mock_server.put + yield device + device.controller._stop_monitor_readback_event.set() + device.destroy() -class TestSmargon: - def test_smargon_read(self, smargon): - smargon.wait_for_connection() - reading = smargon.read() - assert dict(reading) == { - "smargon_x": {"value": 1.0, "timestamp": ANY}, - "smargon_y": {"value": 1.0, "timestamp": ANY}, - "smargon_z": {"value": 1.0, "timestamp": ANY}, - "smargon_phi": {"value": 1.0, "timestamp": ANY}, - "smargon_chi": {"value": 1.0, "timestamp": ANY}, - } +def test_is_the_mx_bec_device(): + assert Smargon is MxSmargon - def test_smargon_set_with_status(self, smargon): - smargon.wait_for_connection() - st = smargon.x.set(5.0) - st.wait(timeout=1) - assert smargon.x.get() == 5.0 + +def test_smargon_read(smargon): + smargon.wait_for_connection() + reading = smargon.read() + assert dict(reading) == { + f"smargon_{axis}": {"value": 1.0, "timestamp": ANY} + for axis in ("x", "y", "z", "phi", "chi") + } + + +def test_smargon_set_with_status(smargon): + smargon.wait_for_connection() + smargon.x.set(5.0).wait(timeout=1) + assert smargon.x.get() == 5.0 -- 2.54.1 From acd92d903d2f1a31976ef4fd1acc2fee39db9713 Mon Sep 17 00:00:00 2001 From: x10sa Date: Wed, 4 Nov 2026 09:16:03 +0100 Subject: [PATCH 08/10] fix: correct entry points --- pxii_bec/device_configs/pxii-devices.yaml | 362 +++++++++++----------- pxii_bec/scripts/init_beamline.py | 9 +- pyproject.toml | 4 +- 3 files changed, 189 insertions(+), 186 deletions(-) diff --git a/pxii_bec/device_configs/pxii-devices.yaml b/pxii_bec/device_configs/pxii-devices.yaml index 57171f7..50fe646 100755 --- a/pxii_bec/device_configs/pxii-devices.yaml +++ b/pxii_bec/device_configs/pxii-devices.yaml @@ -21,7 +21,6 @@ # Default values may be omitted for brevity. ########################################################################################################################## - # An example device configuration with all fields: # device1: @@ -30,7 +29,7 @@ # deviceConfig: # delay: 1 # update_frequency: 10 -# deviceTags: +# deviceTags: # - frontend # - motor # enabled: true @@ -48,19 +47,18 @@ ########################################################################################################################## - aerotech: description: REST-based device which connects to AareScan and Aerotech deviceClass: pxii_bec.devices.Aerotech deviceConfig: prefix: http://mx-x10sa-queue-01:5234 - vel_u_deg_s: 5 + vel_u_deg_s: 30 vel_x_mm_s: 0.1 vel_y_mm_s: 0.1 vel_z_mm_s: 0.1 deviceTags: - - aerotech - - motors + - aerotech + - motors enabled: true onFailure: buffer readoutPriority: baseline @@ -85,7 +83,7 @@ bcu_bpm1: auto_monitor: true read_pv: X10SA-ES-BCBPM:Current1:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -97,7 +95,7 @@ bcu_bpm2: auto_monitor: true read_pv: X10SA-ES-BCBPM:Current2:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -109,7 +107,7 @@ bcu_bpm3: auto_monitor: true read_pv: X10SA-ES-BCBPM:Current3:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -121,7 +119,7 @@ bcu_bpm4: auto_monitor: true read_pv: X10SA-ES-BCBPM:Current4:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -132,7 +130,7 @@ bcu_bpm_x: deviceConfig: prefix: X10SA-ES-BCBPM:TRX deviceTags: - - bcu + - bcu enabled: true onFailure: buffer readoutPriority: baseline @@ -142,7 +140,7 @@ bcu_bpm_y: deviceConfig: prefix: X10SA-ES-BCBPM:TRY deviceTags: - - bcu + - bcu enabled: true onFailure: buffer readoutPriority: baseline @@ -153,7 +151,7 @@ bcu_bpmsum: auto_monitor: true read_pv: X10SA-ES-BCBPM:SumAll:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -165,7 +163,7 @@ bcu_shutter: auto_monitor: true read_pv: X10SA-ES-SHUTTER:SET deviceTags: - - state + - state enabled: true onFailure: buffer readoutPriority: baseline @@ -175,7 +173,7 @@ bcu_sl_xcen: deviceConfig: prefix: X10SA-ES-BCSLH:CENTER deviceTags: - - bcu + - bcu enabled: true onFailure: buffer readoutPriority: baseline @@ -185,7 +183,7 @@ bcu_sl_xr: deviceConfig: prefix: X10SA-ES-BCSLH:TRXR deviceTags: - - bcu + - bcu enabled: true onFailure: buffer readoutPriority: baseline @@ -195,7 +193,7 @@ bcu_sl_xsize: deviceConfig: prefix: X10SA-ES-BCSLH:SIZE deviceTags: - - bcu + - bcu enabled: true onFailure: buffer readoutPriority: baseline @@ -205,7 +203,7 @@ bcu_sl_xw: deviceConfig: prefix: X10SA-ES-BCSLH:TRXW deviceTags: - - bcu + - bcu enabled: true onFailure: buffer readoutPriority: baseline @@ -215,7 +213,7 @@ bcu_sl_yb: deviceConfig: prefix: X10SA-ES-BCSLV:TRYB deviceTags: - - bcu + - bcu enabled: true onFailure: buffer readoutPriority: baseline @@ -225,7 +223,7 @@ bcu_sl_ycen: deviceConfig: prefix: X10SA-ES-BCSLV:CENTER deviceTags: - - bcu + - bcu enabled: true onFailure: buffer readoutPriority: baseline @@ -235,7 +233,7 @@ bcu_sl_ysize: deviceConfig: prefix: X10SA-ES-BCSLV:SIZE deviceTags: - - bcu + - bcu enabled: true onFailure: buffer readoutPriority: baseline @@ -245,7 +243,7 @@ bcu_sl_yt: deviceConfig: prefix: X10SA-ES-BCSLV:TRYT deviceTags: - - bcu + - bcu enabled: true onFailure: buffer readoutPriority: baseline @@ -256,13 +254,13 @@ bl_bright: auto_monitor: true read_pv: X10SA-ES-BL:SET deviceTags: - - state + - state enabled: true onFailure: buffer readoutPriority: baseline userParameter: - 'off': 0.0 - 'on': 1.3 + "off": 0.0 + "on": 1.3 tol: 0.01 type: continuous bl_pos: @@ -272,7 +270,7 @@ bl_pos: auto_monitor: true read_pv: X10SA-ES-BL:POS-SET deviceTags: - - state + - state enabled: true onFailure: buffer readoutPriority: baseline @@ -287,7 +285,7 @@ bs_pos: auto_monitor: true read_pv: X10SA-ES-BS:POS-SET deviceTags: - - state + - state enabled: true onFailure: buffer readoutPriority: baseline @@ -301,7 +299,7 @@ bs_x: deviceConfig: prefix: X10SA-ES-BS:TRX deviceTags: - - se + - se enabled: true onFailure: buffer readoutPriority: baseline @@ -313,7 +311,7 @@ bs_y: deviceConfig: prefix: X10SA-ES-BS:TRY deviceTags: - - se + - se enabled: true onFailure: buffer readoutPriority: baseline @@ -325,7 +323,7 @@ bs_z: deviceConfig: prefix: X10SA-ES-BS:TRZ deviceTags: - - state + - state enabled: true onFailure: buffer readoutPriority: baseline @@ -343,7 +341,7 @@ bsf_f1_y: deviceConfig: prefix: X10SA-OP-BSFFI1:TRY deviceTags: - - bsf + - bsf enabled: true onFailure: buffer readoutPriority: baseline @@ -353,7 +351,7 @@ bsf_f2_y: deviceConfig: prefix: X10SA-OP-BSFFI2:TRY deviceTags: - - bsf + - bsf enabled: true onFailure: buffer readoutPriority: baseline @@ -363,7 +361,7 @@ bsf_sl_xcen: deviceConfig: prefix: X10SA-OP-BSFSLH:CENTER deviceTags: - - bsf + - bsf enabled: true onFailure: buffer readoutPriority: baseline @@ -373,7 +371,7 @@ bsf_sl_xr: deviceConfig: prefix: X10SA-OP-BSFSLH:TRXR deviceTags: - - bsf + - bsf enabled: true onFailure: buffer readoutPriority: baseline @@ -383,7 +381,7 @@ bsf_sl_xsize: deviceConfig: prefix: X10SA-OP-BSFSLH:SIZE deviceTags: - - bsf + - bsf enabled: true onFailure: buffer readoutPriority: baseline @@ -393,7 +391,7 @@ bsf_sl_xw: deviceConfig: prefix: X10SA-OP-BSFSLH:TRXW deviceTags: - - bsf + - bsf enabled: true onFailure: buffer readoutPriority: baseline @@ -403,7 +401,7 @@ bsf_sl_yb: deviceConfig: prefix: X10SA-OP-BSFSLV:TRYB deviceTags: - - bsf + - bsf enabled: true onFailure: buffer readoutPriority: baseline @@ -413,7 +411,7 @@ bsf_sl_ycen: deviceConfig: prefix: X10SA-OP-BSFSLV:CENTER deviceTags: - - bsf + - bsf enabled: true onFailure: buffer readoutPriority: baseline @@ -423,7 +421,7 @@ bsf_sl_ysize: deviceConfig: prefix: X10SA-OP-BSFSLV:SIZE deviceTags: - - bsf + - bsf enabled: true onFailure: buffer readoutPriority: baseline @@ -433,7 +431,7 @@ bsf_sl_yt: deviceConfig: prefix: X10SA-OP-BSFSLV:TRYT deviceTags: - - bsf + - bsf enabled: true onFailure: buffer readoutPriority: baseline @@ -443,7 +441,7 @@ coll_x: deviceConfig: prefix: X10SA-ES-COL:TRX deviceTags: - - se + - se enabled: true onFailure: buffer readoutPriority: baseline @@ -455,7 +453,7 @@ coll_y: deviceConfig: prefix: X10SA-ES-COL:TRY deviceTags: - - state + - state enabled: true onFailure: buffer readoutPriority: baseline @@ -473,7 +471,7 @@ coll_y_in_position: auto_monitor: true read_pv: X10SA-ES-COL:POS-SET-SEQ.DO2 deviceTags: - - se + - se enabled: true onFailure: buffer readoutPriority: baseline @@ -484,7 +482,7 @@ cryo_pos: auto_monitor: true read_pv: X10SA-ES-CS:POS-SET deviceTags: - - state + - state enabled: true onFailure: buffer readoutPriority: baseline @@ -499,7 +497,7 @@ cryo_temp: auto_monitor: true read_pv: X10SA-ES-CS:TEMP_RBV deviceTags: - - se + - se enabled: true onFailure: buffer readOnly: true @@ -510,7 +508,7 @@ cryo_x: deviceConfig: prefix: X10SA-ES-CS:TRX deviceTags: - - se + - se enabled: true onFailure: buffer readoutPriority: baseline @@ -520,7 +518,7 @@ dcm_bragg: deviceConfig: prefix: X10SA-OP-DCM:ROTY deviceTags: - - dcm + - dcm enabled: true onFailure: buffer readoutPriority: baseline @@ -530,7 +528,7 @@ dcm_fpitch: deviceConfig: prefix: X10SA-OP-DCM:ROTY-CR2-FINEPITCH deviceTags: - - dcm + - dcm enabled: true onFailure: buffer readoutPriority: baseline @@ -540,7 +538,7 @@ dcm_froll: deviceConfig: prefix: X10SA-OP-DCM:ROTZ-CR2-FINEROLL deviceTags: - - dcm + - dcm enabled: true onFailure: buffer readoutPriority: baseline @@ -550,7 +548,7 @@ dcm_perp: deviceConfig: prefix: X10SA-OP-DCM:TRX-CR2 deviceTags: - - dcm + - dcm enabled: true onFailure: buffer readoutPriority: baseline @@ -560,7 +558,7 @@ dcm_pitch: deviceConfig: prefix: X10SA-OP-DCM:ROTY-CR2-PITCH deviceTags: - - dcm + - dcm enabled: true onFailure: buffer readoutPriority: baseline @@ -572,7 +570,7 @@ dcm_x: deviceConfig: prefix: X10SA-OP-DCM:TRX deviceTags: - - dcm + - dcm enabled: true onFailure: buffer readoutPriority: baseline @@ -583,7 +581,7 @@ det_cov: auto_monitor: true read_pv: X10SA-ES-DETCOV:SET deviceTags: - - state + - state enabled: true onFailure: buffer readoutPriority: baseline @@ -597,7 +595,7 @@ det_xi_focus: deviceConfig: prefix: X10SA-ES-XEYE:FOCUS deviceTags: - - det + - det enabled: true onFailure: buffer readoutPriority: baseline @@ -607,7 +605,7 @@ det_xi_x: deviceConfig: prefix: X10SA-ES-XEYE:TRX deviceTags: - - det + - det enabled: true onFailure: buffer readoutPriority: baseline @@ -617,7 +615,7 @@ det_xi_zoom: deviceConfig: prefix: X10SA-ES-XEYE:ZOOM deviceTags: - - det + - det enabled: true onFailure: buffer readoutPriority: baseline @@ -627,7 +625,7 @@ det_y: deviceConfig: prefix: X10SA-ES-DET:TRY deviceTags: - - det + - det enabled: true onFailure: buffer readoutPriority: baseline @@ -640,7 +638,7 @@ det_z: deviceConfig: prefix: X10SA-ES-DET:TRZ deviceTags: - - det + - det enabled: true onFailure: buffer readoutPriority: baseline @@ -653,7 +651,7 @@ diag_y: deviceConfig: prefix: X10SA-ES-SCL:TRY deviceTags: - - state + - state enabled: true onFailure: buffer readoutPriority: baseline @@ -670,7 +668,7 @@ diag_z: deviceConfig: prefix: X10SA-ES-SCL:TRZ deviceTags: - - se + - se enabled: true onFailure: buffer readoutPriority: baseline @@ -681,7 +679,7 @@ fe_bpm1: auto_monitor: true read_pv: X10SA-FE-XBPM1:Current1:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -693,7 +691,7 @@ fe_bpm2: auto_monitor: true read_pv: X10SA-FE-XBPM1:Current2:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -705,7 +703,7 @@ fe_bpm3: auto_monitor: true read_pv: X10SA-FE-XBPM1:Current3:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -717,7 +715,7 @@ fe_bpm4: auto_monitor: true read_pv: X10SA-FE-XBPM1:Current4:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -728,7 +726,7 @@ fe_bpm_x: deviceConfig: prefix: X10SA-FE-XBPM1:TRX deviceTags: - - fe + - fe enabled: true onFailure: buffer readoutPriority: baseline @@ -738,7 +736,7 @@ fe_bpm_y: deviceConfig: prefix: X10SA-FE-XBPM1:TRY deviceTags: - - fe + - fe enabled: true onFailure: buffer readoutPriority: baseline @@ -749,7 +747,7 @@ fe_bpmsum: auto_monitor: true read_pv: X10SA-FE-XBPM1:SumAll:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -760,7 +758,7 @@ fe_sl_xcen: deviceConfig: prefix: X10SA-FE-SL1:CENTERX deviceTags: - - fe + - fe enabled: true onFailure: buffer readoutPriority: baseline @@ -770,7 +768,7 @@ fe_sl_xr: deviceConfig: prefix: X10SA-FE-SL1:TRXR deviceTags: - - fe + - fe enabled: true onFailure: buffer readoutPriority: baseline @@ -780,7 +778,7 @@ fe_sl_xsize: deviceConfig: prefix: X10SA-FE-SL1:SIZEX deviceTags: - - fe + - fe enabled: true onFailure: buffer readoutPriority: baseline @@ -790,7 +788,7 @@ fe_sl_xw: deviceConfig: prefix: X10SA-FE-SL1:TRXW deviceTags: - - fe + - fe enabled: true onFailure: buffer readoutPriority: baseline @@ -800,7 +798,7 @@ fe_sl_yb: deviceConfig: prefix: X10SA-FE-SL1:TRYB deviceTags: - - fe + - fe enabled: true onFailure: buffer readoutPriority: baseline @@ -810,7 +808,7 @@ fe_sl_ycen: deviceConfig: prefix: X10SA-FE-SL1:CENTERY deviceTags: - - fe + - fe enabled: true onFailure: buffer readoutPriority: baseline @@ -820,7 +818,7 @@ fe_sl_ysize: deviceConfig: prefix: X10SA-FE-SL1:SIZEY deviceTags: - - fe + - fe enabled: true onFailure: buffer readoutPriority: baseline @@ -830,7 +828,7 @@ fe_sl_yt: deviceConfig: prefix: X10SA-FE-SL1:TRYT deviceTags: - - fe + - fe enabled: true onFailure: buffer readoutPriority: baseline @@ -841,13 +839,13 @@ fl_bright: auto_monitor: true read_pv: X10SA-ES-FL:SET deviceTags: - - state + - state enabled: true onFailure: buffer readoutPriority: baseline userParameter: - 'off': 0.0 - 'on': 3.0 + "off": 0.0 + "on": 3.0 tol: 0.01 type: continuous hfm_bd: @@ -856,7 +854,7 @@ hfm_bd: deviceConfig: prefix: X10SA-ES-HFM:BNDD deviceTags: - - hfm + - hfm enabled: true onFailure: buffer readoutPriority: baseline @@ -866,7 +864,7 @@ hfm_bu: deviceConfig: prefix: X10SA-ES-HFM:BNDU deviceTags: - - hfm + - hfm enabled: true onFailure: buffer readoutPriority: baseline @@ -876,7 +874,7 @@ hfm_pitch: deviceConfig: prefix: X10SA-ES-HFM:PITCH deviceTags: - - hfm + - hfm enabled: true onFailure: buffer readoutPriority: baseline @@ -886,7 +884,7 @@ hfm_roll: deviceConfig: prefix: X10SA-ES-HFM:ROLL deviceTags: - - hfm + - hfm enabled: true onFailure: buffer readoutPriority: baseline @@ -896,7 +894,7 @@ hfm_x: deviceConfig: prefix: X10SA-ES-HFM:TRX deviceTags: - - hfm + - hfm enabled: true onFailure: buffer readoutPriority: baseline @@ -906,7 +904,7 @@ hfm_xd: deviceConfig: prefix: X10SA-ES-HFM:TRXD deviceTags: - - hfm + - hfm enabled: true onFailure: buffer readoutPriority: baseline @@ -916,7 +914,7 @@ hfm_xu: deviceConfig: prefix: X10SA-ES-HFM:TRXU deviceTags: - - hfm + - hfm enabled: true onFailure: buffer readoutPriority: baseline @@ -926,7 +924,7 @@ hfm_y: deviceConfig: prefix: X10SA-ES-HFM:TRY deviceTags: - - hfm + - hfm enabled: true onFailure: buffer readoutPriority: baseline @@ -936,7 +934,7 @@ hfm_yaw: deviceConfig: prefix: X10SA-ES-HFM:YAW deviceTags: - - hfm + - hfm enabled: true onFailure: buffer readoutPriority: baseline @@ -946,7 +944,7 @@ hfm_ydw: deviceConfig: prefix: X10SA-ES-HFM:TRYDW deviceTags: - - hfm + - hfm enabled: true onFailure: buffer readoutPriority: baseline @@ -956,7 +954,7 @@ hfm_yr: deviceConfig: prefix: X10SA-ES-HFM:TRYR deviceTags: - - hfm + - hfm enabled: true onFailure: buffer readoutPriority: baseline @@ -966,7 +964,7 @@ hfm_yuw: deviceConfig: prefix: X10SA-ES-HFM:TRYUW deviceTags: - - hfm + - hfm enabled: true onFailure: buffer readoutPriority: baseline @@ -977,7 +975,7 @@ i1: auto_monitor: true read_pv: X10SA-ES-SCLDI:READOUT deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -989,7 +987,7 @@ i2: auto_monitor: true read_pv: X10SA-ES-XEYEDI:READOUT deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -998,7 +996,7 @@ id_gap: description: undulator gap deviceClass: pxii_bec.devices.undulator.UndulatorGap deviceConfig: - prefix: 'X10SA-UIND:' + prefix: "X10SA-UIND:" enabled: true onFailure: buffer readoutPriority: baseline @@ -1009,7 +1007,7 @@ lu_bpm1: auto_monitor: true read_pv: X10SA-OP-LUBPM:Current1:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -1021,7 +1019,7 @@ lu_bpm2: auto_monitor: true read_pv: X10SA-OP-LUBPM:Current2:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -1033,7 +1031,7 @@ lu_bpm3: auto_monitor: true read_pv: X10SA-OP-LUBPM:Current3:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -1045,7 +1043,7 @@ lu_bpm4: auto_monitor: true read_pv: X10SA-OP-LUBPM:Current4:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -1056,7 +1054,7 @@ lu_bpm_x: deviceConfig: prefix: X10SA-OP-LUBPM:TRX deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1066,7 +1064,7 @@ lu_bpm_y: deviceConfig: prefix: X10SA-OP-LUBPM:TRY deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1077,7 +1075,7 @@ lu_bpmsum: auto_monitor: true read_pv: X10SA-OP-LUBPM:SumAll:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -1088,7 +1086,7 @@ lu_pod1_rotx: deviceConfig: prefix: X10SA-OP-LUPOD1:ROTX deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1098,7 +1096,7 @@ lu_pod1_roty: deviceConfig: prefix: X10SA-OP-LUPOD1:ROTY deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1108,7 +1106,7 @@ lu_pod1_rotz: deviceConfig: prefix: X10SA-OP-LUPOD1:ROTZ deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1118,7 +1116,7 @@ lu_pod1_y: deviceConfig: prefix: X10SA-OP-LUPOD1:TRY deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1128,7 +1126,7 @@ lu_pod1_z: deviceConfig: prefix: X10SA-OP-LUPOD1:TRZ deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1138,7 +1136,7 @@ lu_pod2_rotx: deviceConfig: prefix: X10SA-OP-LUPOD2:ROTX deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1148,7 +1146,7 @@ lu_pod2_roty: deviceConfig: prefix: X10SA-OP-LUPOD2:ROTY deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1158,7 +1156,7 @@ lu_pod2_rotz: deviceConfig: prefix: X10SA-OP-LUPOD2:ROTZ deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1168,7 +1166,7 @@ lu_pod2_y: deviceConfig: prefix: X10SA-OP-LUPOD2:TRY deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1178,7 +1176,7 @@ lu_pod2_z: deviceConfig: prefix: X10SA-OP-LUPOD2:TRZ deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1188,7 +1186,7 @@ lu_z1: deviceConfig: prefix: X10SA-OP-LUTRZ1:TRZ deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1198,7 +1196,7 @@ lu_z2: deviceConfig: prefix: X10SA-OP-LUTRZ2:TRZ deviceTags: - - lu + - lu enabled: true onFailure: buffer readoutPriority: baseline @@ -1209,7 +1207,7 @@ mag_ok: auto_monitor: true read_pv: X10SA-ES-DFS:CBOX-CMP1 deviceTags: - - se + - se enabled: true onFailure: buffer readOnly: true @@ -1221,7 +1219,7 @@ mag_rbv: auto_monitor: true read_pv: X10SA-ES-DFS:CBOX-USER1 deviceTags: - - se + - se enabled: true onFailure: buffer readOnly: true @@ -1233,7 +1231,7 @@ mag_ref: auto_monitor: true read_pv: X10SA-ES-DFS:CBOX-REFVAL1 deviceTags: - - se + - se enabled: true onFailure: buffer readOnly: true @@ -1242,7 +1240,7 @@ microscope_stats: description: Stats Signal of MS camera deviceClass: pxii_bec.devices.stats_signal.StatsSignal deviceConfig: - prefix: 'X10SA-ES-MS:' + prefix: "X10SA-ES-MS:" enabled: true readoutPriority: async softwareTrigger: true @@ -1253,7 +1251,7 @@ samcam_ecc: auto_monitor: true read_pv: X10SA-ES-MS:Stats5:Eccentricity_RBV deviceTags: - - scam + - scam enabled: true onFailure: buffer readOnly: true @@ -1265,7 +1263,7 @@ samcam_exp: auto_monitor: true read_pv: X10SA-ES-MS:cam1:AcquireTime deviceTags: - - scam + - scam enabled: true onFailure: buffer readoutPriority: baseline @@ -1276,7 +1274,7 @@ samcam_gain: auto_monitor: true read_pv: X10SA-ES-MS:cam1:Gain deviceTags: - - scam + - scam enabled: true onFailure: buffer readoutPriority: baseline @@ -1287,7 +1285,7 @@ samcam_max: auto_monitor: true read_pv: X10SA-ES-MS:Stats5:MaxValue_RBV deviceTags: - - scam + - scam enabled: true onFailure: buffer readOnly: true @@ -1299,7 +1297,7 @@ samcam_mean: auto_monitor: true read_pv: X10SA-ES-MS:Stats1:MeanValue_RBV deviceTags: - - scam + - scam enabled: true onFailure: buffer readOnly: true @@ -1311,7 +1309,7 @@ samcam_sigma: auto_monitor: true read_pv: X10SA-ES-MS:Stats1:Sigma_RBV deviceTags: - - scam + - scam enabled: true onFailure: buffer readOnly: true @@ -1323,7 +1321,7 @@ samcam_thresh: auto_monitor: true read_pv: X10SA-ES-MS:Stats5:CentroidThreshold deviceTags: - - scam + - scam enabled: true onFailure: buffer readoutPriority: baseline @@ -1334,7 +1332,7 @@ samcam_x: auto_monitor: true read_pv: X10SA-ES-MS:Stats5:CentroidX_RBV deviceTags: - - scam + - scam enabled: true onFailure: buffer readOnly: true @@ -1346,7 +1344,7 @@ samcam_xcurs: auto_monitor: true read_pv: X10SA-ES-MS:Stats5:CursorX deviceTags: - - scam + - scam enabled: true onFailure: buffer readoutPriority: baseline @@ -1357,7 +1355,7 @@ samcam_xcursprof: auto_monitor: true read_pv: X10SA-ES-MS:Stats5:ProfileCursorX_RBV deviceTags: - - scam + - scam enabled: true onFailure: buffer readOnly: true @@ -1369,7 +1367,7 @@ samcam_xsig: auto_monitor: true read_pv: X10SA-ES-MS:Stats5:SigmaX_RBV deviceTags: - - scam + - scam enabled: true onFailure: buffer readOnly: true @@ -1381,7 +1379,7 @@ samcam_y: auto_monitor: true read_pv: X10SA-ES-MS:Stats5:CentroidY_RBV deviceTags: - - scam + - scam enabled: true onFailure: buffer readOnly: true @@ -1393,7 +1391,7 @@ samcam_ycursprof: auto_monitor: true read_pv: X10SA-ES-MS:Stats5:ProfileCursorY_RBV deviceTags: - - scam + - scam enabled: true onFailure: buffer readOnly: true @@ -1405,7 +1403,7 @@ samcam_ysig: auto_monitor: true read_pv: X10SA-ES-MS:Stats5:SigmaY_RBV deviceTags: - - scam + - scam enabled: true onFailure: buffer readOnly: true @@ -1414,9 +1412,9 @@ scam: description: Sample camera image contrast deviceClass: pxii_bec.devices.contrast.CameraContrast deviceConfig: - prefix: 'X10SA-ES-MS:Stats1:' + prefix: "X10SA-ES-MS:Stats1:" deviceTags: - - detector + - detector enabled: true readOnly: true readoutPriority: monitored @@ -1426,7 +1424,7 @@ scam_zoom: deviceConfig: prefix: X10SA-ES-MS:ZOOM deviceTags: - - scam + - scam enabled: true onFailure: buffer readoutPriority: baseline @@ -1437,7 +1435,7 @@ sls_current: auto_monitor: true read_pv: ARS07-DPCT-0100:CURR deviceTags: - - SLS + - SLS enabled: true onFailure: buffer readOnly: true @@ -1448,8 +1446,8 @@ smargon: deviceConfig: prefix: http://x10sa-smargopolo.psi.ch:3000 deviceTags: - - motors - - smargon + - motors + - smargon enabled: true onFailure: buffer readoutPriority: baseline @@ -1471,7 +1469,7 @@ ss_bpm1: auto_monitor: true read_pv: X10SA-ES-SSBPM:Current1:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -1483,7 +1481,7 @@ ss_bpm2: auto_monitor: true read_pv: X10SA-ES-SSBPM:Current2:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -1495,7 +1493,7 @@ ss_bpm3: auto_monitor: true read_pv: X10SA-ES-SSBPM:Current3:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -1507,7 +1505,7 @@ ss_bpm4: auto_monitor: true read_pv: X10SA-ES-SSBPM:Current4:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -1518,7 +1516,7 @@ ss_bpm_x: deviceConfig: prefix: X10SA-ES-SSBPM:TRX deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1528,7 +1526,7 @@ ss_bpm_y: deviceConfig: prefix: X10SA-ES-SSBPM:TRY deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1539,7 +1537,7 @@ ss_bpmsum: auto_monitor: true read_pv: X10SA-ES-SSBPM:SumAll:MeanValue_RBV deviceTags: - - bpm + - bpm enabled: true onFailure: buffer readOnly: true @@ -1550,7 +1548,7 @@ ss_f1_x: deviceConfig: prefix: X10SA-ES-SSFI1:TRX deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1560,7 +1558,7 @@ ss_f2_x: deviceConfig: prefix: X10SA-ES-SSFI2:TRX deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1570,7 +1568,7 @@ ss_f3_x: deviceConfig: prefix: X10SA-ES-SSFI3:TRX deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1580,7 +1578,7 @@ ss_f4_x: deviceConfig: prefix: X10SA-ES-SSFI4:TRX deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1590,7 +1588,7 @@ ss_sl_xcen: deviceConfig: prefix: X10SA-ES-SSSLH:CENTER deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1600,7 +1598,7 @@ ss_sl_xr: deviceConfig: prefix: X10SA-ES-SSSLH:TRXR deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1610,7 +1608,7 @@ ss_sl_xsize: deviceConfig: prefix: X10SA-ES-SSSLH:SIZE deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1620,7 +1618,7 @@ ss_sl_xw: deviceConfig: prefix: X10SA-ES-SSSLH:TRXW deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1630,7 +1628,7 @@ ss_sl_yb: deviceConfig: prefix: X10SA-ES-SSSLV:TRYB deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1640,7 +1638,7 @@ ss_sl_ycen: deviceConfig: prefix: X10SA-ES-SSSLV:CENTER deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1650,7 +1648,7 @@ ss_sl_ysize: deviceConfig: prefix: X10SA-ES-SSSLV:SIZE deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1660,7 +1658,7 @@ ss_sl_yt: deviceConfig: prefix: X10SA-ES-SSSLV:TRYT deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1670,7 +1668,7 @@ ss_xi_x: deviceConfig: prefix: X10SA-ES-SSXI:TRX deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1684,7 +1682,7 @@ ss_xi_y: deviceConfig: prefix: X10SA-ES-SSXI:TRY deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1695,7 +1693,7 @@ ss_xicam_exp: auto_monitor: true read_pv: X10SA-ES-SSCAM:cam1:AcquireTime deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1706,7 +1704,7 @@ ss_xicam_gain: auto_monitor: true read_pv: X10SA-ES-SSCAM:cam1:Gain deviceTags: - - ss + - ss enabled: true onFailure: buffer readoutPriority: baseline @@ -1717,7 +1715,7 @@ ss_xicam_max: auto_monitor: true read_pv: X10SA-ES-SSCAM:Stats5:MaxValue_RBV deviceTags: - - ss + - ss enabled: true onFailure: buffer readOnly: true @@ -1729,7 +1727,7 @@ ss_xicam_x: auto_monitor: true read_pv: X10SA-ES-SSCAM:Stats5:CentroidX_RBV deviceTags: - - ss + - ss enabled: true onFailure: buffer readOnly: true @@ -1741,7 +1739,7 @@ ss_xicam_xsig: auto_monitor: true read_pv: X10SA-ES-SSCAM:Stats5:SigmaX_RBV deviceTags: - - ss + - ss enabled: true onFailure: buffer readOnly: true @@ -1753,7 +1751,7 @@ ss_xicam_y: auto_monitor: true read_pv: X10SA-ES-SSCAM:Stats5:CentroidY_RBV deviceTags: - - ss + - ss enabled: true onFailure: buffer readOnly: true @@ -1765,7 +1763,7 @@ ss_xicam_ysig: auto_monitor: true read_pv: X10SA-ES-SSCAM:Stats5:SigmaY_RBV deviceTags: - - ss + - ss enabled: true onFailure: buffer readOnly: true @@ -1776,7 +1774,7 @@ transm: deviceConfig: read_pv: X10SA-ES-SSFI:TRANSM-SET deviceTags: - - transm + - transm enabled: true readoutPriority: baseline vfm_bd: @@ -1785,7 +1783,7 @@ vfm_bd: deviceConfig: prefix: X10SA-ES-VFM:BNDD deviceTags: - - vfm + - vfm enabled: true onFailure: buffer readoutPriority: baseline @@ -1795,7 +1793,7 @@ vfm_bu: deviceConfig: prefix: X10SA-ES-VFM:BNDU deviceTags: - - vfm + - vfm enabled: true onFailure: buffer readoutPriority: baseline @@ -1805,7 +1803,7 @@ vfm_pitch: deviceConfig: prefix: X10SA-ES-VFM:PITCH deviceTags: - - vfm + - vfm enabled: true onFailure: buffer readoutPriority: baseline @@ -1815,7 +1813,7 @@ vfm_roll: deviceConfig: prefix: X10SA-ES-VFM:ROLL deviceTags: - - vfm + - vfm enabled: true onFailure: buffer readoutPriority: baseline @@ -1825,7 +1823,7 @@ vfm_x: deviceConfig: prefix: X10SA-ES-VFM:TRX deviceTags: - - vfm + - vfm enabled: true onFailure: buffer readoutPriority: baseline @@ -1835,7 +1833,7 @@ vfm_xd: deviceConfig: prefix: X10SA-ES-VFM:TRXD deviceTags: - - vfm + - vfm enabled: true onFailure: buffer readoutPriority: baseline @@ -1845,7 +1843,7 @@ vfm_xu: deviceConfig: prefix: X10SA-ES-VFM:TRXU deviceTags: - - vfm + - vfm enabled: true onFailure: buffer readoutPriority: baseline @@ -1855,7 +1853,7 @@ vfm_y: deviceConfig: prefix: X10SA-ES-VFM:TRY deviceTags: - - vfm + - vfm enabled: true onFailure: buffer readoutPriority: baseline @@ -1865,7 +1863,7 @@ vfm_yaw: deviceConfig: prefix: X10SA-ES-VFM:YAW deviceTags: - - vfm + - vfm enabled: true onFailure: buffer readoutPriority: baseline @@ -1875,7 +1873,7 @@ vfm_ydr: deviceConfig: prefix: X10SA-ES-VFM:TRYDR deviceTags: - - vfm + - vfm enabled: true onFailure: buffer readoutPriority: baseline @@ -1885,7 +1883,7 @@ vfm_yur: deviceConfig: prefix: X10SA-ES-VFM:TRYUR deviceTags: - - vfm + - vfm enabled: true onFailure: buffer readoutPriority: baseline @@ -1895,7 +1893,7 @@ vfm_yw: deviceConfig: prefix: X10SA-ES-VFM:TRYW deviceTags: - - vfm + - vfm enabled: true onFailure: buffer readoutPriority: baseline @@ -1905,7 +1903,7 @@ xi_focus: deviceConfig: prefix: X10SA-ES-XEYE:FOCUS deviceTags: - - xeye + - xeye enabled: true onFailure: buffer readoutPriority: baseline @@ -1915,7 +1913,7 @@ xi_x: deviceConfig: prefix: X10SA-ES-XEYE:TRX deviceTags: - - xeye + - xeye enabled: true onFailure: buffer readoutPriority: baseline @@ -1925,7 +1923,7 @@ xi_zoom: deviceConfig: prefix: X10SA-ES-XEYE:ZOOM deviceTags: - - xeye + - xeye enabled: true onFailure: buffer readoutPriority: baseline @@ -1936,7 +1934,7 @@ xidiode: auto_monitor: true read_pv: X10SA-ES-XEYEDI:READOUT deviceTags: - - xeye + - xeye enabled: true onFailure: buffer readOnly: true @@ -1948,7 +1946,7 @@ xrf_pos: auto_monitor: true read_pv: X10SA-ES-XRF:POS-SET deviceTags: - - state + - state enabled: true onFailure: buffer readoutPriority: baseline diff --git a/pxii_bec/scripts/init_beamline.py b/pxii_bec/scripts/init_beamline.py index 39e25d7..57549fc 100755 --- a/pxii_bec/scripts/init_beamline.py +++ b/pxii_bec/scripts/init_beamline.py @@ -1,10 +1,15 @@ """Initialise sample environment devices and beamline states.""" -import os import importlib +import os from dataclasses import dataclass from pathlib import Path +from pxii_bec.macros.beamline_planner import StateChangePlanner +from pxii_bec.macros.beamline_state_manager import DefineStatesManager +from pxii_bec.macros.dependencies import planner_deps +from pxii_bec.macros.devices_manager import DeviceManager + @dataclass class Environment: @@ -39,7 +44,7 @@ class Environment: if self.beamline not in self.beamline_configs: raise ValueError( - f"Unknown beamline '{self.beamline}'. " f"Choose from {list(self.beamline_configs)}" + f"Unknown beamline '{self.beamline}'. Choose from {list(self.beamline_configs)}" ) cfg = self.beamline_configs[self.beamline] diff --git a/pyproject.toml b/pyproject.toml index b5d968d..fd7e7a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,10 +60,10 @@ plugin_widgets_update = "pxii_bec.bec_widgets.auto_updates" plugin_widgets = "pxii_bec.bec_widgets.widgets" [project.entry-points."bec.messages"] -plugin_scans = "pxii_bec.messages" +plugin_messages = "pxii_bec.messages" [project.entry-points."bec.bl_states"] -plugin_scans = "pxii_bec.states" +plugin_bl_states = "pxii_bec.states" [tool.hatch.build.targets.wheel] include = ["*"] -- 2.54.1 From 417db43d6bc7140711a13c61623beefce66dd901 Mon Sep 17 00:00:00 2001 From: David Perl Date: Tue, 10 Nov 2026 09:32:36 +0100 Subject: [PATCH 09/10] feat: spreadsheet display hax --- pxii_bec/bec_widgets/widgets/client.py | 23 ++++++++ .../bec_widgets/widgets/designer_plugins.py | 2 + pxii_bec/bec_widgets/widgets/imported.py | 4 ++ .../px_ii_spreadsheet_display.pyproject | 1 + .../px_ii_spreadsheet_display_plugin.py | 57 +++++++++++++++++++ .../register_px_ii_spreadsheet_display.py | 15 +++++ 6 files changed, 102 insertions(+) create mode 100644 pxii_bec/bec_widgets/widgets/px_ii_spreadsheet_display.pyproject create mode 100644 pxii_bec/bec_widgets/widgets/px_ii_spreadsheet_display_plugin.py create mode 100644 pxii_bec/bec_widgets/widgets/register_px_ii_spreadsheet_display.py diff --git a/pxii_bec/bec_widgets/widgets/client.py b/pxii_bec/bec_widgets/widgets/client.py index c09931d..db67679 100644 --- a/pxii_bec/bec_widgets/widgets/client.py +++ b/pxii_bec/bec_widgets/widgets/client.py @@ -14,6 +14,7 @@ logger = bec_logger.logger _Widgets = { "PxIIActorConfigWiget": "PxIIActorConfigWiget", + "PxIISpreadsheetDisplay": "PxIISpreadsheetDisplay", "PxIITaskPanel": "PxIITaskPanel", "PxIITaskQueueWidget": "PxIITaskQueueWidget", "ScanHistory": "ScanHistory", @@ -30,6 +31,28 @@ class PxIIActorConfigWiget(RPCBase): """ +class PxIISpreadsheetDisplay(RPCBase): + _IMPORT_MODULE = "pxii_bec.bec_widgets.widgets.imported" + + @rpc_call + def remove(self): + """ + Cleanup the BECConnector + """ + + @rpc_call + def attach(self): + """ + None + """ + + @rpc_call + def detach(self): + """ + Detach the widget from its parent dock widget (if widget is in the dock), making it a floating widget. + """ + + class PxIITaskPanel(RPCBase): _IMPORT_MODULE = "pxii_bec.bec_widgets.widgets.imported" diff --git a/pxii_bec/bec_widgets/widgets/designer_plugins.py b/pxii_bec/bec_widgets/widgets/designer_plugins.py index ec9f16c..7b4a3e1 100644 --- a/pxii_bec/bec_widgets/widgets/designer_plugins.py +++ b/pxii_bec/bec_widgets/widgets/designer_plugins.py @@ -6,6 +6,7 @@ from __future__ import annotations designer_plugins = { "PxIIActorConfigWiget": ("pxii_bec.bec_widgets.widgets.imported", "PxIIActorConfigWiget"), + "PxIISpreadsheetDisplay": ("pxii_bec.bec_widgets.widgets.imported", "PxIISpreadsheetDisplay"), "PxIITaskPanel": ("pxii_bec.bec_widgets.widgets.imported", "PxIITaskPanel"), "PxIITaskQueueWidget": ("pxii_bec.bec_widgets.widgets.imported", "PxIITaskQueueWidget"), "ScanHistory": ("pxii_bec.bec_widgets.widgets.scan_history.scan_history", "ScanHistory"), @@ -13,6 +14,7 @@ designer_plugins = { widget_icons = { "PxIIActorConfigWiget": "format_list_bulleted", + "PxIISpreadsheetDisplay": "format_list_bulleted", "PxIITaskPanel": "play_arrow", "PxIITaskQueueWidget": "pending_actions", "ScanHistory": "widgets", diff --git a/pxii_bec/bec_widgets/widgets/imported.py b/pxii_bec/bec_widgets/widgets/imported.py index c229118..6b7b3cb 100644 --- a/pxii_bec/bec_widgets/widgets/imported.py +++ b/pxii_bec/bec_widgets/widgets/imported.py @@ -1,4 +1,5 @@ from mx_bec.bec_widgets.widgets.aare_bec.actors_config import MxActorConfigWidget +from mx_bec.bec_widgets.widgets.aare_bec.sample_spreadsheet_display import SampleSpreadsheetDisplay from mx_bec.bec_widgets.widgets.aare_bec.task_panel import MxTaskPanel from mx_bec.bec_widgets.widgets.aare_bec.task_queue import MxTaskQueueWidget @@ -10,3 +11,6 @@ class PxIITaskQueueWidget(MxTaskQueueWidget): ... class PxIITaskPanel(MxTaskPanel): ... + + +class PxIISpreadsheetDisplay(SampleSpreadsheetDisplay): ... diff --git a/pxii_bec/bec_widgets/widgets/px_ii_spreadsheet_display.pyproject b/pxii_bec/bec_widgets/widgets/px_ii_spreadsheet_display.pyproject new file mode 100644 index 0000000..4cbb48d --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/px_ii_spreadsheet_display.pyproject @@ -0,0 +1 @@ +{'files': ['imported.py']} \ No newline at end of file diff --git a/pxii_bec/bec_widgets/widgets/px_ii_spreadsheet_display_plugin.py b/pxii_bec/bec_widgets/widgets/px_ii_spreadsheet_display_plugin.py new file mode 100644 index 0000000..3a8323a --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/px_ii_spreadsheet_display_plugin.py @@ -0,0 +1,57 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +from qtpy.QtDesigner import QDesignerCustomWidgetInterface +from qtpy.QtWidgets import QWidget + +from bec_widgets.utils.bec_designer import designer_material_icon +from pxii_bec.bec_widgets.widgets.imported import PxIISpreadsheetDisplay + +DOM_XML = """ + + + + +""" + + +class PxIISpreadsheetDisplayPlugin(QDesignerCustomWidgetInterface): # pragma: no cover + def __init__(self): + super().__init__() + self._form_editor = None + + def createWidget(self, parent): + if parent is None: + return QWidget() + t = PxIISpreadsheetDisplay(parent) + return t + + def domXml(self): + return DOM_XML + + def group(self): + return "" + + def icon(self): + return designer_material_icon(PxIISpreadsheetDisplay.ICON_NAME) + + def includeFile(self): + return "px_ii_spreadsheet_display" + + def initialize(self, form_editor): + self._form_editor = form_editor + + def isContainer(self): + return False + + def isInitialized(self): + return self._form_editor is not None + + def name(self): + return "PxIISpreadsheetDisplay" + + def toolTip(self): + return "PxIISpreadsheetDisplay" + + def whatsThis(self): + return self.toolTip() diff --git a/pxii_bec/bec_widgets/widgets/register_px_ii_spreadsheet_display.py b/pxii_bec/bec_widgets/widgets/register_px_ii_spreadsheet_display.py new file mode 100644 index 0000000..f47b096 --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/register_px_ii_spreadsheet_display.py @@ -0,0 +1,15 @@ +def main(): # pragma: no cover + from qtpy import PYSIDE6 + + if not PYSIDE6: + print("PYSIDE6 is not available in the environment. Cannot patch designer.") + return + from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection + + from pxii_bec.bec_widgets.widgets.px_ii_spreadsheet_display_plugin import PxIISpreadsheetDisplayPlugin + + QPyDesignerCustomWidgetCollection.addCustomWidget(PxIISpreadsheetDisplayPlugin()) + + +if __name__ == "__main__": # pragma: no cover + main() -- 2.54.1 From ee52a6f2ce2a0cd26dac96369edcf5c4c5d59470 Mon Sep 17 00:00:00 2001 From: x10sa Date: Fri, 13 Nov 2026 13:44:41 +0100 Subject: [PATCH 10/10] sample queue widget --- pxii_bec/bec_widgets/widgets/client.py | 23 ++++++++ .../bec_widgets/widgets/designer_plugins.py | 2 + pxii_bec/bec_widgets/widgets/imported.py | 14 +++-- .../px_ii_sample_queue_widget.pyproject | 1 + .../px_ii_sample_queue_widget_plugin.py | 57 +++++++++++++++++++ .../register_px_ii_sample_queue_widget.py | 15 +++++ pxii_bec/messages.py | 6 +- 7 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 pxii_bec/bec_widgets/widgets/px_ii_sample_queue_widget.pyproject create mode 100644 pxii_bec/bec_widgets/widgets/px_ii_sample_queue_widget_plugin.py create mode 100644 pxii_bec/bec_widgets/widgets/register_px_ii_sample_queue_widget.py diff --git a/pxii_bec/bec_widgets/widgets/client.py b/pxii_bec/bec_widgets/widgets/client.py index db67679..ec1bfbc 100644 --- a/pxii_bec/bec_widgets/widgets/client.py +++ b/pxii_bec/bec_widgets/widgets/client.py @@ -14,6 +14,7 @@ logger = bec_logger.logger _Widgets = { "PxIIActorConfigWiget": "PxIIActorConfigWiget", + "PxIISampleQueueWidget": "PxIISampleQueueWidget", "PxIISpreadsheetDisplay": "PxIISpreadsheetDisplay", "PxIITaskPanel": "PxIITaskPanel", "PxIITaskQueueWidget": "PxIITaskQueueWidget", @@ -31,6 +32,22 @@ class PxIIActorConfigWiget(RPCBase): """ +class PxIISampleQueueWidget(RPCBase): + _IMPORT_MODULE = "pxii_bec.bec_widgets.widgets.imported" + + @rpc_call + def refresh(self): + """ + Reload the queued samples from Redis. + """ + + @rpc_call + def clear_queue(self): + """ + Delete the queue contents + """ + + class PxIISpreadsheetDisplay(RPCBase): _IMPORT_MODULE = "pxii_bec.bec_widgets.widgets.imported" @@ -72,6 +89,12 @@ class PxIITaskQueueWidget(RPCBase): Reload the queued tasks from Redis. """ + @rpc_call + def clear_queue(self): + """ + Delete the queue contents + """ + class ScanHistory(RPCBase): _IMPORT_MODULE = "pxii_bec.bec_widgets.widgets.scan_history.scan_history" diff --git a/pxii_bec/bec_widgets/widgets/designer_plugins.py b/pxii_bec/bec_widgets/widgets/designer_plugins.py index 7b4a3e1..c19874e 100644 --- a/pxii_bec/bec_widgets/widgets/designer_plugins.py +++ b/pxii_bec/bec_widgets/widgets/designer_plugins.py @@ -6,6 +6,7 @@ from __future__ import annotations designer_plugins = { "PxIIActorConfigWiget": ("pxii_bec.bec_widgets.widgets.imported", "PxIIActorConfigWiget"), + "PxIISampleQueueWidget": ("pxii_bec.bec_widgets.widgets.imported", "PxIISampleQueueWidget"), "PxIISpreadsheetDisplay": ("pxii_bec.bec_widgets.widgets.imported", "PxIISpreadsheetDisplay"), "PxIITaskPanel": ("pxii_bec.bec_widgets.widgets.imported", "PxIITaskPanel"), "PxIITaskQueueWidget": ("pxii_bec.bec_widgets.widgets.imported", "PxIITaskQueueWidget"), @@ -14,6 +15,7 @@ designer_plugins = { widget_icons = { "PxIIActorConfigWiget": "format_list_bulleted", + "PxIISampleQueueWidget": "pending_actions", "PxIISpreadsheetDisplay": "format_list_bulleted", "PxIITaskPanel": "play_arrow", "PxIITaskQueueWidget": "pending_actions", diff --git a/pxii_bec/bec_widgets/widgets/imported.py b/pxii_bec/bec_widgets/widgets/imported.py index 6b7b3cb..59cb071 100644 --- a/pxii_bec/bec_widgets/widgets/imported.py +++ b/pxii_bec/bec_widgets/widgets/imported.py @@ -1,7 +1,10 @@ -from mx_bec.bec_widgets.widgets.aare_bec.actors_config import MxActorConfigWidget -from mx_bec.bec_widgets.widgets.aare_bec.sample_spreadsheet_display import SampleSpreadsheetDisplay -from mx_bec.bec_widgets.widgets.aare_bec.task_panel import MxTaskPanel -from mx_bec.bec_widgets.widgets.aare_bec.task_queue import MxTaskQueueWidget +from mx_bec.bec_widgets.widgets.aare_bec import ( + MxActorConfigWidget, + MxTaskPanel, + MxTaskQueueWidget, + SampleQueueWidget, + SampleSpreadsheetDisplay, +) class PxIIActorConfigWiget(MxActorConfigWidget): ... @@ -10,6 +13,9 @@ class PxIIActorConfigWiget(MxActorConfigWidget): ... class PxIITaskQueueWidget(MxTaskQueueWidget): ... +class PxIISampleQueueWidget(SampleQueueWidget): ... + + class PxIITaskPanel(MxTaskPanel): ... diff --git a/pxii_bec/bec_widgets/widgets/px_ii_sample_queue_widget.pyproject b/pxii_bec/bec_widgets/widgets/px_ii_sample_queue_widget.pyproject new file mode 100644 index 0000000..4cbb48d --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/px_ii_sample_queue_widget.pyproject @@ -0,0 +1 @@ +{'files': ['imported.py']} \ No newline at end of file diff --git a/pxii_bec/bec_widgets/widgets/px_ii_sample_queue_widget_plugin.py b/pxii_bec/bec_widgets/widgets/px_ii_sample_queue_widget_plugin.py new file mode 100644 index 0000000..8868fa0 --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/px_ii_sample_queue_widget_plugin.py @@ -0,0 +1,57 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +from qtpy.QtDesigner import QDesignerCustomWidgetInterface +from qtpy.QtWidgets import QWidget + +from bec_widgets.utils.bec_designer import designer_material_icon +from pxii_bec.bec_widgets.widgets.imported import PxIISampleQueueWidget + +DOM_XML = """ + + + + +""" + + +class PxIISampleQueueWidgetPlugin(QDesignerCustomWidgetInterface): # pragma: no cover + def __init__(self): + super().__init__() + self._form_editor = None + + def createWidget(self, parent): + if parent is None: + return QWidget() + t = PxIISampleQueueWidget(parent) + return t + + def domXml(self): + return DOM_XML + + def group(self): + return "" + + def icon(self): + return designer_material_icon(PxIISampleQueueWidget.ICON_NAME) + + def includeFile(self): + return "px_ii_sample_queue_widget" + + def initialize(self, form_editor): + self._form_editor = form_editor + + def isContainer(self): + return False + + def isInitialized(self): + return self._form_editor is not None + + def name(self): + return "PxIISampleQueueWidget" + + def toolTip(self): + return "PxIISampleQueueWidget" + + def whatsThis(self): + return self.toolTip() diff --git a/pxii_bec/bec_widgets/widgets/register_px_ii_sample_queue_widget.py b/pxii_bec/bec_widgets/widgets/register_px_ii_sample_queue_widget.py new file mode 100644 index 0000000..effa8d7 --- /dev/null +++ b/pxii_bec/bec_widgets/widgets/register_px_ii_sample_queue_widget.py @@ -0,0 +1,15 @@ +def main(): # pragma: no cover + from qtpy import PYSIDE6 + + if not PYSIDE6: + print("PYSIDE6 is not available in the environment. Cannot patch designer.") + return + from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection + + from pxii_bec.bec_widgets.widgets.px_ii_sample_queue_widget_plugin import PxIISampleQueueWidgetPlugin + + QPyDesignerCustomWidgetCollection.addCustomWidget(PxIISampleQueueWidgetPlugin()) + + +if __name__ == "__main__": # pragma: no cover + main() diff --git a/pxii_bec/messages.py b/pxii_bec/messages.py index faaeee5..5cefdde 100644 --- a/pxii_bec/messages.py +++ b/pxii_bec/messages.py @@ -3,14 +3,16 @@ find them through the `bec.messages` entry point registered by this package.""" from mx_bec.messages import ( MXMeasurementSequenceMessage, + MXQueueChangedMessage, + MXSampleExecutionMessage, MXTaskExecutionMessage, - MXTaskQueueChangedMessage, OpticalPredictionMessage, ) __all__ = [ "MXMeasurementSequenceMessage", "MXTaskExecutionMessage", - "MXTaskQueueChangedMessage", + "MXSampleExecutionMessage", + "MXQueueChangedMessage", "OpticalPredictionMessage", ] -- 2.54.1