zingy
zingy

Reputation: 811

Simple custom UI in Maya using Python

Hi I am learning about creating custom UI for Maya using Python. I am trying to achieve few things which I am unable to do. I searched around but couldn't find my answers.

import maya.cmds as cmds

def main():

    cmds.window(title='Test Window')
    cmds.columnLayout()
    cmds.textFieldGrp('obj1', label='Name', text ="Please enter your name")
    cmds.textFieldGrp('obj2', label='Address', text = "Please enter your address")
    cmds.rowLayout(nc=3)
    cmds.button(label="Lock", width=100, c='disable_texts()')
    cmds.button(label="Edit", width=100, c='change_texts()')
    cmds.button(label="Reset", width=100, c='default()')
    cmds.showWindow()

def disable_texts():
    # disable the text fields

def change_texts():
    # enable the text fields

def default():
   # change the text fields back to default ie like above

Upvotes: 0

Views: 13280

Answers (2)

Khamui Shirou
Khamui Shirou

Reputation: 11

After you made your experiences with layouting UIs with the Maya builtin possibilities I recommend you to setup PyQT for Maya.

If you are using Maya Version below 2014, than you need to install the compiled PyQt from here: http://nathanhorne.com/?s=pyqt

Since Maya integrated PyQT with 2014 (therefore 2015 also) you don't need to install anything for this version.

Here some starting tutorials: http://zurbrigg.com/maya-python/category/pyqt-projects-for-maya

Have fun!!!

Upvotes: 1

Argiri Kotsaris
Argiri Kotsaris

Reputation: 492

This might answer your question, if I understand..

cmds.window(title='Test Window')
cmds.columnLayout()
cmds.textFieldGrp('obj1', label='Name', text ="Please enter your name")
cmds.textFieldGrp('obj2', label='Address', text = "Please enter your address")
cmds.rowLayout(nc=3)
cmds.button(label="Lock", width=100, c=disable_texts)
cmds.button(label="Edit", width=100)
cmds.button(label="Reset", width=100)
cmds.showWindow()

def disable_texts(*args):
    #The e=True is for edit, so I'm 'editing' 'obj1' which is the name of the textFieldGrp
    cmds.textFieldGrp('obj1', e=True, enable=False)

As a side note, it's better to pass the function object to the command flag. Check this out if you're unsure why. As for the cmds functions you should check the docs to see what other commands there are.

Upvotes: 1

Related Questions