.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "11_demos\itom\basics\demo_timerExample.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_11_demos_itom_basics_demo_timerExample.py: Timer =========== This script creates an instance of a ``DummyGrabber`` and implements a timer with an interval of ``1000ms``. Every time, the interval is expired the method ``imageAcquisition`` is called. It acquires a new image an appends it to the global list ``myImages``. To stop the timer, call the method ``cancel``. Additionally, the timer is automatically interrupted after ``10`` iterations. .. GENERATED FROM PYTHON SOURCE LINES 14-19 .. code-block:: Python from itom import timer from itom import dataIO from itom import dataObject .. GENERATED FROM PYTHON SOURCE LINES 21-22 Function for the image acquisition. .. GENERATED FROM PYTHON SOURCE LINES 22-40 .. code-block:: Python def imageAcquisition(): global iters global t global cam global myImages print("acquire next image") cam.acquire() d = dataObject() cam.getVal(d) globals()["myImages"].append(d.copy()) iters += 1 if iters >= 10: t.stop() .. GENERATED FROM PYTHON SOURCE LINES 41-42 Call this method (e.g. by your gui) to stop the timer. .. GENERATED FROM PYTHON SOURCE LINES 42-51 .. code-block:: Python def cancel(): global t global cam t.stop() cam.stopDevice() .. GENERATED FROM PYTHON SOURCE LINES 52-53 Define a ``DummyGrabber`` camera and timer for a timed acquisition. .. GENERATED FROM PYTHON SOURCE LINES 53-60 .. code-block:: Python cam = dataIO("DummyGrabber") myImages = [] iters = 0 cam.startDevice() t = timer(1000, imageAcquisition) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.040 seconds) .. _sphx_glr_download_11_demos_itom_basics_demo_timerExample.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_timerExample.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_timerExample.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_timerExample.zip `