Skip to content

Set as a Context#

You may want to temporarily set something on core such as core.setAutoShutter(False) when writing an MDA Engine. For this case you can use the convenience method CMMCorePlus.setContext.

set_as_context.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from pymmcore_plus import CMMCorePlus

core = CMMCorePlus.instance()

# set some state temporarily
with core.setContext(autoShutter=False):
    assert not core.getAutoShutter()
    # do other stuff

assert core.getAutoShutter()

This will work for the set methods on the core such as setAutoShutter, setShutterOpen, ...