# the same, but write it to a textctrl.
def DoTextCtrlThread(text, mesg):
while 1:
sleeptime = (random() * 3) + 0.5
# the same, but write it to a textctrl.
def DoTextCtrlThread(text, mesg):
while 1:
sleeptime = (random() * 3) + 0.5
# A very simple queue for textctrls.
# Nice demonstration of the power of OO programming too (at least I think so!)
# A very simple queue for textctrls.
# Nice demonstration of the power of OO programming too (at least I think so!)
# 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):
# 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 = []
- 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)
- 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))
# Start two threads that print a message every second
thread.start_new_thread(DoThread, ("thread A",))
# Start two threads that print a message every second
thread.start_new_thread(DoThread, ("thread A",))