View Single Post
# 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.