import shiboken from PySide import QtGui, QtCore import maya.OpenMayaUI as apiUI def getMayaWindow(): ptr = apiUI.MQtUtil.mainWindow() if ptr is not None: return shiboken.wrapInstance(long(ptr), QtGui.QWidget) def addMenuItem(myMenu=None, title='', action=''): myMenu.addMenu(title) #menu.addAction(action) def addSeparator(myMenu): myMenu.addSeparator() def setupMenuBar(): print 'setting up menu bar' mayaWindow = getMayaWindow() mainMenu = QtGui.QMenu('Overkill_Tools', mayaWindow) addMenuItem(mainMenu, 'TESTING', lambda: test) #mayaWindow.menuBar().addMenu(mainMenu) def test(): print 'testing qt-ness' setupMenuBar()
Cheers,
return shiboken.wrapInstance(long(ptr), QtGui.QMainWindow)
Adding the menu using: mayaWindow.menuBar().addMenu(mainMenu) works well now :)
But in the meantime if anyone has any solid tips to consider while creating something like this please feel free to post
Cheers,
Ben
How about the goold ol’ cmds.menu
?
import maya.cmds as cmds
cmds.menu( label='MyMenu', tearOff=True, parent='MayaWindow' )
cmds.menuItem( label='New' )
cmds.menuItem( label='Open', subMenu=True )
cmds.menuItem( label='Cheese')
cmds.menuItem( label='Pasta')
Qt is great and all, but sometimes the built-in methods aren’t actually that bad either.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e5e17196-fcda-47ad-be89-0a5a5e61427d%40googlegroups.com.--
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.
--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/IcMpXXmDnSM/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAFRtmOAe%3DYCT7n%2BrxoxwybELuaGQKLOteZOg_wwOjzLovgid5g%40mail.gmail.com.
Who recommended that? And are you really worried about the performance of your menu?
Functionality-wise, you could embed Quake 3 into Google Maps and draw your menu into it with Qt so it’s safe to say it wins there. But whether you need it or not is another matter.
Usability-wise, the cmds
module offers less lines if all you’re looking for is a menu. Some might say, that doing a plain menu using QMenu is “re-inventing the wheel”. But again, maybe you are looking for something more than just a menu, in which case Qt is a good choice.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkXaohCQABj3AQv-aBj1ET7MmEskidpDM1wUB0_Lmb0ZPA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOARe--XYSHkRWMoDNB-pA%3D8kKVWxv5hVscr9%3DYiCUxjLA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkXS9fubrMMN-or0OBsOqQZ5FXiP%2BEH_7iCnnu7tNV4cvg%40mail.gmail.com.
I also agree. If you can avoid doing custom Qt modifications to Maya that circumvent the official API, then you can minimize the potential for strange behavior to crop up. Especially across versions of Maya.
Maya is free to do any number of extra operations surrounding its procedure for adding a menu via its commands api, such as registering information about it. You may miss that behavior if you do it with Qt directly.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAD%3DwhWNZ4YR4wc2Oz-rMS4p_GtajQgbcEfofy1t7WwJKq5-V4A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0Y-ZV4WLmCgHNFNHdLSPxncGwRqQtch0U5CsV%2BgSj8WA%40mail.gmail.com.
def addMenuItem(parentMenu=None, labelName='', callback=None, sub=False, tearable=False): if callback == None: newMenu = pm.menuItem(parent=parentMenu, label=labelName, subMenu=sub, tearOff=tearable) return newMenu else: pm.menuItem(p=parentMenu, label=labelName, command=pm.Callback(callback))
Is there a better way to pin our menu items i.e. pin the script itself or would that be based around the command being something other that pm.Callback?
You could use the string form in this case, and make sure your callback is globally executable. That means either the function you use is in Maya's main namespace or you use something self contained
"import myPackage; myPackage.run()"
--
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/CAM2ybkW63EmZ6%3DY-GZaxCMKOVXinu5LeqBmjNod-497rv-gpCQ%40mail.gmail.com.