Hi Justin!
Thanks for your reply and thanks for your snippet!
The best idea seems to be to stick with creating menus through the cmds
module. I will run the command directly on the optionbox click. I agree
that it is not that descriptive, but it will be fine for what I am doing.
Below is a test snippet I did based on your code.
Again, thanks!
Best Regards,
Johan
from functools import partial
import maya.cmds as cmds
import 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 box
def 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 menu
gMainWindow = mm.eval('$win=$gMainWindow')
# create my root menu
root_menu = cmds.menu('my_menu_root', label='My menu root',
parent=gMainWindow)
# add menu items
for 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))
On Friday, July 11, 2014 1:59:42 PM UTC+2, johan Borgström wrote:
>
> Hi!
>
> I am building a basic menu populated with some menuItems. I want the user
> to be able to add and remove menuItems to the menu. I have wrapped the menu
> in a class and written some methods to help to add and remove menuItems. I
> do not want to write a special ui to handle the removing of items, so my
> idea is to check if the user holds a modifier key while clicking the
> menuItem and if so delete it. Another idea is to use a right click popup
> menu on the menuItem and have the option "delete item".
> To add the command to the menuItem I use functools.partial. So to wrap it
> up my questions are:
>
>
> - How can I add a right click popup menu to a menuItem.
> - How can I check if a modifier key was pressed when the menuItem was
> clicked.
>
> Best Regards,
> Johan
>
>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/a5ab3baa-4a00-4985-a7c9-22ebe135bc91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.