DirectGui element parenting

I expected this code to render the button in the lower right corner of the frame. Instead it ends up outside the frame in the lower right corner of the screen. What am I doing wrong?

from direct.gui.DirectGui import *
from direct.showbase.ShowBase import ShowBase

class myapp(ShowBase):      
   def __init__(self):
      ShowBase.__init__(self)         
      self.frame = DirectFrame(frameColor=(0,0,0,1), frameSize=(-.5,.5,-.5,.5))
      self.quitButton = DirectButton(text="Quit", scale=0.05, pos=(0.95,0,-0.95))
      self.quitButton.reparentTo(self.frame)
      
app = myapp()
app.run()

The size and position of the frame has nothing to do with the position of the button that’s later parented to it. You have to place it in aspect2d coordinates like this:

from direct.gui.DirectGui import *
from direct.showbase.ShowBase import ShowBase

class myapp(ShowBase):     
   def __init__(self):
      ShowBase.__init__(self)         
      self.frame = DirectFrame(frameColor=(0,0,0,1), frameSize=(-.5,.5,-.5,.5))
      self.quitButton = DirectButton(text="Quit", scale=0.05, pos=(0.44,0,-0.49))
      self.quitButton.reparentTo(self.frame)
     
app = myapp()
app.run()

Or make the frame ‘fullscreen’, scale it 50% and then reparent the button to it. Then pos=(0.95,0,-0.95)will be somewhere around the bottom right of the frame.

from direct.gui.DirectGui import *
from direct.showbase.ShowBase import ShowBase

class myapp(ShowBase):     
   def __init__(self):
      ShowBase.__init__(self)         
      self.frame = DirectFrame(frameColor=(0,0,0,1), frameSize=(-1,1,-1,1), scale=0.5)
      self.quitButton = DirectButton(text="Quit", scale=0.1, pos=(0.95,0,-0.95), parent=self.frame)
     
app = myapp()
app.run()

I’m not the best at explaining stuff, but I hope the code will help a bit :wink:

Huh. OK. I guess I was expecting to work like Tkinter, where child widgets are placed relative to the parents. That’s the normal parent-child relationship in the scene graph. Is there any point in parenting widgets then?

I really wish I could get direct-gui-edit to work. This is going to be really time consuming without any sort of GUI editor.

Use my aligner. Click my sig.

If you parent a few buttons to a frame then you can move, scale, rotate, hide/show all the buttons by manipulating just the frame.

As for placing element and keeping sane at the same time… that’s tricky.

Ynjh_jos’ aligner is one option. pixel2d is another. 1 pixel is 1 panda unit then, but up-down is the -Z axis and DirectScrolledFrame is sort of inverted and all crazy and all default sizes make no sense (like text 0.5 pixels hight). Still, parenting to pixel2d is what I’d use (and as a bonus all gui textures stay sharp).

Is it the “A2D Editor” that you are talking about?

I tried to get that going with the supplied scripts, but I get an error when running WORLD.py:

D:\personal\python\panda\a2deditor>world.py
DirectStart: Starting the game.
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
Traceback (most recent call last):
  File "D:\personal\python\panda\a2deditor\WORLD.py", line 13, in <module> from aspect2d_editor2 import AutoSaveAspect2d
  File "D:\personal\python\panda\a2deditor\aspect2d_editor2.py", line 12, in <module>
    from buttonColl import *
  File "D:\personal\python\panda\a2deditor\buttonColl.py", line 530, in <module>

    setupButtonCollision()
  File "D:\personal\python\panda\a2deditor\buttonColl.py", line 69, in setupButtonCollision
    0,-100,0, 0,1,0, MASK_button,MASK_off)
  File "D:\Program Files\Panda3D-1.8.0\pandac\libpandaModules.py", line 1415, in
 attachCollisionRay
    coll = CollisionRay.CollisionRay(ox, oy, oz, dx, dy, dz)
AttributeError: type object 'libpanda.CollisionRay' has no attribute 'CollisionRay'

Hmm. I’d really like this to be resolution independent. Is using something like Rocket easier? Are there GUI editors for that? What I’m doing is pretty simple; I’m not trying to make a windowing system or anything, just a few nice-looking dialogs. I’m sure if I could get A2D Editor or direct-gui-edit to work that would be enough.

Thanks

My aligner is titled “DirectGUI or nodepath alignment”.

A2DEditor is old and I haven’t used it in years, but I’m sure it’s easy to make it work for 1.8. I’ll take a look at it.

Oh, that’s great!

Cool, let us know!

Thanks

That error you got there isn’t directly in the A2Deditor itself, but it’s a bug in P3D 1.8, as I found earlier here :
[1.8.0 SDK release & 1.0.4 Runtime release)

Fortunately it’s just a python file you can easily edit : /pandac/libpandaModules.py
Change each occurence of :
CollisionRay.CollisionRay to CollisionRay
CollisionNode.CollisionNode to CollisionNode
CollisionSegment.CollisionSegment to CollisionSegment
CollisionSphere.CollisionSphere to CollisionSphere

Note that the modules A2Deditor uses are years old. The latest ones are used in :
discourse.panda3d.org/viewtopic.php?t=3875
if you care in picking up the changes yourself.

I’ve updated my A2DEditor.