work around mystery print failure in Python

This commit is contained in:
David Rose 2003-05-08 22:00:39 +00:00
parent 010e616d80
commit f06c2c81f8
3 changed files with 26 additions and 10 deletions

View File

@ -15,6 +15,11 @@ class DirectNotify:
# create a default log file # create a default log file
self.logger = Logger.Logger() 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): def __str__(self):
"""__str__(self) """__str__(self)
Print handling routine""" Print handling routine"""

View File

@ -105,7 +105,7 @@ class Notifier:
if (self.__warning): if (self.__warning):
string = (self.getTime() + self.__name + '(warning): ' + warningString) string = (self.getTime() + self.__name + '(warning): ' + warningString)
self.__log(string) self.__log(string)
print(string) self.__print(string)
return 1 # to allow assert(myNotify.warning("blah")) return 1 # to allow assert(myNotify.warning("blah"))
def setWarning(self, bool): def setWarning(self, bool):
@ -125,7 +125,7 @@ class Notifier:
if (self.__debug): if (self.__debug):
string = (self.getTime() + self.__name + '(debug): ' + debugString) string = (self.getTime() + self.__name + '(debug): ' + debugString)
self.__log(string) self.__log(string)
print(string) self.__print(string)
return 1 # to allow assert(myNotify.debug("blah")) return 1 # to allow assert(myNotify.debug("blah"))
def setDebug(self, bool): def setDebug(self, bool):
@ -145,7 +145,7 @@ class Notifier:
if (self.__info): if (self.__info):
string = (self.getTime() + self.__name + '(info): ' + infoString) string = (self.getTime() + self.__name + '(info): ' + infoString)
self.__log(string) self.__log(string)
print(string) self.__print(string)
return 1 # to allow assert(myNotify.info("blah")) return 1 # to allow assert(myNotify.info("blah"))
def getInfo(self): def getInfo(self):
@ -175,11 +175,18 @@ class Notifier:
Set the logging flag to int (1=on, 0=off)""" Set the logging flag to int (1=on, 0=off)"""
self.__logging = bool 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

View File

@ -190,6 +190,10 @@ class ShowBase(DirectObject.DirectObject):
__builtins__["globalClock"] = ClockObject.getGlobalClock() __builtins__["globalClock"] = ClockObject.getGlobalClock()
__builtins__["vfs"] = vfs __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 # Now hang a hook on the window-event from Panda. This allows
# us to detect when the user resizes, minimizes, or closes the # us to detect when the user resizes, minimizes, or closes the
# main window. # main window.