qt_device_adapter#
Qt adapter that bridges pure-Python device signals into ``pyqtSignal``s.
GUI code (e.g. live plotting, image previews) needs Qt signals so that
emissions are delivered on the main thread with QueuedConnection
semantics. Devices built on
mesofield.devices.base.BaseDataProducer use psygnal and
remain Qt-free. This module is the seam: attach an adapter to a
device, expose the adapter’s pyqtSignal as an attribute on the
device, and the GUI reads that attribute.
Two adapters live here:
QtDeviceAdapter— for serial-style devices. Bridgessignals.dataintoserialDataReceived/serialSpeedUpdated.QtImageAdapter— for camera-shaped devices. Provides animage_ready(np.ndarray)pyqtSignal that the MDA viewer subscribes to. The device pushes frames into the adapter viaadapter.emit_frame(frame).
- class mesofield.gui.qt_device_adapter.QtDeviceAdapter[source]#
Bases:
QObjectBridges
device.signals.datainto Qt-friendly emissions.Subscribes to the device’s
signals.dataand re-emits:serialDataReceived(object)— the raw payload.serialSpeedUpdated(float, float)—(time_s, speed)whenever the payload is adictcarrying a"speed"key.time_sdefaults to the device timestamp; if absent, the queue timestamp.
- class mesofield.gui.qt_device_adapter.QtImageAdapter[source]#
Bases:
QObjectBridges per-frame ndarray emissions into a Qt
image_readysignal.The MDA gui’s static-viewer branch subscribes via
preview = ImagePreview(image_payload=cam.image_ready, ...), which callsimage_payload.connect(cb, type=QueuedConnection)– soimage_readyMUST be a realpyqtSignal. Devices built onBaseDataProducerare non-Qt; they hold an instance of this adapter and expose itsimage_readyattribute as their own.Usage:
class MyCam(BaseDataProducer): def __init__(self, cfg=None, **kwargs): super().__init__(cfg, **kwargs) self._qt_image_adapter = QtImageAdapter() self.image_ready = self._qt_image_adapter.image_ready def _run_loop(self): ... self._qt_image_adapter.emit_frame(frame)