fix(xray_eye): use the public Image interface for the live view #356
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
|
||||
|
||||
@@ -33,7 +33,10 @@ def dialog(qapp):
|
||||
client = mock.MagicMock()
|
||||
client.get_global_var.return_value = registry
|
||||
client.device_manager.devices = {"keithley": mock.MagicMock(limits=(0.0, 3.0))}
|
||||
return CommandJobBuilderDialog(client)
|
||||
builder = CommandJobBuilderDialog(client)
|
||||
yield builder
|
||||
builder.close()
|
||||
builder.deleteLater()
|
||||
|
||||
|
||||
def _add_step(dialog, action, **values):
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
"""Tests for the live view of OMNY_XRayEye.
|
||||
|
||||
The X-ray eye drives its embedded bec_widgets Image only through the public
|
||||
``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`` no longer exist.
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
from bec_widgets.tests.fake_devices import FakeDevice
|
||||
from bec_widgets.tests.fixtures import * # noqa: F401,F403 the shared widget test bed
|
||||
from bec_widgets.tests.utils import create_widget
|
||||
|
||||
from csaxs_bec.bec_widgets.widgets.xray_eye.x_ray_eye import CAMERA, OMNY_XRayEye
|
||||
|
||||
# pylint: disable=protected-access,redefined-outer-name
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def xray_eye(qtbot, mocked_client, monkeypatch):
|
||||
"""The X-ray eye on a client that has the camera with its two 2D preview signals."""
|
||||
camera = FakeDevice(CAMERA[0])
|
||||
for signal in (CAMERA[1], "smear_preview"):
|
||||
camera._info["signals"][signal] = {
|
||||
"obj_name": signal,
|
||||
"signal_class": "PreviewSignal",
|
||||
"component_name": signal,
|
||||
"describe": {"signal_info": {"ndim": 2}},
|
||||
}
|
||||
# the devices the widget reads once when it is built; there is no device server here
|
||||
gui, shutter = FakeDevice("omny_xray_gui"), FakeDevice("fsh")
|
||||
for device in (gui, shutter):
|
||||
monkeypatch.setattr(device, "read", lambda *args, **kwargs: {})
|
||||
mocked_client.device_manager.add_devices([camera, gui, shutter])
|
||||
return create_widget(qtbot, OMNY_XRayEye, client=mocked_client)
|
||||
|
||||
|
||||
def test_live_view_connects_and_disconnects_the_camera(xray_eye):
|
||||
xray_eye.on_live_view_enabled(True)
|
||||
assert (xray_eye.image.device, xray_eye.image.signal) == CAMERA
|
||||
assert xray_eye.live_preview_toggle.checked is True
|
||||
|
||||
xray_eye.on_live_view_enabled(False)
|
||||
assert xray_eye.image.device == ""
|
||||
assert xray_eye.live_preview_toggle.checked is False
|
||||
|
||||
xray_eye.on_live_view_enabled(True)
|
||||
assert (xray_eye.image.device, xray_eye.image.signal) == CAMERA
|
||||
|
||||
|
||||
def test_live_view_signal_can_be_switched(xray_eye):
|
||||
xray_eye.on_live_view_enabled(True)
|
||||
|
||||
xray_eye.set_live_view_signal("smear_preview")
|
||||
assert (xray_eye.image.device, xray_eye.image.signal) == (CAMERA[0], "smear_preview")
|
||||
assert xray_eye.smear_preview_toggle.checked is True
|
||||
|
||||
xray_eye.set_live_view_signal()
|
||||
assert (xray_eye.image.device, xray_eye.image.signal) == CAMERA
|
||||
assert xray_eye.smear_preview_toggle.checked is False
|
||||
|
||||
|
||||
def test_last_smear_preview_is_cached_and_shown_on_switch(xray_eye):
|
||||
composite = np.arange(12, dtype=float).reshape(3, 4)
|
||||
|
||||
xray_eye._on_smear_preview_cached_update({"data": composite}, {})
|
||||
xray_eye._on_smear_preview_cached_update({}, {}) # a message without data keeps the cache
|
||||
xray_eye.set_live_view_signal("smear_preview")
|
||||
|
||||
np.testing.assert_array_equal(xray_eye._last_smear_composite, composite)
|
||||
np.testing.assert_array_equal(xray_eye.image.main_image.raw_data, composite)
|
||||
Reference in new issue
Block a user