fix(xray_eye): use the public Image interface for the live view
CI for csaxs_bec / test (push) Successful in 3m51s
CI for csaxs_bec / test (pull_request) Successful in 3m45s

This commit is contained in:
wyzula_j committed 2026-11-17 14:07:27 +01:00
1 parent fb6e9a2163
commit c7e369cfdb
2 files changed
+85 -3

No files matched your search

@@ -1253,7 +1253,9 @@ class OMNY_XRayEye(BECWidget, QWidget):
self.live_preview_toggle.blockSignals(False)
return
self.image.disconnect_monitor(CAMERA[0], self._live_view_signal)
# An empty device disconnects the current monitor. This is the public way that
# every bec_widgets version has; Image.disconnect_monitor is gone with the DataAPI.
self.image.image(device="", signal="")
self.live_preview_toggle.checked = enabled
self.live_preview_toggle.blockSignals(False)
@@ -1263,7 +1265,7 @@ class OMNY_XRayEye(BECWidget, QWidget):
channel self.image is currently displaying -- see the permanent
subscription set up in __init__ and the note in
set_live_view_signal() about why this is needed."""
data = self.image._get_payload_data(msg) # pylint: disable=protected-access
data = msg.get("data") # the payload of a device_preview message
if data is not None:
self._last_smear_composite = data
@@ -1278,8 +1280,8 @@ class OMNY_XRayEye(BECWidget, QWidget):
changes here unless a caller explicitly requests it.
"""
if signal != self._live_view_signal:
self.image.disconnect_monitor(CAMERA[0], self._live_view_signal)
self._live_view_signal = signal
# image() disconnects the monitor it has before it connects the new one.
self.image.image(device=CAMERA[0], signal=signal)
if hasattr(self.image, "_autorange_on_next_update"):
self.image._autorange_on_next_update = False
@@ -0,0 +1,80 @@
"""Tests for the live view of OMNY_XRayEye: it uses only the public interface of the
bec_widgets Image (``image(device, signal)``), so it works with the Image before and after
its move to the BEC DataAPI, where ``disconnect_monitor`` and ``_get_payload_data`` are gone.
The slots are exercised on a minimal stub instead of the full widget, which needs a live BEC
client context via get_bec_shortcuts() -- same approach as test_x_ray_eye_skip_button.py.
"""
from unittest import mock
import numpy as np
from csaxs_bec.bec_widgets.widgets.xray_eye.x_ray_eye import CAMERA, OMNY_XRayEye
class _Image:
"""Only what every Image version offers; anything else raises AttributeError."""
def __init__(self):
self.calls = []
self.main_image = mock.Mock()
def image(self, device=None, signal=None):
self.calls.append((device, signal))
class _Toggle:
checked = False
def blockSignals(self, _blocked):
pass
class _StubXRayEye:
on_live_view_enabled = OMNY_XRayEye.on_live_view_enabled
set_live_view_signal = OMNY_XRayEye.set_live_view_signal
_on_smear_preview_cached_update = OMNY_XRayEye._on_smear_preview_cached_update
def _make_stub():
stub = _StubXRayEye()
stub.image = _Image()
stub.live_preview_toggle = _Toggle()
stub.smear_preview_toggle = _Toggle()
stub._live_view_signal = CAMERA[1]
stub._last_smear_composite = None
stub._manual_toggle_blocked_by_queue = lambda: False
return stub
def test_live_view_is_switched_on_and_off_through_image():
stub = _make_stub()
stub.on_live_view_enabled(True)
stub.on_live_view_enabled(False)
assert stub.image.calls == [(CAMERA[0], CAMERA[1]), ("", "")]
assert stub.live_preview_toggle.checked is False
def test_switching_the_live_view_signal_reconnects_once():
stub = _make_stub()
stub.set_live_view_signal("smear_preview")
assert stub.image.calls == [(CAMERA[0], "smear_preview")]
assert stub._live_view_signal == "smear_preview"
assert stub.smear_preview_toggle.checked is True
def test_smear_preview_is_cached_from_the_preview_message_and_shown_on_switch():
stub = _make_stub()
composite = np.arange(6).reshape(2, 3)
stub._on_smear_preview_cached_update({"data": composite}, {})
stub._on_smear_preview_cached_update({}, {}) # a message without data keeps the cache
stub.set_live_view_signal("smear_preview")
assert stub._last_smear_composite is composite
stub.image.main_image.set_data.assert_called_once_with(composite)