{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Anatomist commands\n\nUsing the commands interpreter in a generic way\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\nfrom soma.qt_gui.qt_backend import Qt\nimport sip\nimport sys\n\nrun_loop = Qt.QApplication.instance() is None \\\n    and 'sphinx_gallery' not in sys.modules\n\na = anatomist.Anatomist()\n\ncx = anatomist.cpp.CommandContext.defaultContext()\n\n# custom command\ni = cx.freeID()\nc = a.execute('CreateWindow', type='Coronal', res_pointer=i)\n\nwin = c.createdWindow()\n\n# otherwise, we can retreive the new window using the context\n# (which will work if the exact command has no python binding)\nprint(cx.id(win))\nprint(cx.object(i))\nwin2 = cx.object(i)\n\nprint(win2 is win)\n\nvol = aims.read('irm.ima')\navol = a.toAObject(vol)\navol.releaseAppRef()\n\n# keywords / real objects test\na.execute('AddObject', objects=[avol], windows=[win])\n\nif run_loop:\n    Qt.QApplication.instance().exec_\n\nif run_loop or 'sphinx_gallery' not in sys.modules:\n    del win, win2, avol, vol, cx, i"
      ]
    }
  ],
  "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
}