PDA

View Full Version : simple UI question - radioButtons


Luddy
05-02-2003, 10:31 PM
I'm trying to rename a selected object with an extension. "Lf" or "Rg". I'm confused on how you query the selected button into another procedure. :D

global proc renameObj()
{
//?radioCollection -query -select $rcn;
string $curSel[] = `ls -sl`;
//string $newName = "object" + $LR;
//rename $curSel[0] $newName;

}

global proc winProc()
{
string $window = `window`;

columnLayout;

button -label "Rename Selected"
-command renameObj;

rowLayout -columnWidth2 60 60 -numberOfColumns 2;
radioCollection;
string $rightName = "Rg";
string $leftName = "Lf";
$leftName = `radioButton -label "Left"`;
$rightName = `radioButton -label "Right"`;
//?radioCollection -query -select $LR;
showWindow $window;
}
winProc;

mark_wilkins
05-03-2003, 05:34 AM
You could define a global string and throw the name of the radio button collection into it, then use that variable to query it within your button action procedure.

-- Mark

X-Tender
05-03-2003, 08:33 AM
use this .

$radiobuttons = `radioCollection`;



then you can later use

$selection_in_the_radiocollelction = `radioCollection -q -sl $radiobuttons' ;


then you get the selected item (the label string)

mark_wilkins
05-03-2003, 08:48 AM
as I pointed out though, the variable must be global.

global string $radiobuttons;

etc.

-- Mark

Luddy
05-03-2003, 08:25 PM
I'm still confused on how to get "Lf" and "Rg" into $sir (the $leftName, $rightName part). $sir prints out NONE, $radiobuttons prints out radioCollection12, radioCollection13. :hmm:



global proc renameObj()
{
$radiobuttons = `radioCollection`;
$sir = `radioCollection -q -sl $radiobuttons`;
print $sir;
print " ";
print $radiobuttons;
}

global proc winProc()
{
string $window = `window`;
columnLayout;
button -label "Rename Selected"
-command renameObj;

rowLayout -columnWidth2 60 60 -numberOfColumns 2;

global string $radiobuttons;
$radiobuttons = `radioCollection`;

?? string $leftName = "Lf";
?? string $rightName = "Rg";

$leftName = `radioButton -label "Left"`;
$rightName = `radioButton -label "Right"`;

showWindow $window;
}
winProc;

mark_wilkins
05-03-2003, 10:45 PM
OK, first off you don't want to reassign the value of $radiobuttons a second time in the renameObj proc. Just define it as a global string in each and they'll share the value.

Second, you weren't indicating that either of the radio buttons had to come up selected. To do this, stick a -sl flag on the command where you make the Left radio button.

Finally, the way to give the actual radio button object the name you want (which is what gets returned when you do a radioCollection -q) is to stick the name you want at the end of the radioButton command. Note that the object name is not the same as the label. In this case, I made Lf and Rg the object names.

There's a simpler way to do all of this if you have a small number of radio buttons and don't want to do anything fancy: use the radioButtonGrp command. It will make all the buttons, label them, hook them together in a collection, select one of them by default, and all in one command. That's the way I talk about doing it in my book, but if you're doing certain more complex things or have more than eight or so radio buttons you'll need to make your own collection like you have.

-- Mark


global proc renameObj()
{
global string $radiobuttons;

$sir = `radioCollection -q -sl $radiobuttons`;
print ($sir + " " + $radiobuttons + "\n");
}

global proc winProc()
{

global string $radiobuttons;

string $window = `window`;
columnLayout;
button -label "Rename Selected"
-command renameObj;

rowLayout -columnWidth2 60 60 -numberOfColumns 2;

$radiobuttons = `radioCollection`;

$leftName = `radioButton -label "Left" -sl "Lf"`;
$rightName = `radioButton -label "Right" "Rg"`;

showWindow $window;
}
winProc;

CGTalk Moderation
01-15-2006, 02:00 AM
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.