PDA

View Full Version : shelf button into custom shelfLayout, need help with code please.


ph2003
01-18-2009, 02:58 PM
hi folks,

can any1 tell me wats wrong with this "setParent" code i did?

with this code i was unable to add shelfbutton into the shelftablayout :shrug:
if (`window -ex AC_ControlWindow`)
{
deleteUI AC_ControlWindow;
}

window -wh 400 200 -rtf 0 AC_ControlWindow;
string $mainForm = `tabLayout -innerMarginWidth 0 -innerMarginHeight 0 mainForm`;
string $colLayout3 = `columnLayout Faces`;

formLayout uiForm;
string $baseCol = `columnLayout`;
formLayout charControl;

setParent mainForm;
string $tabs = `shelfTabLayout "Presets"`;
string $shelf = `shelfLayout "Body Presets"`;
string $radioButton1;
radioCollection;
$radioButton1 = `button -label "Save" -command "save"`;
setParent mainForm;

showWindow AC_ControlWindow;

global proc save()
{
shelfButton -image1 "commandButton.xpm" -command "select -all";
}

if i remove the line20 "setParent mainForm;"
i was able to add shelf into it, but i wont able to add more shelftabs w/o using the "setParent" (theres 3 more tabs i will add later for faces and fingers presets)

im sorry that this was a simple question, im still learning about building UI atm :sad:
thank you!

goleafsgo
01-19-2009, 01:58 PM
Here are a few things to get you going...

The "setParent" you have is not needed because you are not creating anything after it. The "save" callback you have will be called sometime later when the user hits the button and the current parent could be anything at that point.

To see that happening, try running your code as it is now and then execute this:

window;
columnLayout;
button;button;button;button;
showWindow;

then, with both windows still visible, try hitting your button and you should see the buttons getting added to the other window and not yours.

What you probably need to do is to pass in the name of the parent that your callback should be adding its buttons to. Commands that create UI should all have a "-parent" flag which lets you provide the parent to use for it, so your "save" callback could look something like this: (and you should probably find a more specific name then just "save")

global proc save(string $parent)
{
shelfButton -parent $parent -image1 "commandButton.xpm" -command "select -all";
}


Some people try to give parts of their UI's really specific names so that they can just rely on them being the only ones to use it, but since you are passing the name in explicitly like this then you don't really have to even provide a name and just use the one that Maya returns.

So now this line:

$radioButton1 = `button -label "Save" -command "save"`;

will now have to change to pass in the name of the parent that we created and will now look like this:

$radioButton1 = `button -label "Save" -command ("save \"" + $shelf + "\"")`;

where $shelf was the name of the layout that you got back.

If you have another proc which is going to create extra tabs or whatever, then you can do something similar to this where you pass in the name of the layout that you want to add tabs to.

ph2003
01-21-2009, 04:06 PM
hi, goleafsgo
thanks for the explain!

it works!

CGTalk Moderation
01-21-2009, 04:06 PM
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.