0

I'm trying to add a right click function to a button or text in the Maya UI - specifically the 'color' input into a shader's attribute editor.

What I mean is I want the user to be able to right click on the word 'Color' OR perhaps on the checker box buttons next to it, and it gets the current shader name and runs a function (opens a little window).

(NOTE - this is for the existing UI - I'm not talking about adding right click to a custom shelf button.)

Is this at all possible?

JackNapier
  • 318
  • 4
  • 14

2 Answers2

0

it would be doable in any context outside the Attribute Editor -- but unfortunately it's a lot harder inside the AE.

Attribute Editor UI is generated in MEL and is a little different than ordinary MEL UI (the kind you write for yourself). In particular, there's already a right click menu on the labels inside the attribute editor -- the one that lets you set expressions or connect attributes -- and it's buried somewhere inside the attribute editor MEL (that will be in the scripts folder inside your Maya installation). Even if you can get the underlying widgets there's no easy way to find and disable or extend the existing popup menu; it's buried in there somewhere but exactly where is hard to say: the old-school MEL trick of using a text search of all the scripts in the folder is probably not going to work because many of the visible labels on the UI are now inside of separate resource files to support internationalization -- good for non English customers, but it means that searching for "Create New Expression..." doesn't find the AE popup menu script. While it's not literally impossible -- that UI is getting created somewhere -- it's probably not a good value for your time investment.

If you're only interested getting a script to run on the object that's currently visible in the AE, this will get you the name of the active item:

 cmds.nameField('AEnodeNameField', q=True, o=True)

That'll get you whatever is showing in the main AE editor -- though if nothing is selected (so the AE appears empty) it will still return the last item that was in the AE.

theodox
  • 12,028
  • 3
  • 23
  • 36
-1

here is a code snippet I was using with pyqt4

self.btn = QtGui.QPushButton("myname")
self.btn.clicked.connect(self.btn_proc)


def btn_proc(self):
    if QtGui.qApp.keyboardModifiers() & QtCore.Qt.ControlModifier:
        self.func1()
    elif QtGui.qApp.keyboardModifiers() & QtCore.Qt.AltModifier:
        self.func2()
    elif QtGui.qApp.mouseButtons() & QtCore.Qt.RightButton:
        cmds.softSelect(ssd=.1)
    else:
        self.func3()

otherwise with pyqt5 : How to check if a key modifier is pressed (shift, ctrl, alt)?

DrWeeny
  • 2,487
  • 1
  • 14
  • 17
  • Thank you for this - however I'm wondering how I map that to an area of the UI. ie. How do I say 'if you click this area of the existing Maya UI, run this procedure'? I could be mistaken but isn't that for *custom* UI buttons? – JackNapier Dec 05 '18 at 21:38
  • You could import only QtGui.qApp and put it in the maya command ui – DrWeeny Dec 05 '18 at 22:48
  • I unfortunately am not sure what you mean by that sorry. Can you elaborate for a bit of a noob? – JackNapier Dec 06 '18 at 00:14