{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\nEvents handling\n---------------\n\nCatching click events and plugging a callback\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "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)"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }
  ], 
  "metadata": {
    "kernelspec": {
      "display_name": "Python 2", 
      "name": "python2", 
      "language": "python"
    }, 
    "language_info": {
      "mimetype": "text/x-python", 
      "nbconvert_exporter": "python", 
      "name": "python", 
      "file_extension": ".py", 
      "version": "2.7.17", 
      "pygments_lexer": "ipython2", 
      "codemirror_mode": {
        "version": 2, 
        "name": "ipython"
      }
    }
  }
}