disabling a button with a checkbox

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 10 October 2009   #1
disabling a button with a checkbox

Hi everyone.. I finally gathered some courage and tackled UI building in MEL.. The issue here is:
I want a couple of intFields & textFields to be disabled until the user clicks on a checkbox. This way the user might add its own values instead of using the default ones...

My guess is that this might be achieved using the -onCommand and -offComand on the checkbox.. But being the total n00b I am, I can't figure it out how to make this thing turn on/off the -enable flag on the textfield.

I'll be thankfull if you guys can point me in the right direction.
 
Old 10 October 2009   #2
you can use the "-enable" flag to turn controls on or off. Just make sure you also use the "-edit" flag when you want to change the enable state of an existing control.
__________________
Digital Characters R&D - Suntoucher Labs
 
Old 10 October 2009   #3
Here is a super simple example:


  global proc openWindow(){
  
  // If the window exists, delete it
  if (`window -exists toggleWin`)
  deleteUI toggleWin;
  
  // Declare the window and a couple options
  window -title "Toggle Window" -widthHeight  220 310 -maximizeButton  off toggleWin;
  
  // Declare a layout for us to put a couple of controls
  columnLayout mainColumn;
  
  // Create our textField and checkbox
  // Give them variable names which we can use to query their attributes later
  // Tell the checkBox to do something when we change it's status
  textField -text "This is text" -width 150 myTxtField;
  checkBox  -label "Toggle" -changeCommand toggleTxtEnable myCheckBox;
  
  // Show our Window
  showWindow toggleWin;
  }
  
  // Global Proc to toggle the enable state of the text field
  global proc toggleTxtEnable(){
  
  // Query the enable state of the textField, notce how we use its name
  // If it "Is" enabled set enable to 0, else set enable to 1
  if(`textField -q -enable myTxtField`){
  textField -edit -enable 0 myTxtField;
  }
  else{
  textField -edit -enable 1 myTxtField;
  	}
  }
  
  // Initiate the Global Proc to launch our window
  openWindow();
  


As with everything in Maya there is always multiple ways to achieve the same result.
It's important not to think of one way as the magic bullet solution.

Good Luck.
__________________
Ok, But Can You Do It...ON FIRE!

Last edited by Pyrokinesis : 10 October 2009 at 07:05 AM.
 
Old 10 October 2009   #4
Thanks for the help guys! it works great... I guess I was barking at the wrong tree there with the -onCommand and -offCommand.
Thanks again
 
Old 10 October 2009   #5
Originally Posted by TheRispo: Thanks for the help guys! it works great... I guess I was barking at the wrong tree there with the -onCommand and -offCommand.
Thanks again


You can use those flags too.

eg)
-onCommand textOn
-offCommand textOff

proc textOn {
// turn on the text, text -e -en 1
}

proc textOff {
// turn off text, text -e -en 0, there should be a flag to control visibility too
}
 
Old 10 October 2009   #6
Thanks for the reply efecto, Its great to learn diferent ways to achieve the same thing.
 
Old 10 October 2009   #7
here is one more magic bullet:

window;
columnLayout;
button -label "Ok!" theButton;
checkBox -v 1 -cc "button -e -en #1 theButton";
showWindow;


Use the #1-placeholder which stands for the current value of the control. Of course this is more pain in the a if you try to stuff more elements into the -changeCommand (-cc) but you could also en-/disable a layout which holds all the controls you want to switch.
__________________
goodsoul.de
 
Old 10 October 2009   #8
Great.. thanks for that!!

I didnt know that #1 would have such a function... Does a more in depth explanation of that comes in the docs?? or is it kind of basic coding knowledge?? sorry if its a question to basic, but my only coding knowledge comes from particle expresions and simple "proceduraly-build-your-own-stairs" scripts... nothing UI related.

Thanks
 
Old 10 October 2009   #9
I doubt that you find much more about that in the docs.. Its actually very simple. #1,#2 or #3 .. in a command at a control is replaced with the current value of the control. At controls with multiple inputs there is #2,#3 for the other ones..

instead you could also write:

window;
columnLayout;
button -label "Ok!" theButton;
checkBox -v 1 -cc "button -e -en (`checkBox -q -v theCheckBox`) theButton" theCheckBox;
showWindow;


So the controls asks itself what value it currently has. You need to name it then and the string is much longer. But wurks as well. One issue I experienced: if you use #1 at textFields entered quote signs are not properly passed.
__________________
goodsoul.de
 
Old 10 October 2009   #10
thanks for the explanation ewerybody, I think its much clearer now.
Thanks for the help
 
Old 10 October 2009   #11
Thread automatically closed

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.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



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
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 12:07 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.