0

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
2
  • What's the question/problem? Commented Jan 20, 2014 at 20:22
  • As posted you'll never be able to update the texts, since you are not storing the name of the texts anywhere. 'textFieldGroup -e obj1' might not work, since you can't be sure that you haven't already got an 'obj1' somewhere else. Capture the result of the command into a variable and use that Commented Jan 21, 2014 at 0:28

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Same issue as here -- use commands directly for the callbacks instead of strings. stackoverflow.com/questions/21215582/…
1

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!!!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.