{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\nSelection handling\n------------------\n\nGetting selected objects\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 ana\nfrom soma import aims\nfrom soma.aims import colormaphints\nimport sys\nimport os\n\n# determine wheter we are using Qt4 or Qt5, and hack a little bit accordingly\nfrom soma.qt_gui import qt_backend\nfrom soma.qt_gui.qt_backend import QtCore, QtGui\n\n# do we have to run QApplication ?\nif not QtGui.QApplication.instance() and 'sphinx_gallery' not in sys.modules:\n    runqt = True\nelse:\n    runqt = False\n\n# start the Anatomist engine, in batch mode (no main window)\na = ana.Anatomist('-b')\n\n# create a sphere mesh\nm = aims.SurfaceGenerator.sphere(aims.Point3df(0), 100, 100)\nmesh = a.toAObject(m)\nmesh.releaseAppRef()\n\n# Create a new 3D window in Anatomist\naw = a.createWindow('3D')\n\n# Put the mesh in the created window\na.addObjects(mesh, aw)\n\ng = a.getDefaultWindowsGroup()\nprint('mesh isSelected:', g.isSelected(mesh))\nprint('selecting it')\ng.setSelection(mesh)\nprint(\"selection in default group\", a.getSelection())\nprint(\"selection of\", g, g.getSelection())\nsel = g.getSelection()\n# print(mesh, sel, mesh == sel[0], mesh is sel[0])\n# print('mesh isSelected:', g.isSelected( mesh ))\n\n# run Qt\nif runqt:\n    qapp.exec_()\nelif 'sphinx_gallery' in sys.modules:\n    aw.sphinx_gallery_snapshot()\nif runqt or 'sphinx_gallery' in sys.modules:\n    del aw, mesh, m, g, sel"
      ], 
      "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"
      }
    }
  }
}