Search code examples
pythonscriptingmaya

Maya Python - IconTextButton Right Click Command


I've been trying to get a right click command working on the icontextbutton in maya using python. I know there is a popup menu, which is working fine, but i dont want a popup, as it adds a second click to the workflow, rather than having a command execute on RMB press. There seems to be no doc on the subject and google isnt helping either, so i am hoping anyone may have an idea, maybe some undocumented flags I'm unaware of. So LMB should execute one command and RMB should execute another. Is there any way of doing that ?


Solution

  • I would recommend straight-up using Qt for this, instead of wrapping through Maya's Python stuff.

    That said, you can achieve something mostly functional by hooking the RMB through an empty popupMenu:

    import maya.cmds as cmds
    
    window = cmds.window()
    cmds.columnLayout(adjustableColumn=True )
    cmds.iconTextButton(style='iconOnly', image1='spotlight.png', label='spotlight', command='print "left click"')
    cmds.popupMenu(postMenuCommand='print "right click"')
    cmds.showWindow(window)
    

    However, the focus on the open-but-invisible menu seems to make multiple clicks a bit "off" somehow, but otherwise it seems quite usable.