Displaying in Panda Output From console

Hello All,

I wonder if any one had a go or had some tipe to redirect console message.(mesage that display in the dos window while running panda) into a direct gui component, to show it to end user.

How do you redirect such message?
What Direct Gui components may display them?

is it something built in with the Notify system?

Thanks in advance and never forget, Panda Rocks!!

OK, I have a sample object that will do this for you. Feel free to take this as a starting point, and then modify it for your needs.

You will also need to get at least CVS version 1.28 of direct/src/directnotifier/Notifier.py, which I have just checked in (and it should be available shortly in the viewCVS tree
here) Put this file in your direct/src/directnotifier directory, replacing the existing Notifier.py. You don’t need to have this file, but if you don’t get it, only the Notify messages generated in C++, not those generated in Python, will be reported in the onscreen widget.

Now, here is the sample object that captures the Notify output and displays it in an onscreen widget:

from pandac.PandaModules import *
from direct.gui.DirectGui import *
from direct.showbase import DirectObject
from direct.task import Task
from direct.directnotify.Notifier import Notifier

class NotifyMonitor(DirectObject.DirectObject):
    def __init__(self):
        # Hijack the output of Notify so we can query it here.
        self.notifyOut = LineStream()
        Notify.ptr().setOstreamPtr(self.notifyOut, 0)
        Notifier.streamWriter = StreamWriter(Notify.out())

        # Create a label to display the output.
        self.label = DirectLabel(frameSize = (0, 2.6, 0, 0.3),
                                 relief = RIDGE,
                                 borderWidth = (0.012, 0.012),
                                 pos = (-1.3, 0, -0.95),
                                 text = 'initial',
                                 text_scale = 0.07,
                                 text_pos = (0.03, 0.23),
                                 text_align = TextNode.ALeft,
                                 )

        # We use this object to compute wordwrapping for us.  (It
        # should have the same font as the above label.  Here, they
        # both use the default font.)
        self.wordWrapObj = TextNode('wordWrapObj')
        self.wordWrapObj.setWordwrap(36.2)

        # This is the history of output lines that we will display
        # within the label.
        self.lines = []

        # Parameters that control the number of lines to retain and
        # display.
        self.numKeepLines = 100
        self.numDisplayLines = 3

        # Now spawn a task to keep things up to date.
        self.__updateText()
        taskMgr.add(self.updateNotify, 'updateNotify')
        
    def updateNotify(self, task):
        """ This method is run every frame as a task to query for the
        latest Notify output. """

        while self.notifyOut.isTextAvailable():
            self.addLine(self.notifyOut.getLine())
        return Task.cont

    def addLine(self, line):
        """ Adds a single line to the output.  The line is wordwrapped
        into multiple lines if necessary. """

        # We handle wordwrap explicitly, so that we can keep an
        # accurate count of the number of lines.
        self.wordWrapObj.setText(line)
        result = self.wordWrapObj.getWordwrappedText().split('\n')
        self.lines += result

        self.__updateText()

    def __updateText(self):
        """ Called internally whenever self.lines is modified, to
        update the label display and do other maintenance. """
        
        # Truncate the text to keep only numKeepLines lines, so we
        # don't bloat memory indefinitely.
        self.lines = self.lines[-self.numKeepLines:]

        # Show the last numDisplayLines in the label.
        text = '\n'.join(self.lines[-self.numDisplayLines:])
        self.label['text'] = text

David