.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_events.py: Events handling --------------- Catching click events and plugging a callback .. code-block:: default from __future__ import print_function from __future__ import absolute_import import anatomist.direct.api as anatomist from soma import aims a = anatomist.Anatomist() # definig a custom event handler in python: def clickHandler(eventName, params): print('click event: ', eventName) print('LinkedCursor event contents:', list(params.keys())) pos = params['position'] print('pos:', pos) win = params['window'] print('window:', win) # register the function on the cursor notifier of anatomist. It will be # called when the user click on a window a.onCursorNotifier.add(clickHandler) # definig a custom event in python class TotoEvent (anatomist.cpp.OutputEvent): def __init__(self): # we can't make a custom Object yet... anatomist.cpp.OutputEvent.__init__(self, 'Toto', {}, 1) ev = TotoEvent() ev.send() # ... # wen you're done # you can remove the handler # a.onCursorNotifier.remove(clickHandler) .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_events.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: events.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: events.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_