SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Home / forum / Animation / Mel Scripts & Programming / Disabling the "OK" button in promptDialog
Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 01-03-2006, 01:27 AM   #1
junkyBob
Subscriber
 
Join Date: Dec 2004
Posts: 203
Thanks: 0
Thanked 3 Times in 3 Posts
Default 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?
junkyBob is offline   Reply With Quote
Old 01-03-2006, 05:34 AM   #2
skywola
Registered User
 
skywola's Avatar
 
Join Date: Jan 2004
Location: Tempe, Arizona, USA
Posts: 224
Thanks: 0
Thanked 0 Times in 0 Posts
Default

http://www.morten-moen.net/tutorials...wShopping.html
__________________
"The Sage as an Astronomer: If you still see the stars as something above you, you lack the eye of knowledge." Friedrich Nietzsche
skywola is offline   Reply With Quote
Old 01-03-2006, 01:40 PM   #3
junkyBob
Subscriber
 
Join Date: Dec 2004
Posts: 203
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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 04:56 PM.
junkyBob is offline   Reply With Quote
Old 01-03-2006, 05:20 PM   #4
junkyBob
Subscriber
 
Join Date: Dec 2004
Posts: 203
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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 05:23 PM.
junkyBob is offline   Reply With Quote
Old 02-03-2006, 04:41 AM   #5
junkyBob
Subscriber
 
Join Date: Dec 2004
Posts: 203
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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.
junkyBob is offline   Reply With Quote
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.