DIrectGui problem{SOLVED}

so I added this code to my “Client” and now I have 2 windows when I run it lol.

############################################################
# GUI using DirectGUI
############################################################
myFrame = DirectFrame(frameColor=(0, 0, 0, 1),frameSize= (-1, 1, -1, 1), pos=(1, -1, -1))
bk_text = "This is a test Does it work?"
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)

#--Callback to set text
def setText():
        bk_text = "Button Clicked"
        textObject.setText(bk_text)

        #--Add a button
b = DirectButton(text = ("OK","Click me!","Rollong Over","Disabled"), scale = .05, command = setText)

one has all my geometry and stuff, and the other is a standard panda window with the gui stuff, How do I get the GUI stuff into my original window?

EDIT::
The code was in the wrong location, moving it to right before my app.run() call seems to have fixed it sort of im guessing you want gui stuff to load last. BUT I still have 2 windows opening, one is just grey now with nothing in it but the GUI stuff is now in the right window.

Can you give more information about your problem? DirectGUI shouldn’t imply that problem, maybe the reason of your problem stays in other parts of your code, which you’ve omitted.

sure, here is the complete client code:

import direct.directbase.DirectStart
from direct.distributed.PyDatagram import PyDatagram
from direct.distributed.PyDatagramIterator import PyDatagramIterator
from direct.showbase.DirectObject import DirectObject
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from pandac.PandaModules import *
from pandac.PandaModules import ConnectionWriter
from pandac.PandaModules import QueuedConnectionListener
from pandac.PandaModules import QueuedConnectionManager
from pandac.PandaModules import QueuedConnectionReader
from direct.gui.DirectGui import *
#from direct.gui.DirectGui import DirectFrame
#from pandac.PandaModules import TextNode

#--Networking Stuff
class Client(DirectObject):
    def __init__(self):
        print "Initializing client test"

        self.port = 9099
        self.ip_address = "darkrift.dyndns-server.com"
        self.timeout = 3000             # 3 seconds to timeout

        self.cManager = QueuedConnectionManager()
        self.cListener = QueuedConnectionListener(self.cManager, 0)
        self.cReader = QueuedConnectionReader(self.cManager, 0)
        self.cWriter = ConnectionWriter(self.cManager, 0)
       
        self.Connection = self.cManager.openTCPClientConnection(self.ip_address, self.port, self.timeout)
       
        if self.Connection:
            taskMgr.add(self.tskReaderPolling, "read the connection listener", -40)
            # this tells the client to listen for datagrams sent by the server
            
            print "Connected to Server"
            self.cReader.addConnection(self.Connection)
            print "Message Recieved..."
            print "\n"
            myPyDatagram = PyDatagram()
            myPyDatagram.addUint8(100)
            # adds an unsigned integer to your datagram
            myPyDatagram.addString("first string of text")
            # adds a string to your datagram
            myPyDatagram.addString("second string of text")
            # adds a second string to your datagram
            self.cWriter.send(myPyDatagram, self.Connection)
            # fires it off to the server
           
            #self.cManager.closeConnection(self.Connection)
            #print "Disconnected from Server"
            # uncomment the above 2 lines if you want the client to
            # automatically disconnect.  Or you can just
            # hit CTRL-C twice when it's running to kill it
            # in windows, I don't know how to kill it in linux

      
            #taskMgr.add(self.tskReaderPolling, "read the connection listener", -40)

    def tskReaderPolling(self, task):
        if self.cReader.dataAvailable():
            datagram = PyDatagram()
            if self.cReader.getData(datagram):
                self.processServerMessage(datagram)
        return Task.cont

    def processServerMessage(self, netDatagram):
        myIterator = PyDatagramIterator(netDatagram)
        print myIterator.getString()
       
    
        #taskMgr.add(self.tskReaderPolling, "read the connection listener", -40)




class DarkRift(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)



#------------load models and stuff here------------------
    #--Lighting
        alight = AmbientLight("alight")
        alight.setColor(VBase4(0.2, 0.2, 0.2, 1))
        alnp = render.attachNewNode(alight)
        render.setLight(alnp)

    #--Directional Light for SUN
        dlight = DirectionalLight('dlight')
        dlight.setColor(VBase4(0.8, 0.8, 0.5, 1))
        dlnp = render.attachNewNode(dlight)
        dlnp.setHpr(0, -60, 0)
        render.setLight(dlnp)

            #--static models (non-animated)
        self.environ = self.loader.loadModel("Models/Antris V")
        self.environ.setScale(1.25, 1.25, 1.25)
        self.environ.setTwoSided(True)
        self.environ.reparentTo(self.render)
    #tex = loader.loadTexture("Textures/space009.jpg")
    #self.setTexture(tex,1)
        self.environ.setPos(-0, 60, 0)


    #--Background Starfeilds
        self.skysphere = loader.loadModel("Models/Antrisystemstars.bam")
        self.skysphere.setBin("background", 1)
        self.skysphere.setDepthWrite(0)
        self.skysphere.reparentTo(render)
        taskMgr.add(self.skysphereTask, "SkySphere Task")

#task for rendering the skysphere each frame and moving it relitive to the camera
    def skysphereTask(self, task):
        self.skysphere.setPos(base.camera, 0, 0, 0)
        return task.cont



        

# Main Loop

Client = Client()
app = DarkRift()

#taskMgr.add(sendOutput, "Send the output to the server", -39)
#taskMgr.add(tskReaderPolling, "Poll the connection reader", -38)
############################################################
# GUI using DirectGUI
############################################################
'''myFrame = DirectFrame(frameColor=(0, 0, 0, 1),frameSize= (-1, 1, -1, 1), pos=(1, -1, -1))
bk_text = "This is a test Does it work?"
textObject = OnscreenText(text = bk_text, pos = (0.95, -0.95),
scale = 0.05, fg = (1,0.5,0.5,1), align=TextNode.ACenter, mayChange=1)

#--Callback to set text
def setText():
        bk_text = "Button Clicked"
        textObject.setText(bk_text)

        #--Add a button
b = DirectButton(text = ("OK","Click me!","Rolling Over","Disabled"), scale = .07, command = setText)'''

app.run()

no idea why its makeing 2 panda windows but for now I have the GUI code block commented till I figure it out.

It’s because you are (a) importing DirectStart and also (b) creating an instance of a class that derives from ShowBase.

You should do one or the other of these two things, but not both.

David

I kinda had a feeling that was the case , now i have to figrue out how to re write the stuff in the DirectStart(showbase) class so dont get a bunch of “XYZ is not defined” type errors which is what happens when I remove the Class statement and the def init(self) Or perhaps remove the inport for DirectStart entirly.

Just remove the DirectStart import. The only reason DirectStart exists is to automatically create a ShowBase instance for you. If you’re going to create your own, there’s no reason at all to import DirectStart (and doing so will cause problems, as you see).

David

and now with out that import the error: global name ‘taskMgr’ is not defined has returned no matter where I put it. so im guessing since im making my own ShowBase instance there is some code missing that will fix that issue?

The taskMgr is created when you instantiate ShowBase. Make sure that you instantiate your ShowBase object before you do anything else.

If you can’t do this for some reason, you can also explicitly import the taskMgr with:

from direct.task.TaskManagerGlobal import taskMgr

David

so basicly i need to move my code around so things are insintated in the proper order.

dont know why but moving the code around didnt do it, so I used the import and all is well and one benefit is my logic flow should now be in the correct order. :blush: my Darkrift(ShowBase) class is first, then my network stuff fires up, then the gui stuff , and it works as intended now.

Thank you once again! I am back on track.