Skip to content

ImagePreview

ImagePreview widget

This image generated from example code below.

ImagePreview #

Bases: QWidget

A Widget that displays the last image snapped by active core.

This widget will automatically update when the active core snaps an image, when the active core starts streaming or when a Multi-Dimensional Acquisition is running.

Parameters:

Name Type Description Default
parent QWidget | None

Optional parent widget. By default, None.

None
mmcore CMMCorePlus | None

Optional pymmcore_plus.CMMCorePlus micromanager core. By default, None. If not specified, the widget will use the active (or create a new) CMMCorePlus.instance.

None
use_with_mda bool

If False, the widget will not update when a Multi-Dimensional Acquisition is running. By default, True.

True

clims: tuple[float, float] | Literal['auto'] property writable #

Get the contrast limits of the image.

cmap: str property writable #

Get the colormap (lookup table) of the image.

use_with_mda: bool property writable #

Get whether the widget should update when a MDA is running.

Example#

image_preview.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from pymmcore_plus import CMMCorePlus
from qtpy.QtWidgets import QApplication, QGroupBox, QHBoxLayout, QVBoxLayout, QWidget

from pymmcore_widgets import (
    ChannelWidget,
    ExposureWidget,
    ImagePreview,
    LiveButton,
    SnapButton,
)


class ImageFrame(QWidget):
    """An example widget with a snap/live button and an image preview."""

    def __init__(self, parent: QWidget | None = None) -> None:
        super().__init__(parent)

        self.preview = ImagePreview()
        self.snap_button = SnapButton()
        self.live_button = LiveButton()
        self.exposure = ExposureWidget()
        self.channel = ChannelWidget()

        self.setLayout(QVBoxLayout())

        buttons = QGroupBox()
        buttons.setLayout(QHBoxLayout())
        buttons.layout().addWidget(self.snap_button)
        buttons.layout().addWidget(self.live_button)

        ch_exp = QWidget()
        layout = QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        ch_exp.setLayout(layout)

        ch = QGroupBox()
        ch.setTitle("Channel")
        ch.setLayout(QHBoxLayout())
        ch.layout().setContentsMargins(0, 0, 0, 0)
        ch.layout().addWidget(self.channel)
        layout.addWidget(ch)

        exp = QGroupBox()
        exp.setTitle("Exposure")
        exp.setLayout(QHBoxLayout())
        exp.layout().setContentsMargins(0, 0, 0, 0)
        exp.layout().addWidget(self.exposure)
        layout.addWidget(exp)

        self.layout().addWidget(self.preview)
        self.layout().addWidget(ch_exp)
        self.layout().addWidget(buttons)


if __name__ == "__main__":
    mmc = CMMCorePlus().instance()
    mmc.loadSystemConfiguration()
    app = QApplication([])
    frame = ImageFrame()
    frame.show()
    mmc.snap()
    app.exec_()