{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Events handling\n\nCatching click events and plugging a callback\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from __future__ import print_function\n\nfrom __future__ import absolute_import\nimport anatomist.direct.api as anatomist\nfrom soma import aims\n\na = anatomist.Anatomist()\n\n# definig a custom event handler in python:\n\n\ndef clickHandler(eventName, params):\n    print('click event: ', eventName)\n    print('LinkedCursor event contents:', list(params.keys()))\n    pos = params['position']\n    print('pos:', pos)\n    win = params['window']\n    print('window:', win)\n\n\n# register the function on the cursor notifier of anatomist. It will be\n# called when the user click on a window\na.onCursorNotifier.add(clickHandler)\n\n\n# definig a custom event in python\nclass TotoEvent (anatomist.cpp.OutputEvent):\n\n    def __init__(self):\n        # we can't make a custom Object yet...\n        anatomist.cpp.OutputEvent.__init__(self, 'Toto',\n                                           {}, 1)\n\n\nev = TotoEvent()\nev.send()\n\n# ...\n# wen you're done\n# you can remove the handler\n# a.onCursorNotifier.remove(clickHandler)"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.11.0"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}