View Full Version : TextFields (confused about Maya Documentation)
12-19-2007, 10:58 PM
Under textFields in the Maya Docs, it gives the following code:
// Create a window with a some fields for entering text.
string $window = `window`;
rowColumnLayout -numberOfColumns 2 -columnAttach 1 "right" 0
-columnWidth 1 100 -columnWidth 2 250;
text -label "Name";
string $name = `textField`;
text -label "Address";
string $address = `textField`;
text -label "Phone Number";
string $phoneNumber = `textField`;
text -label "Email";
string $email = `textField`;
// Attach commands to pass focus to the next field if the Enter
// key is pressed. Hitting just the Return key will keep focus
// in the current field.
textField -edit -enterCommand ("setFocus " + $address) $name;
textField -edit -enterCommand ("setFocus " + $phoneNumber) $address;
textField -edit -enterCommand ("setFocus " + $email) $phoneNumber;
textField -edit -enterCommand ("setFocus " + $name) $email;
I'm not clear on why they suggest setting up the textFields like this. If I understand correctly, they say to create a textField in column 2, setting the result to $variable, and then later on in the code, editing that textField's attributes. Why not just set the attributes immediately? I've noticed that I can't change the width of the textFields in this example, they just default straight to the 250 set by the column. Why?
12-19-2007, 11:29 PM
i'm no expert in creating textfields but maybe i can help a bit.
what's the fundamental difference between "string $variable = `textField`;" and "textfield $variable;"
if i understand it correctly "string $variable = `textField`;" creates a new textfield and returns the path name to the control (so you can use it later). when you use "textfield $variable" you can access the textfields attributes.
so you first create a textfield and store its path in a string variable. later you can access the textfield via the variable like this: "textfield -edit ...attributes and values... $variable"
when you just use "textfield" the return value is the path of the current layout.
hope this helps a little. just ask if something is still unclear.
Lastly, I've noticed that I can't change the width of the textFields in this example, they just default straight to the 250 set by the column. Why?
well i think this is because the layout overrules the textfields attributes. As i already said i'm not that trained in creating textfields but i think you need to choose another layout when you want to have control over those things. formLayout would be one thing but there are two sides of the coin. when you get control over the size you need to align all the fields. so why not choosing a rowcolumnlayout? search in the maya documentation for "layout" so you get an overview of the different layouts.
phu... Does this help you?
12-19-2007, 11:39 PM
It does. Your first answer clears up the confusion for me - I was under the assumption that you could dio "textfield .. attributes and values .. $variable" on creation. It doesn't seem that way, so that makes sense to me that you need to assign it to a variable and then edit it.
As for the layout, this example was only referred to because I was working on something else and delved into textFields. I'm actually using rowColumnLayout and still having similar problems with the width of the textField. It may just be that I have to actually create a rowColumnLayout with a width of 20 if I want a textField with a width of 20 - it seems rather counter-intuitive to me. You create a container to hold these objects (so to speak) that's 250px wide, and now all those objects HAVE to be 250px? I just assumed they couldn't exceed 250.
Thanks for your help!
12-19-2007, 11:46 PM
you can use more than one layout in a window!
so as soon as you need a special textfield you can add another layout.
You create a container to hold these objects (so to speak) that's 250px wide, and now all those objects HAVE to be 250px
a rowcolumnLayout is like a chart. you can define the number of rows and the chart's width. maya will automatically align the inserted textfields and also set the size so the space is used in an optimal way.
so a rowcolumnlayout with a width of 250 and 3 object will adjust the 3 objects so their total width is equal to 250.
12-19-2007, 11:48 PM
You can encapsulate the textField within its own columnLayout.
Then you can set it to anything as long as it doesn't exceed the width of its parent, the rowColumnLayout. :)
rowColumnLayout -numberOfColumns 2 -columnAttach 1 "right" 0 -columnWidth 1 100 -columnWidth 2 250;
text -label "Name";
columnLayout -adjustableColumn false;
string $name = `textField -width 100`;
12-20-2007, 02:10 AM
Ah, gotcha. Thanks guys!
12-20-2007, 02:10 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.