Digital humans the art of the digital double
Ever wanted to know how digital doubles are created in the movie industry? This course will give you an insight into how it's done.
# 1 01-03-2006 , 02:27 AM
Subscriber
Join Date: Dec 2004
Posts: 203

Disabling the "OK" button in promptDialog

Hi there all,
I am new to MEL, but not in respects of programming in general, so I have a question that I would like to ask.

I wanted to know when calling the procedure 'promptDialog', is it possible to disable the "OK" button until the user enters some text inside message the field?

# 2 01-03-2006 , 06:34 AM
skywola's Avatar
Registered User
Join Date: Jan 2004
Location: Tempe, Arizona, USA
Posts: 224


"The Sage as an Astronomer: If you still see the stars as something above you, you lack the eye of knowledge." Friedrich Nietzsche
# 3 01-03-2006 , 02:40 PM
Subscriber
Join Date: Dec 2004
Posts: 203
Thanks skywola,
This is a great tutorial, but I have a few questions. First, considering that you gave me a tutorial on the new window command, and how to create a button inside of it, I am assuming that you are saying that I could not do this in the "promptDialog" command? Yo do realize my original question was asking if it could be done in the promptDialog command?

Anywho, if it is true that it can't be done in the promptDialog command, and I do it by creating a new window, then how could I make the button know if text is entered in the text field or not?

For example, here is a rough diagram of what I want in my window...

[pre]
-----------------------------------
| |
| Enter Name: |
| ------------------------------ |
| | | |
| ------------------------------ |
| |
| ----------- ------------ |
| | OK | | Cancle | |
| ----------- ------------ |
______________________
[/pre]

Now if there is no text in the "Enter Name:", then I want the "OK" button to be disabled. However as soon as the user starts typing into the text field, I want the button become enabled. Now, in the tutorial that you have provided, I see how I just set the enable flag to 0 when I want the button to be grayed out and set the enable flag to 1 when I want the button to be not grayed out. However, I how do I make the button know if there is text in the "Enter Name:" field?


Last edited by junkyBob; 01-03-2006 at 05:56 PM.
# 4 01-03-2006 , 06:20 PM
Subscriber
Join Date: Dec 2004
Posts: 203
ok, I am thinking that I might be able to do this by queriing the textField. However, I can't seem to figure out how to do this. I have been doing a testing and here is my code so far but it only queries the field after I close the window or hit the return key which I don't want. What I want is it to query as soon as the user enters their first key. However here is the code so far...

{
string $text;
string $value;

window;
columnLayout;

$text = `textField "enteredText"`;
textField -edit -changeCommand("changeText()" )"enteredText";
}

proc changeText() {
string $value;

$value = `textField -q -tx "enteredText"`;
if (size($value) > 0) {
print("you have started to type\n");
}


so in other words, the procedure "changeText()", is not being called until I press the return key or close the window. Is there any way that I can do this when the user enter's their first key?


Last edited by junkyBob; 01-03-2006 at 06:23 PM.
# 5 02-03-2006 , 05:41 AM
Subscriber
Join Date: Dec 2004
Posts: 203
ok I found a website that mentioned an example of how to call a command if the user closes the window by using the scriptJob. I then looked up scriptJob in the Maya's documentiation and gave me an idea of using the event flag with it set to idle. However, I am having some troubles with killiing the job. The troubles that I am having is that I would like to kill all jobs if the user closes the window with "x" button that is on top of the title bar. As of right now, if the user closes the window, the way I have my script, I get an error stating that the job can not be killed while it is running.
here is my script...

window -title "Enter Name" myWindow;
columnLayout;
string $field = 'textfield myField';
button -label "OK" -enable 0 -command "buttonClicked" okButton;
showWindow myWindow;

// -e idle stands for an event that happens on idle
scriptJob -e idle "sendMessage";
scriptJob -uiDeleted myWindow "endAllJobs";

proc sendMessage() {
string $value = `textField -q -tx myField`;
if(size(#value) > 0) {
button -e -enable 1 okButton;
}
else {
//re-disables button if the user had text in the field but then deleted it
if (`button -q -enable okButton` == 1)
button -e -enable 0 okButton;
}
}

proc buttonClicked() {
//make sure button is not disabled
if (`button -q -enable okButton == 1 {
//go ahead and kill all jobs considering user clicked on "OK"
scriptJob -ka -f;
//note this next line will be changed after I get this script to work. It is only here temporally for me to know that clicking on the button was successful
print("button was clicked-on\n");
}
}

// the next procedure is for a just in case the user closes the window and makes sure that all jobs are killed. HOWEVER it is not working and prompts an error at run-time stating that the jobs can not be killed while rinning.
proc endAllJobs() {
scriptJob -ka -f;
}

so as you can see, when clicking on the "OK" button, the killjob works. However, it doesn't work when the procedure "endAllJobs() is called, thats when I get the error. So is there any way I can fix this? I am asking because if I don't kill all of the jobs then the idle event is still running in the background, even if I close the window.

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads