4.4 gui -- GUI classes

This module provides an object-oriented approach to the GUI functionality in Maya. For each MEL function that represents a particular GUI element there is a corresponding class that wraps that function. For example, instead of using the MEL function window to create or edit windows you can use the Window class to do the same thing.

Attributes of a GUI element can be accessed via regular Python attribute access on the appropriate GUI object. MEL functions that are related to a particular GUI element are wrapped as methods (for example, the method Window.Show() will internally invoke the MEL function showWindow). Some GUI objects define their own methods to invoke certain operations which are also done via flags in MEL. To distinguish attributes from methods and to prevent name clashes, all methods on GUI classes begin with an upper case letter. For example, the TextScrollList class provides a method Append() that can be used to append a new item to the scroll list. You can either use this method or still use attribute access:

tsl = TextScrollList()
tsl.append = "Spam"    # this line is equivalent to the previous line

Both ways will internally invoke the MEL command textScrollList -e -append "Spam".

The main advantage of the GUI classes is that they allow passing Python functions or methods as commands or callbacks whereas the MEL GUI functions would only allow MEL code. Example:

def myCallback():
    print "This is from a Python callback"
Button(label="Hit me", command=myCallback)

The above line defines a button that will invoke the function myCallback() whenever the button is pressed. You could achieve the same by using the mel.button() function but the code would not look as sleek as the above version:

mel.button(label="Hit me", command='python \\\"myCallback()\\\"')