I can’t be sure as I’m not particularly experienced with the menuItem of maya.cmds (which btw I’m assuming that you mean?) but I would assume that by using that particular command you’re most likely bound to the features it exposes.
Having said that, if you were interested in venturing outside of commands-land and into Qt you may have some luck with something like this:
>>> from PySide import QtGui
>>> QtGui.QApplication.queryKeyboardModifiers()
Which will look, in a global fashion, on which keys are being held at the time of invocation.
As for menu within a menu, that sounds like you’ll be best off implementing a menu widget on your own, or perhaps hack the option-box to remove items for you.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/643993ce-63d0-431a-b27e-20568cb74355%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#import pprint#from maya import cmdsfrom maya import OpenMayaUI as omuifrom PySide import QtCore, QtGuifrom shiboken import wrapInstance
omui.MQtUtil.mainWindow() ptr = omui.MQtUtil.mainWindow() #widget = wrapInstance(long(ptr), QtGui.QWidget)widget = wrapInstance(long(ptr), QtGui.QMainWindow)
test_win = QtGui.QMainWindow(parent=widget)root_menu = test_win.menuBar().addMenu('Root menu')sub_menu = root_menu.addMenu("Sub Menu"); l_1 = root_menu.addAction("Leaf 1");l_2 = sub_menu.addAction("Leaf 2"); test_win.show()--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7acbda71-d10a-4f74-94b9-290960155a2f%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD1Qk35L9x%3DY%3DPvDLNAeTrYH%2Bu1b%2BQWSKufCcEmnTVGqQ%40mail.gmail.com.
from maya import OpenMayaUI as omuifrom PySide import QtCore, QtGuifrom shiboken import wrapInstance
# maya main windowptr = omui.MQtUtil.mainWindow() widget = wrapInstance(long(ptr), QtGui.QWidget)#widget.windowTitle()
# get a reference to the menu barmenubar = [w for w in widget.children() if isinstance(w, QtGui.QMenuBar) ]menubar[0].show()
# add menu and menuitemsmy_menu = menubar[0].addMenu("My Menu") sub_menu = my_menu.addMenu("Sub Menu")l_1 = my_menu.addAction("Leaf 1")l_2 = sub_menu.addAction("Leaf 2");--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/4ca132ba-898e-4c47-90c6-66a7785003d5%40googlegroups.com.
from functools import partial
import maya.cmds as cmds
import maya.mel as mm
# Start the top menu
gMainWindow = mm.eval("$win=$gMainWindow")
cmds.setParent(gMainWindow)
m = cmds.menu("myRootMenu", label="Root Menu")
# Add items and submenus
m_sub1 = cmds.menuItem(label="Sub Menu", subMenu=True)
m_sub1_item1 = cmds.menuItem(label="Leaf 1")
cmds.setParent(m, menu=True)
m_item1 = cmds.menuItem(label="Leaf 2")
m_item1_opt = cmds.menuItem(optionBox=True)
# Attach a callback to the option box
def handleMenuItem(item, *args):
print "Do something with", item
cmds.menuItem(m_item1_opt, e=True, stp="python", c=partial(handleMenuItem, m_item1))
# finding the menu
ptr = omui.MQtUtil.findControl(m)
qm = wrapInstance(long(ptr), QtGui.QMenu)
# finding the menu item
ptr = omui.MQtUtil.findMenuItem(m_item1)
m_item1_action = wrapInstance(long(ptr), QtGui.QAction)
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c9057d58-27d0-4aa6-bae7-ac3d2d043eac%40googlegroups.com.
from functools import partial import maya.cmds as cmdsimport maya.mel as mm
if cmds.menu('MayaWindow|my_menu_root', exists=1): cmds.deleteUI('MayaWindow|my_menu_root') # Attach a callback to the option boxdef optionbox_click(item, *args): print('Deleted ', item) if cmds.menuItem(item, exists=1): cmds.deleteUI(item) def item_click(item, *args): print('Do something with ', item) # ref to maya main menugMainWindow = mm.eval('$win=$gMainWindow')
# create my root menuroot_menu = cmds.menu('my_menu_root', label='My menu root', parent=gMainWindow)
# add menu itemsfor x in range(5): # create item my_item = cmds.menuItem('item_{0}'.format(x), label='Item {0}'.format(x), parent=root_menu) # add menu item & optionbox handlers cmds.menuItem(my_item, e=True, stp='python', c=partial(item_click, my_item)) my_item_ob = cmds.menuItem(optionBox=True, c=partial(optionbox_click, my_item))