diff --git a/direct/src/directnotify/DirectNotify.py b/direct/src/directnotify/DirectNotify.py index 8bed59036f..d6d5a621ff 100644 --- a/direct/src/directnotify/DirectNotify.py +++ b/direct/src/directnotify/DirectNotify.py @@ -15,6 +15,11 @@ class DirectNotify: # create a default log file self.logger = Logger.Logger() + # This will get filled in later by ShowBase.py with a + # C++-level StreamWriter object for writing to standard + # output. + self.streamWriter = None + def __str__(self): """__str__(self) Print handling routine""" diff --git a/direct/src/directnotify/Notifier.py b/direct/src/directnotify/Notifier.py index 7d1c0e66fa..a40129a77e 100644 --- a/direct/src/directnotify/Notifier.py +++ b/direct/src/directnotify/Notifier.py @@ -105,7 +105,7 @@ class Notifier: if (self.__warning): string = (self.getTime() + self.__name + '(warning): ' + warningString) self.__log(string) - print(string) + self.__print(string) return 1 # to allow assert(myNotify.warning("blah")) def setWarning(self, bool): @@ -125,7 +125,7 @@ class Notifier: if (self.__debug): string = (self.getTime() + self.__name + '(debug): ' + debugString) self.__log(string) - print(string) + self.__print(string) return 1 # to allow assert(myNotify.debug("blah")) def setDebug(self, bool): @@ -145,7 +145,7 @@ class Notifier: if (self.__info): string = (self.getTime() + self.__name + '(info): ' + infoString) self.__log(string) - print(string) + self.__print(string) return 1 # to allow assert(myNotify.info("blah")) def getInfo(self): @@ -175,11 +175,18 @@ class Notifier: Set the logging flag to int (1=on, 0=off)""" self.__logging = bool + def __print(self, string): + """__print(self, string) + Prints the string to standard output followed by a newline. + """ + # We could use the print command, but that seems to stop + # working when Python is in the program-level exception + # handler for some reason (!). So we use C++-level output + # instead, as soon as we have the DirectNotify level + # streamWriter available. - - - - - - - + import DirectNotifyGlobal + if DirectNotifyGlobal.directNotify.streamWriter: + DirectNotifyGlobal.directNotify.streamWriter.appendData(string + '\n') + else: + print string diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index f561e23797..5fab3045a7 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -190,6 +190,10 @@ class ShowBase(DirectObject.DirectObject): __builtins__["globalClock"] = ClockObject.getGlobalClock() __builtins__["vfs"] = vfs + # Route all of our DirectNotify output through the Panda level + # ostream object from now on. + directNotify.streamWriter = StreamWriter(ostream) + # Now hang a hook on the window-event from Panda. This allows # us to detect when the user resizes, minimizes, or closes the # main window.