Skip to content

Follow changes in MMCore#

pymmcore-plus implements an enhanced Observer pattern, making it easier to connect callback functions to events that occur in the core. This is useful for things like updating a GUI when a property changes, or writing and/or processing data as it is acquired.

See the Events API documentation for complete details on what events are emitted and how to connect to them.

on_prop_changed.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from pymmcore_plus import CMMCorePlus

core = CMMCorePlus.instance()
core.loadSystemConfiguration()


@core.events.propertyChanged.connect
def _on_prop_changed(dev, prop, value):
    # Note that when state devices change either the state or the label
    # TWO propertyChanged events will be emitted, one for prop 'State'
    # and one for prop 'Label'. Probably, best to check the property
    # name and only respond to one of them
    if dev == "Objective" and prop == "Label":
        print("new objective is", value)


core.setState("Objective", 3)