.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/events.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_events.py>`
        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

.. GENERATED FROM PYTHON SOURCE LINES 39-81

.. 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 sphx-glr-footer-example




    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: events.py <events.py>`

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: events.ipynb <events.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_