pixel2d and reparent

Been wracking my brain for a better solution to this so just going to ask here as I am always concerned my solutions are more or less hacks.

Issue
Most of my GUI components have subcomponents, example would be a target hud has an image create as a DirectFrame, three DirectWaitBars representing different character stats and then text displaying the target’s name.

I’ve used reparentTo() and parent= to no avail. When I move the frame that the subcomponents should be parented to, the subcomponents do not move.

My Current Solution
What I’ve done as a solution was to keep track of all of the “children” in a dict and then iterate through and move them according to their relative position to their “parent”. However, I was reading that in render2d or aspect2d you can use reparentTo and it will function without needing to iterate through a dict like I use.

My Question
Is this correct? Is there some undocumented method that should be in the API to make this possible in pixel2d?

Answers, thoughts and comments are always welcome.

Thanks for taking the time to read this.

It is supposed to work fine, reparenting should work for any kind of node. If you’re sure that it’s not an issue in your own code, could you create a small test program that clearly shows the issue?

Carved out a quickie from what I had been doing.

Added a few commented out lines of code to show what I had been trying. This version doesn’t even show the image.

What I’ve tried:
reparentTo
parent =
parenting to pixel2d and then to the self.frame
setting no pos
setting no scale
setting pos relative to the parented gui object that I wanted it parented to …

I will be buggered if I know why it won’t work and the pasted code my show my complete lack of coding knowledge. So here goes …

from pandac.PandaModules import * 
import direct.directbase.DirectStart
from direct.showbase.ShowBaseGlobal import * 
from direct.showbase.DirectObject import DirectObject 
from direct.gui.OnscreenImage import OnscreenImage 
from direct.gui.DirectGui import *
import random

class GUIComponents(DirectObject):
    def __init__(self):
        self.frame = None
        self.children = { }
        
        self.accept('r', self.moveRandom)
        self.guiParts = loader.loadModel('client/GUI/gui/gui.egg')
        
        self.initGUI()
        self.initButton()
        
    def initGUI(self):
        self.frame = DirectFrame(image=self.guiParts.find('**/winBackground'),
                                 relief=None,
                                 state=DGG.NORMAL)
        self.frame.reparentTo(pixel2d)
        self.frame.setPos(200, 0, -400)
        self.frame.setScale(200, -1, 200)
        #print self.frame
        
    def initButton(self):
        self.children[1] = DirectButton(geom = (self.guiParts.find('**/magi'),
                                             self.guiParts.find('**/magi'),
                                             self.guiParts.find('**/magi'),
                                             self.guiParts.find('**/magi')),
                                        parent = self.frame,
                                        pos = (40, 0.001, -40),
                                        relief = None)
        self.children[1].setScale(40, 0.001, 40)
        #self.children[1].setPos(40, .5, -40)
        #self.children[1].reparentTo(self.frame)
        #self.children[1].reparentTo(pixel2d)
        #print self.children[1]
        
    def moveRandom(self):
        x = random.randint(1, 1000)
        y = random.randint(1, 1000)
        y *= -1
        self.frame.setPos(x, 0, y)
        

base.game = GUIComponents()

run()

Sorry for the loaderloadModel function but I didn’t feel like typing in the frameColors, etc. to make it look pretty.

Uh, it’s only useful when I can run it and try it for myself. Could you put up the model somewhere?

Sorry at the office and all models are on my home PC.

Will amend the code when I get home tonight as I don’t have Panda installed at work.

Thanks for looking into this by the way.

For what it’s worth … you did answer my question and it was a problem with my code.

Started to think about this a little more and I was reparenting to a DirectFrame, not a node in pixel2d. Fairly certain that was the error and for the life of me I didn’t even think to make a node for the gui components until you mentioned it.

Cheers!