Maya Training

Introduction to Hard Surface Modeling

Maya Training

Interiors and Furniture Vol 1 & 2 - Modeling & Cloth

Maya Training

Shading, Lighting and Rendering the Bedroom in MR

Maya Training

Robot volume one - Modeling with animation in mind

Maya Training

Spach-Alspaugh House the complete courseware

Maya Training

Burt The Cartoon Dinosaur Vol 01 - Modeling

New Maya Training

Robot Volume 02 - Hybrid Rigging
You are here > Home > SimplyMaya Community Forums
Loading

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 01-03-2006, 02: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, 06: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, 02: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 05:56 PM.
junkyBob is offline   Reply With Quote
Old 01-03-2006, 06: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 06:23 PM.
junkyBob is offline   Reply With Quote
Old 02-03-2006, 05: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

A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2015 SimplyMaya - vBulletin® Copyright © 2000-2015, Jelsoft Enterprises Ltd.