X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..7581faf616eef3617152b9ad05b939999f442502:/wxPython/tests/test8.py?ds=inline diff --git a/wxPython/tests/test8.py b/wxPython/tests/test8.py index ec383b7a09..34cd268791 100644 --- a/wxPython/tests/test8.py +++ b/wxPython/tests/test8.py @@ -18,15 +18,15 @@ use_wxpython = 1 def DoThread(mesg): while 1: sleeptime = (random() * 3) + 0.5 - print "Hello from %s (%1.3f)" % (mesg, sleeptime) - time.sleep(sleeptime) + print "Hello from %s (%1.3f)" % (mesg, sleeptime) + time.sleep(sleeptime) # the same, but write it to a textctrl. def DoTextCtrlThread(text, mesg): while 1: sleeptime = (random() * 3) + 0.5 - text.WriteText("Hello from %s (%1.3f)\n" % (mesg, sleeptime)) - time.sleep(sleeptime) + text.WriteText("Hello from %s (%1.3f)\n" % (mesg, sleeptime)) + time.sleep(sleeptime) # A very simple queue for textctrls. # Nice demonstration of the power of OO programming too (at least I think so!) @@ -34,41 +34,41 @@ def DoTextCtrlThread(text, mesg): # The main (UI) thread must call Flush to force output. (see MyFrame::OnIdle) class wxTextCtrlQueue(wxTextCtrl): def __init__(self, parent, id, value, pos, size, flags): - wxTextCtrl.__init__(self,parent, id, value, pos, size, flags) - self.queue = [] + wxTextCtrl.__init__(self,parent, id, value, pos, size, flags) + self.queue = [] def WriteText(self, value): - self.queue.append(value) + self.queue.append(value) def Flush(self): - queue = self.queue - self.queue = [] - for value in queue: - wxTextCtrl.WriteText(self,value) + queue = self.queue + self.queue = [] + for value in queue: + wxTextCtrl.WriteText(self,value) # MyFrame and MyApp are very simple classes to test python threads in # wxPython. class MyFrame(wxFrame): def __init__(self): - wxFrame.__init__(self, NULL, -1, "test threads", wxDefaultPosition, wxSize(300,200)) - self.text = wxTextCtrlQueue(self, -1, "thread output\n", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE) - menu = wxMenu() - menu.Append(1001, "Start thread") - self.cnt = 0; - menubar = wxMenuBar() - menubar.Append(menu, "Action") - self.SetMenuBar(menubar) - EVT_MENU(self, 1001, self.StartThread) + wxFrame.__init__(self, NULL, -1, "test threads", wxDefaultPosition, wxSize(300,200)) + self.text = wxTextCtrlQueue(self, -1, "thread output\n", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE) + menu = wxMenu() + menu.Append(1001, "Start thread") + self.cnt = 0; + menubar = wxMenuBar() + menubar.Append(menu, "Action") + self.SetMenuBar(menubar) + EVT_MENU(self, 1001, self.StartThread) def StartThread(self, event): - self.cnt = self.cnt + 1 - thread.start_new_thread(DoTextCtrlThread, (self.text, "thread %d" % self.cnt)) + self.cnt = self.cnt + 1 + thread.start_new_thread(DoTextCtrlThread, (self.text, "thread %d" % self.cnt)) def OnIdle(self, event): - self.text.Flush() + self.text.Flush() class MyApp(wxApp): def OnInit(self): - frame = MyFrame() - self.SetTopWindow(frame) - frame.Show(TRUE) - return TRUE + frame = MyFrame() + self.SetTopWindow(frame) + frame.Show(TRUE) + return TRUE # Start two threads that print a message every second thread.start_new_thread(DoThread, ("thread A",)) @@ -80,6 +80,6 @@ if use_wxpython: app.MainLoop() else: while 1: - print "main loop" - time.sleep(4) + print "main loop" + time.sleep(4) print 'done!'