Is it possible to keep the window open long enough to read it? Is there
an
easy function call to redirect stdout/stderr back to their original
values?
Or do I have to do this manually?
I believe the default logger is some window thing, you want to change that.
wxLog_SetActiveTarget(some wxPyLog) is the command to change the default
logger. There are some standard ones, but I just made my own (see below)
For development(under win32) I use the following logger to display on the
console. I run my app from a dos box, the box sticks around even if my app
does dies. So, I can see the fatal exceptions
Logging to a file would also be a good choice.
I'm no wxPython expert but this is what I've been using. It does a little
more than you ask for. wxLogException is something I find very usefull. I
have it in almost every except block.
class stdout_Logger(wxPyLog):
def __init__(self, CodeStamp=1, TimeStamp=0):
"""
CodeStamp bool (t) adds file/func/line to log
TimeStamp bool (t) adds timestamp to log
"""
wxPyLog.__init__(self)
self.TimeStamp = TimeStamp
self.CodeStamp = CodeStamp
def DoLogString(self, message, timeStamp):
if self.CodeStamp:
try:
f = sys._getframe(1)
t = "[%s:%s:%i]" % (f.f_code.co_filename, f.f_code.co_name,
f.f_lineno)
message = "%-32s %s" % (t,message)
except:
pass
if self.TimeStamp:
message = time.strftime("%X", time.localtime(timeStamp)) + " " +
message
sys.stderr.write(message+'\n')
#cause under win32 wxLogDebug goes someplace silly instead of where I want
it.
wxLogDebug = wxLogInfo
def wxLogException():
f = sys._getframe(1)
type, value, trace = sys.exc_info()
wxLogInfo("%s" % (''.join(traceback.format_exception(type, value,
trace))) )
del trace
del value
del type
#trickyness (aka lame hack) to init only if not existing
try:
a_Logger.GetActiveTarget()
except:
a_Logger = stdout_Logger(is_devel_system(),not is_devel_system())
wxLog_SetActiveTarget(a_Logger)