-
Notifications
You must be signed in to change notification settings - Fork 23
How it works
Under the hood. most of what mGui does is simply to disguise the clunky command syntax of maya.cmds
.
When you create an instance of an mGui class, you're creating an instance of a conventional Maya gui item at the same time. Consider this simple example:
with Window() as win:
with ColumnLayout(width = 128) as col:
btn = Button(label = "Press")
win.show()
This will create a conventional Maya window containing a columnLayout that has a single button.
Each of the mGui objects (win
, col
and btn
in this example) keeps a reference to the actual Maya gui item:
print win.widget
# window123
# .... actual names will vary unless you've explicitly specified the id
print col.widget
# columnLayout456
print btn.widget
# button790
If you edit one of the properties, the mGui object will translate the property change into a the correct call. For example:
win.title = "Example window"
issues
cmds.window(win.widget, e=True, title = 'Example window")
When you read a property, mGui gets the value using cmds
as well. So if you edited the properties of the maya window from some other code, the mGui class will still give you the correct answers:
# set from mGui
win.title = "Example window"
# override with cmds
cmds.window(win.widget, e=True, title = 'I was changed")
print win.title
# I was changed
The other big mGui addition to vanilla commands is the extensive use of context managers: the nested layouts you see in the example code:
with Window() as root:
with ColumnLayout() as vertical:
with ColumnLayout() as upper:
text = TextField(width = 128)
canvas = Canvas(width = 128, height = 128, rgbValue = (1, 0, 0))
with RowLayout(numberOfColumns = 3, width = 128):
cancel = Button("Cancel")
reset = Button("Reset")
accept = Button("Accept")
root.show()
The nesting makes the layout easier to visualize.