Many time we need debug our application and we want to know which step is our app run at .a good practis is add some log information and traces it.then the question is how to keep them.the answer is
redirection.there are two import paramter of wx.App
- redirection:the optional value is Ture of False,if it's True,the information message will display in a Frame that you can see.if it's false,the message will display in Console.
- filename:if you set first paramter as False,then you can config it,and specify how to save your message in a file.
Following is an example:
import wx
import sys
class MyFrame(wx.Frame):
def __init__(self,parent,id,title):
print "init frame" #entry of frame init
wx.Frame.__init__(self,parent,id,title)
class MyApp(wx.App):
def __init__(self,redirect=True,filename=None):
print "init app" #entry of app init
wx.App.__init__(self,redirect, filename)
def OnInit(self):
print "Oninit"
self.mf=MyFrame(parent=None,id=-1,title="Show it")
self.mf.Show(True)
self.SetTop1Window(self.mf)
#put the message to sys.stderr,we can also put it into sys.stdout
print >>sys.stderr, "A pretend error message"
return True
def OnExit(self):
print "OnExit"
if __name__=="__main__":
app=MyApp(redirect=False)#set redirect as False,then the message display at console
app=MyApp(redirect=True,filename="c:/aa.txt")#set redirect as True and specify the path of redirect.
print "before MainLoop"
app.MainLoop()
print "after MainLoop"
No comments:
Post a Comment