class ErrorMessageDisplay(RPObject):

    """ This is a gui element which listens to the panda output stream
    and shows errors """

    def __init__(self):
        RPObject.__init__(self)
        self._num_errors = 0
        self._error_node = Globals.base.pixel2d.attach_new_node("ErrorDisplay")
        self._error_node.set_z(-180)
        self._notify_stream = None

    def _init_notify(self):
        """ Internal method to init the stream to catch all notify messages """
        self._notify_stream = LineStream()
        Notify.ptr().set_ostream_ptr(self._notify_stream, False)

    def update(self):
        """ Updates the error display, fetching all new messages from the notify
        stream """

        if not self._notify_stream:
            self._init_notify()

        while self._notify_stream.is_text_available():
            line = self._notify_stream.get_line().strip()
            if "warning" in line:
                RPObject.global_warn("Panda3D", line)
                # self.add_warning(line)
            elif "error" in line:
                RPObject.global_error("Panda3D", line)
                self.add_error(line)
            else:
                RPObject.global_debug("Panda3D", line)

    def add_error(self, msg):
        """ Adds a new error message """
        self.add_text(msg, Vec3(1, 0.2, 0.2))

    def add_warning(self, msg):
        """ Adds a new warning message """
        self.add_text(msg, Vec3(1, 1, 0.2))

    def add_text(self, text, color):
        """ Internal method to add a new text to the output """
        Text(
            x=Globals.native_resolution.x - 30, y=self._num_errors * 23,
            align="right", text=text, size=12, parent=self._error_node, color=color)

        self._num_errors += 1

        if self._num_errors > 30:
            self.clear_messages()
            self.add_error("Error count exceeded. Cleared errors ..")

    def clear_messages(self):
        """ Clears all messages / removes them """
        self._error_node.node().remove_all_children()
        self._num_errors = 0
Esempio n. 2
0
 def getRenderInfo(self):
     sga = SceneGraphAnalyzer()
     sga.addNode(self.scene.scene.node())
     
     ls = LineStream()
     sga.write(ls)
     desc = []
     while ls.isTextAvailable():
         desc.append(ls.getLine())
     desc = '\n'.join(desc)
     return desc
    def doAnalyzeScene(self):
        render.analyze()

        ls = LineStream()
        sga = SceneGraphAnalyzer()
        sga.addNode(render.node())
        sga.write(ls)
        text = ""
        while ls.isTextAvailable():
            text += ls.getLine() + "\n"
        self.acceptOnce('analyzedone', self.__handleAnalyzeDone)
        self.analyzeDlg = GlobalDialog(message=text,
                                       style=Ok,
                                       doneEvent='analyzedone',
                                       text_scale=0.05)
        self.analyzeDlg.show()
 def _init_notify(self):
     """ Internal method to init the stream to catch all notify messages """
     self._notify_stream = LineStream()
     Notify.ptr().set_ostream_ptr(self._notify_stream, False)
 def _init_notify(self):
     """ Internal method to init the stream to catch all notify messages """
     self._notify_stream = LineStream()
     Notify.ptr().set_ostream_ptr(self._notify_stream, False)
class ErrorMessageDisplay(RPObject):

    """ This is a gui element which listens to the panda output stream
    and shows errors """

    def __init__(self):
        RPObject.__init__(self)
        self._num_errors = 0
        self._error_node = Globals.base.pixel2d.attach_new_node("ErrorDisplay")
        self._error_node.set_z(-180)
        self._notify_stream = None

    def _init_notify(self):
        """ Internal method to init the stream to catch all notify messages """
        self._notify_stream = LineStream()
        Notify.ptr().set_ostream_ptr(self._notify_stream, False)

    def update(self):
        """ Updates the error display, fetching all new messages from the notify
        stream """

        if not self._notify_stream:
            self._init_notify()

        while self._notify_stream.is_text_available():
            line = self._notify_stream.get_line().strip()
            if "warning" in line:
                RPObject.global_warn("Panda3D", line)
                # self.add_warning(line)
            elif "error" in line:
                RPObject.global_error("Panda3D", line)
                self.add_error(line)
            else:
                RPObject.global_debug("Panda3D", line)

    def add_error(self, msg):
        """ Adds a new error message """
        self.add_text(msg, Vec3(1, 0.2, 0.2))

    def add_warning(self, msg):
        """ Adds a new warning message """
        self.add_text(msg, Vec3(1, 1, 0.2))

    def add_text(self, text, color):
        """ Internal method to add a new text to the output """
        Text(
            x=Globals.native_resolution.x - 30, y=self._num_errors * 23,
            align="right", text=text, size=12, parent=self._error_node, color=color)

        self._num_errors += 1

        if self._num_errors > 30:
            self.clear_messages()
            self.add_error("Error count exceeded. Cleared errors ..")

    def clear_messages(self):
        """ Clears all messages / removes them """
        self._error_node.node().remove_all_children()
        self._num_errors = 0

    def show(self):
        self._error_node.show()

    def hide(self):
        self._error_node.hide()