'ello everyone,
I’m trying to create a GUI in a seperate window, so that I can control the main window without cluttering it. In a previous script I created three buttons for loading different scripts in a queue. There are two animations that it loads, and the third button cancels the current animation. I basically took the directbutton example from the manual and worked from there.
What I have tried to do is create another window and put the buttons there. I followed the steps drwr layed out in this thread:
https://discourse.panda3d.org/viewtopic.php?t=456&highlight=tkinter
. Here is how I tried to implement it:
import direct.directbase.DirectStart
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from posetest import *
from animationtest2 import *
from direct.showbase.DirectObject import DirectObject
import sys, os
class GUI(DirectObject):
def __init__(self):
#create new window for the gui
wp = WindowProperties()
wp.setSize(400, 300)
wp.setOrigin(879, 200)
controlwin = base.openWindow(props = wp, aspectRatio = 1.33)
render2d = NodePath('render2d')
camera2d = base.makeCamera2d(controlwin)
camera2d.reparentTo(render2d)
#add some text
bk_text = "This is my Demo"
self.textObject = OnscreenText(text = bk_text, pos = (0.95,-0.95),
scale = 0.07,fg=(1,0.5,0.5,1),align=TextNode.ACenter,mayChange=1)
bk_text = "Current Animation: None"
self.runtextObject = OnscreenText(text = bk_text, pos = (0.95, -0.90),
scale = .07, fg = (1, 0.5, 0.5, 1),
align = TextNode.ACenter, mayChange = 1)
#add buttons
b = DirectButton(text = ("Ready", "Run", "Click to run posetest", "disabled"), scale = .10, command = self.addPoseq, pos = (.8, 0, .8))
b.reparentTo(render2d)
a = DirectButton(text = ("Ready", "Run", "Click to run animationtest2", "disabled"), scale = .10, command = self.addAnimq, pos = (-.8, 0, .8))
a.reparentTo(render2d)
b1 = DirectButton(text = ("Ready", "Stop", "Click to stop animations", "disabled"), scale = .10, command = self.stopAnim, pos = (-.8, 0, -.8))
b1.reparentTo(render2d)
self.q = []
taskMgr.add(self.runQ, 'run')
#task for running the queue
def runQ(self, task):
if len(self.q) == 0:
bk_text = "No objects in queue"
self.textObject.setText(bk_text)
else:
if self.q[-1].running == 0:
self.q[-1].run()
bk_text = "Current: " + self.q[-1].name
self.runtextObject.setText(bk_text)
if self.q[-1].done == 1:
self.q.pop()
return Task.cont
#function for adding "posetest"
def addPoseq(self):
self.q.insert(0, World())
bk_text = "posetest added to queue"
self.textObject.setText(bk_text)
#function for adding "animation2"
def addAnimq(self):
self.q.insert(0, Anim())
bk_text = "animationtest2 added to queue"
self.textObject.setText(bk_text)
#function for cancel button
def stopAnim(self):
if len(self.q) != 0:
self.q[-1].stop()
bk_text = "Animation canceled"
self.textObject.setText(bk_text)
else:
sys.exit()
w = GUI()
#run the tutorial
run()
Unsure of what drwr meant by “passing the parent parameter”, I just reparented the buttons to the render2d object. The window is created fine, and the images(default) for the buttons appear in the designated positions, but none of the text for the buttons appears, in addition to the buttons not clicking properly. I’m almost certain that reparent the buttons iis my problem, but I do not know how else to get them over to the window, as the manual does not speak of any “parent” keyword for directobjects. Any advice in this manner would be WONderful. Thanks.
EDIT: Almost forgot an important thing: When I click in the main window, a thick red dot appears in the middle of both windows. Weird…