.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_addMenuEntry.py: Adding custom menus in an object options ======================================== .. code-block:: default from __future__ import print_function from __future__ import absolute_import import anatomist.direct.api as anatomist from soma import aims import os a = anatomist.Anatomist() class MyCallback(anatomist.cpp.ObjectMenuCallback): def __init__(self): anatomist.cpp.ObjectMenuCallback.__init__(self) def doit(self, objects): print('plop!!') # Store python callbacks callbacks_list = [] # Add plop Menu to an object def addMenuEntryToOptionTree(object): import sip m = anatomist.cpp.ObjectMenu(object.optionTree()) mycallback = MyCallback() callbacks_list.append(mycallback) m.insertItem([], 'plop!', mycallback) m.insertItem(['bloups'], 'plop!', mycallback) t = m.releaseTree() sip.transferto(t, None) # Create a dummy AGraph and add plop menu entry g = aims.Graph('dummy') ag = a.toAObject(g) ag.releaseAppRef() addMenuEntryToOptionTree(ag) if __name__ == '__main__': from soma.qt_gui.qt_backend import Qt if Qt.QApplication.startingUp(): Qt.qApp.exec_() del ag, g, callbacks_list .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_addMenuEntry.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: addMenuEntry.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: addMenuEntry.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_