Bounds of DirectGUI object's parent

This is all about directGUI, so button means DirectButton etc…

I create a frame, then i make button and parent it to frame.

when i do

print button.getParent()

i get Frame,
but when i want to get bounds via button.getParent().getBounds(), i get

bsphere, c <0.7,0,0>,r 1.42

Is that collision sphere or what???
I need to get bounds of parent because i want to make system in which i can place widgets relatively in corner based manner.

I placed object to fit in exact bottom left corner (frame is a2dbottomleft, and button is in corner of frame after frame changes position)

i tried couple of thing like calling node() and whatnot, but cant really get it right…

here is code

from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import *

class MainMenu(DirectObject):
    def __init__(self):
        self.accept("a", self.posDownLeft)
        self.accept("s", self.posDownRight)
        self.accept("d", self.posTopLeft)
        self.accept("f", self.posTopRight)
        self.text = OnscreenText(text = 'my text string', pos = (-0.9, -0.9), scale = 0.147)
        self.Frame = DirectFrame(frameColor=(0,0,0,1) , frameSize=(0,1.41,0,1.123 ) )
        self.Frame.setPos(self.Frame, 0.5,0,0.5)
        #Add button
        self.b = DirectButton(text = ("T", "click!", "rolling over", "disabled"), scale=.4)
    def posDownLeft(self):
        x = self.b.getBounds()
        scale = self.b['scale']
        posX = x[0]*scale*-1
        posy = x[2]*scale*-1
    def posTopLeft(self):
        bounds = self.b.getBounds()
        scale = self.b['scale']
        parent = self.b.getParent()
        ph = parent.node().getBounds()
        print ph
        posX = bounds[0]*scale*-1 
        posy = bounds[2] * scale *-1

and of course, this is just prototype to get it working, i will write fair wrappers later, that is reason why i dont simply call self.Frame instead of getParent()…

To get the perfectly fit bounds, it’s getTightBounds(), but that doesn’t work for DGUI.
So, you could try to recursively query and accumulate the framesize of each widget :

def getWidgetsBounds(parent,bounds=None):
    bounds = parent.node().getFrame() #also try parent['frameSize']
    for c in parent.getChildren():
        cB = getWidgetsBounds(c)
        bounds.setX(min(cB[0],bounds[0])) #L
        bounds.setY(max(cB[1],bounds[1])) #R
        bounds.setZ(min(cB[2],bounds[2])) #B
        bounds.setW(max(cB[3],bounds[3])) #T
    return bounds

Didn’t try it though.

Oh thanks very much, getFrame() was thing i needed, it works great :smiley:

I’ve just posted a simple snippet to align a widget to the other.