List,

I know python and I know Maya, but I've never mixed the two. I have a marking
menu written with pymel. The menu itself works. The question is, how do I
assign it to a hotkey? With MEL, in the hotkey editor, you get code like this::

    // Press:
    if (`popupMenu -exists tempMM`) { deleteUI tempMM; }
    popupMenu -button 1 -ctl false -alt false -allowOptionBoxes true
-parent `findPanelPopupParent` -mm 1 tempMM;
    source "menu_foo";


    // Release::
    if (`popupMenu -exists tempMM`) { deleteUI tempMM; }


What's the python equivalent? I *guessed* something like this, but I don't
think it's right:


    # Press:
    try:
        tempMM.delete()
    except NameError:
        pass
    finally:
        import pymel_foo


    # Release:
    try:
        tempMM.delete()
    except NameError:
        pass

Finally, should I be wrapping my python in function i.e. 'main' and callling
that after I import, instead? E.g::

    import foo
    foo.main()

Here's my dummy marking menu::

    import pymel.core.windows as pwin
    import pymel.core.uitypes as ui

    def amazing(*args):
        '''Does something amazing.'''
        print("amazing!")

    def fantastic(*args):
        print("fantastic!")

    # The UI:
    tempMM = ui.PopupMenu(parent="MayaWindow")
    tempMM.setMarkingMenu()
    tempMM.setAltModifier()
    tempMM.setButton(1)   #<-- Active with alt+left mouse button for now.

    item1 = ui.CommandMenuItem(parent=tempMM)
    item1.setLabel("Amazing")
    item1.setRadialPosition("S")
    item1.setCommand(pwin.Callback(amazing))

    item2 = ui.CommandMenuItem(parent=tempMM)
    item2.setLabel("Fantastic")
    item2.setRadialPosition("N")
    item2.setCommand(pwin.Callback(fantastic))


Thanks!
-Modulok-

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to