{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Selection handling\n\nGetting selected objects\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 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"
      ]
    }
  ],
  "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
}