WxPython рдореЗрдВ рдзрд╛рдЧреЗ

рдЬрдм рдЧреНрд░рд╛рдлрд┐рдХрд▓ рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рдкрд╛рдпрдерди рдореЗрдВ рдкреНрд░реЛрдЧреНрд░рд╛рдо рд▓рд┐рдЦрддреЗ рд╣реИрдВ, рддреЛ рдХрднреА-рдХрднреА рдЖрдкрдХреЛ рдХрд┐рд╕реА рднреА рдбреЗрдЯрд╛ рдХреЗ рд╡рд┐рднрд┐рдиреНрди рджреАрд░реНрдШрдХрд╛рд▓рд┐рдХ рдкреНрд░рд╕рдВрд╕реНрдХрд░рдг рд╢реБрд░реВ рдХрд░рдирд╛ рдкрдбрд╝рддрд╛ рд╣реИ, рдФрд░ рдЬреНрдпрд╛рджрд╛рддрд░ рдорд╛рдорд▓реЛрдВ рдореЗрдВ рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рдЕрд╡рд░реБрджреНрдз рд╣реЛ рдЬрд╛рдПрдЧрд╛ рдФрд░ рдЙрдкрдпреЛрдЧрдХрд░реНрддрд╛ рдкреНрд░реЛрдЧреНрд░рд╛рдо рдХреЛ рдЬрдореЗ рд╣реБрдП рджреЗрдЦреЗрдВрдЧреЗред рдЗрд╕рд╕реЗ рдмрдЪрдиреЗ рдХреЗ рд▓рд┐рдП, рд╣рдорд╛рд░реЗ рдХрд╛рд░реНрдп рдХреЛ рд╕рдорд╛рдирд╛рдВрддрд░ рдзрд╛рдЧреЗ рдпрд╛ рдкреНрд░рдХреНрд░рд┐рдпрд╛ рдореЗрдВ рдЪрд▓рд╛рдирд╛ рдЖрд╡рд╢реНрдпрдХ рд╣реИред рдЗрд╕ рд▓реЗрдЦ рдореЗрдВ, рд╣рдо рдереНрд░реЗрдбрд┐рдВрдЧ рдореЙрдбреНрдпреВрд▓ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ wxPython рдореЗрдВ рдРрд╕рд╛ рдХрд░рдиреЗ рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рджреЗрдЦреЗрдВрдЧреЗред

рдереНрд░реЗрдб рд╕реБрд░рдХреНрд╖рд┐рдд wxPython рд╡рд┐рдзрд┐рдпрд╛рдБ


WxPython рдореЗрдВ рдереНрд░реЗрдбреНрд╕ рдХреЗ рд╕рд╛рде рдХрд╛рдо рдХрд░рдиреЗ рдХреА рддреАрди рд╡рд┐рдзрд┐рдпрд╛рдБ рд╣реИрдВред рдпрджрд┐ рдЖрдк рдЙрдирдХрд╛ рдЙрдкрдпреЛрдЧ рдирд╣реАрдВ рдХрд░рддреЗ рд╣реИрдВ, рддреЛ рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рдХреЛ рдЕрдкрдбреЗрдЯ рдХрд░рддреЗ рд╕рдордп, рдкрд╛рдпрдерди рдкреНрд░реЛрдЧреНрд░рд╛рдо рдлреНрд░реАрдЬ рд╣реЛ рд╕рдХрддреЗ рд╣реИрдВред рдЗрд╕рд╕реЗ рдмрдЪрдиреЗ рдХреЗ рд▓рд┐рдП, рдЖрдкрдХреЛ рдереНрд░реЗрдб рд╕реБрд░рдХреНрд╖рд┐рдд рд╡рд┐рдзрд┐рдпреЛрдВ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдирд╛ рдЪрд╛рд╣рд┐рдП: wx.PostEvent, wx.CallAfter, рдФрд░ wx.CallLaterред рд░реЙрдмрд┐рди рдбрди рдХреЗ рдЕрдиреБрд╕рд╛рд░ (wxPython рдХреЗ рдирд┐рд░реНрдорд╛рддрд╛) wx.CallAfter рдПрдХ рдЖрд╡реЗрджрди рд╡рд╕реНрддреБ рдХреЗ рд▓рд┐рдП рдПрдХ рдШрдЯрдирд╛ рднреЗрдЬрдиреЗ рдХреЗ рд▓рд┐рдП wx.PostEvent рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддрд╛ рд╣реИред рдЗрд╕ рдШрдЯрдирд╛ рдХреЗ рд▓рд┐рдП рдПрдкреНрд▓рд┐рдХреЗрд╢рди рдореЗрдВ рдПрдХ рд╣реИрдВрдбрд▓рд░ рд╣реЛрдЧрд╛ рдФрд░ рдиреАрдЪреЗ рджрд┐рдП рдЧрдП рдПрд▓реНрдЧреЛрд░рд┐рджрдо рдХреЗ рдЕрдиреБрд╕рд╛рд░ рдЗрд╕рдХрд╛ рдЬрд╡рд╛рдм рджреЗрдЧрд╛ред рдЬрд╣рд╛рдВ рддрдХ тАЛтАЛрдореИрдВ рд╕рдордЭрддрд╛ рд╣реВрдВ, wx.CallLater wx.CallAfter рджрд┐рдП рдЧрдП рд╕рдордп рдкреИрд░рд╛рдореАрдЯрд░ рдХреЗ рд╕рд╛рде рдХреЙрд▓ рдХрд░рддрд╛ рд╣реИ, рддрд╛рдХрд┐ рдпрд╣ рдкрддрд╛ рдЪрд▓реЗ рдХрд┐ рдШрдЯрдирд╛ рдХреЛ рднреЗрдЬрдиреЗ рд╕реЗ рдкрд╣рд▓реЗ рдЗрд╕рдХреЗ рд▓рд┐рдП рдХрд┐рддрдирд╛ рдЗрдВрддрдЬрд╛рд░ рдХрд░рдирд╛ рд╣реИред

рд░реЙрдмрд┐рди рдбрди рдиреЗ рдпрд╣ рднреА рдиреЛрдЯ рдХрд┐рдпрд╛ рдХрд┐ рдЧреНрд▓реЛрдмрд▓ рдЗрдВрдЯрд░рдкреНрд░реЗрдЯрд░ рд▓реЙрдХ (GIL) рдПрдХ рд╕реЗ рдЕрдзрд┐рдХ рдереНрд░реЗрдб рдХреЛ рдПрдХ рд╕рд╛рде рдЪрд▓рд╛рдиреЗ рдХреА рдЕрдиреБрдорддрд┐ рдирд╣реАрдВ рджреЗрдЧрд╛, рдЬреЛ рдХрд┐ рдЗрд╕реНрддреЗрдорд╛рд▓ рдХрд┐рдП рдЬрд╛рдиреЗ рд╡рд╛рд▓реЗ рдкреНрд░реЛрд╕реЗрд╕рд░ рдХреЛрд░ рдХреА рд╕рдВрдЦреНрдпрд╛ рдХреЛ рд╕реАрдорд┐рдд рдХрд░ рд╕рдХрддрд╛ рд╣реИред рджреВрд╕рд░реА рдУрд░, рдЙрдиреНрд╣реЛрдВрдиреЗ рдпрд╣ рднреА рдХрд╣рд╛ рдХрд┐ wxPython рдХреЛ wx рд▓рд╛рдЗрдмреНрд░реЗрд░реА рдХреЗ API рдлрдВрдХреНрд╢рдВрд╕ рдХреЛ рд▓рд╛рдЧреВ рдХрд░рдиреЗ рд╕реЗ GIL рд╕реЗ рдореБрдХреНрдд рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ, рдЗрд╕рд▓рд┐рдП рдЕрдиреНрдп рдереНрд░реЗрдбреНрд╕ рдПрдХ рд╕рд╛рде рдХрд╛рдо рдХрд░ рд╕рдХрддреЗ рд╣реИрдВред рджреВрд╕рд░реЗ рд╢рдмреНрджреЛрдВ рдореЗрдВ, рдорд▓реНрдЯреАрдХреЛрд░ рдорд╢реАрдиреЛрдВ рдкрд░ рдереНрд░реЗрдбреНрд╕ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддреЗ рд╕рдордп рдкреНрд░рджрд░реНрд╢рди рдмрджрд▓ рд╕рдХрддрд╛ рд╣реИред рдЗрд╕ рдореБрджреНрджреЗ рдХреА рдЪрд░реНрдЪрд╛ рджрд┐рд▓рдЪрд╕реНрдк рд╣реЛ рд╕рдХрддреА рд╣реИ рдФрд░ рд╕реНрдкрд╖реНрдЯ рдирд╣реАрдВ ...
рд▓рдЧрднрдЧред рдЯреНрд░рд╛рдВрд╕ред - рдЬреАрдЖрдИрдПрд▓ рдХреЗ рд╕рд╛рде рдЕрдзрд┐рдХ рдкреВрд░реНрдг рдкрд░рд┐рдЪрд┐рдд рдХреЗ рд▓рд┐рдП, рдореИрдВ рдпрд╣рд╛рдВ рдкреВрдЫрддрд╛ рд╣реВрдВред

рд╣рдорд╛рд░реЗ рддреАрди рддрд░реАрдХреЛрдВ рдХреЛ рдЕрдореВрд░реНрддрддрд╛ рдХреЗ рд╕реНрддрд░ рдореЗрдВ рд╡рд┐рднрд╛рдЬрд┐рдд рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИ, wx.CallLater рд╕рдмрд╕реЗ рдКрдкрд░ рд╣реИ, рдЗрд╕рдХреЗ рдмрд╛рдж wx.CallAfter, рдФрд░ wx.PostEvent рд╕рдмрд╕реЗ рдирд┐рдЪрд▓реЗ рд╕реНрддрд░ рдкрд░ рд╣реИред рдирд┐рдореНрдирд▓рд┐рдЦрд┐рдд рдЙрджрд╛рд╣рд░рдгреЛрдВ рдореЗрдВ, рдЖрдк рджреЗрдЦреЗрдВрдЧреЗ рдХрд┐ рдХреИрд╕реЗ Wx.CallAfter рдФрд░ wx.PostEvent рдХрд╛ рдЙрдкрдпреЛрдЧ WxPytson рдХрд╛рд░реНрдпрдХреНрд░рдореЛрдВ рдореЗрдВ рдХрд░реЗрдВред

wxPython, рдереНрд░реЗрдбрд┐рдВрдЧ, wx.CallAfter рдФрд░ PubSub


WxPython рдореЗрд▓рд┐рдВрдЧ рд╕реВрдЪреА рдореЗрдВ, рдЖрдк рджреЗрдЦреЗрдВрдЧреЗ рдХрд┐ рд╡рд┐рд╢реЗрд╖рдЬреНрдЮ рдЕрдиреНрдп рдЙрдкрдпреЛрдЧрдХрд░реНрддрд╛рдУрдВ рдХреЛ рдПрдкреНрд▓рд┐рдХреЗрд╢рди рдФрд░ рдереНрд░реЗрдб рдХреЗ рдмреАрдЪ рд╕рдВрджреЗрд╢реЛрдВ рдХрд╛ рдЖрджрд╛рди-рдкреНрд░рджрд╛рди рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП PubSub рдХреЗ рд╕рд╛рде wx.CallAfter рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдХрд╣реЗрдВрдЧреЗред рдирд┐рдореНрдирд▓рд┐рдЦрд┐рдд рдЙрджрд╛рд╣рд░рдг рдореЗрдВ, рд╣рдо рдЗрд╕реЗ рдкреНрд░рджрд░реНрд╢рд┐рдд рдХрд░реЗрдВрдЧреЗ:
Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  1. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  2. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  3. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  4. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  5. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  6. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  7. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  8. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  9. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  10. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  11. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  12. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  13. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  14. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  15. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  16. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  17. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  18. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  19. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  20. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  21. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  22. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  23. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  24. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  25. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  26. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  27. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  28. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  29. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  30. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  31. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  32. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  33. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  34. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  35. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  36. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  37. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  38. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  39. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  40. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  41. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  42. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  43. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  44. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  45. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  46. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  47. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  48. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  49. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  50. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  51. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  52. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  53. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  54. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  55. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  56. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  57. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  58. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  59. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  60. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  61. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  62. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  63. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()
  64. Copy Source | Copy HTML import time import wx from threading import Thread from wx.lib.pubsub import Publisher ######################################################################## class TestThread (Thread): """Test Worker Thread Class.""" #---------------------------------------------------------------------- def __init__ (self): """Init Worker Thread Class.""" Thread. __init__ (self) self .start() # start the thread #---------------------------------------------------------------------- def run (self): """Run Worker Thread.""" # This is the code executing in the new thread. for i in range ( 6 ): time .sleep( 10 ) wx.CallAfter( self . postTime , i) time .sleep( 5 ) wx.CallAfter(Publisher().sendMessage, "update" , "Thread finished!" ) #---------------------------------------------------------------------- def postTime (self, amt): """ <br/> Send time to GUI <br/> """ amtOfTime = (amt + 1 ) * 10 Publisher().sendMessage( "update" , amtOfTime) ######################################################################## class MyForm (wx.Frame): #---------------------------------------------------------------------- def __init__ (self): wx.Frame. __init__ (self, None, wx.ID_ANY, "Tutorial" ) # Add a panel so it looks the correct on all platforms panel = wx.Panel(self, wx.ID_ANY) self .displayLbl = wx.StaticText(panel, label= "Amount of time since thread started goes here" ) self .btn = btn = wx.Button(panel, label= "Start Thread" ) btn.Bind(wx.EVT_BUTTON, self . onButton ) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add( self .displayLbl, 0 , wx.ALL|wx.CENTER, 5 ) sizer.Add(btn, 0 , wx.ALL|wx.CENTER, 5 ) panel.SetSizer(sizer) # create a pubsub receiver Publisher().subscribe( self . updateDisplay , "update" ) #---------------------------------------------------------------------- def onButton (self, event): """ <br/> Runs the thread <br/> """ TestThread () self .displayLbl.SetLabel( "Thread started!" ) btn = event.GetEventObject() btn.Disable() #---------------------------------------------------------------------- def updateDisplay (self, msg): """ <br/> Receives data from thread and updates the display <br/> """ t = msg.data if isinstance (t, int): self .displayLbl.SetLabel( "Time since thread started: %s seconds" % t) else : self .displayLbl.SetLabel( "%s" % t) self .btn.Enable() #---------------------------------------------------------------------- # Run the program if __name__ == "__main__" : app = wx.PySimpleApp() frame = MyForm ().Show() app.MainLoop()

рдпрд╣ рдЙрджрд╛рд╣рд░рдг рд▓рдВрдмреЗ рд╕рдордп рддрдХ рдЪрд▓рдиреЗ рд╡рд╛рд▓реА рдирдХрд▓реА рдкреНрд░рдХреНрд░рд┐рдпрд╛ рдмрдирд╛рдиреЗ рдХреЗ рд▓рд┐рдП рд╕рдордп рдореЙрдбреНрдпреВрд▓ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддрд╛ рд╣реИред рд╣рд╛рд▓рд╛рдБрдХрд┐, рдЖрдк рдЗрд╕рдХреЗ рдмрдЬрд╛рдп рдХреБрдЫ рдЕрдзрд┐рдХ рдЙрдкрдпреЛрдЧреА рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░ рд╕рдХрддреЗ рд╣реИрдВред рдПрдХ рд╡рд╛рд╕реНрддрд╡рд┐рдХ рдЙрджрд╛рд╣рд░рдг рдореЗрдВ, рдореИрдВ рдПрдбреЛрдм рд░реАрдбрд░ рдЦреЛрд▓рдиреЗ рдФрд░ рдкреНрд░рд┐рдВрдЯ рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдПрдХ рдкреАрдбреАрдПрдл рднреЗрдЬрдиреЗ рдХреЗ рд▓рд┐рдП рдПрдХ рд╕реНрдЯреНрд░реАрдо рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рддрд╛ рд╣реВрдВред рдпрд╣ рдСрдкрд░реЗрд╢рди рдирд┐рд░рд░реНрдердХ рд▓рдЧ рд╕рдХрддрд╛ рд╣реИ, рд▓реЗрдХрд┐рди рдЬрдм рдореИрдВ рдереНрд░реЗрдбреНрд╕ рдХрд╛ рдЙрдкрдпреЛрдЧ рдирд╣реАрдВ рдХрд░рддрд╛ рд╣реВрдВ, рддреЛ рдореЗрд░реЗ рдЖрд╡реЗрджрди рдореЗрдВ рдкреНрд░рд┐рдВрдЯ рдмрдЯрди рджрдмрд╛рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ рдЬрдм рддрдХ рдХрд┐ рджрд╕реНрддрд╛рд╡реЗрдЬрд╝ рдкреНрд░рд┐рдВрдЯрд░ рдкрд░ рдирд╣реАрдВ рднреЗрдЬрд╛ рдЬрд╛рддрд╛ рд╣реИ рдФрд░ рдХрд╛рд░реНрд░рд╡рд╛рдИ рдкреВрд░реА рд╣реЛрдиреЗ рддрдХ рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рд╕реНрдерд┐рд░ рд░рд╣рддрд╛ рд╣реИред рдпрд╣рд╛рдВ рддрдХ тАЛтАЛрдХрд┐ рдПрдХ рдпрд╛ рджреЛ рдЙрдкрдпреЛрдЧрдХрд░реНрддрд╛ рдХреЗ рд▓рд┐рдП рдЙрд▓реНрд▓реЗрдЦрдиреАрдп рд╣реИрдВ!

рдПрдХ рддрд░реАрдХрд╛ рдпрд╛ рджреВрд╕рд░рд╛, рдЖрдЗрдП рджреЗрдЦреЗрдВ рдХрд┐ рдпрд╣ рдХреИрд╕реЗ рдХрд╛рдо рдХрд░рддрд╛ рд╣реИред рд╣рдорд╛рд░реЗ рдереНрд░реЗрдб рдХреНрд▓рд╛рд╕ (рдиреАрдЪреЗ рд╡рд░реНрдгрд┐рдд) рдореЗрдВ, рд╣рдордиреЗ рдЖрд╡рд╢реНрдпрдХрддрд╛рдиреБрд╕рд╛рд░ "рд░рди" рд╡рд┐рдзрд┐ рдХреЛ рдлрд┐рд░ рд╕реЗ рдкрд░рд┐рднрд╛рд╖рд┐рдд рдХрд┐рдпрд╛ред рдпрд╣ рдзрд╛рдЧрд╛ рддрдм рд╢реБрд░реВ рд╣реЛрддрд╛ рд╣реИ рдЬрдм рд╣рдо рдЗрд╕реЗ рдмрдирд╛рддреЗ рд╣реИрдВ рдХреНрдпреЛрдВрдХрд┐ рд╣рдорд╛рд░реЗ рдкрд╛рд╕ __init__ рд╡рд┐рдзрд┐ рдореЗрдВ "self.start ()" рд╣реИред "рд░рди" рд╡рд┐рдзрд┐ рдореЗрдВ, рд╣рдо рдкреНрд░рддреНрдпреЗрдХ 10 рд╕реЗрдХрдВрдб рдореЗрдВ рд▓реВрдк рдХрд░рддреЗ рд╣реИрдВ, 6 рдмрд╛рд░ wx.CallAfter рдФрд░ PubSub рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рд╣рдорд╛рд░реЗ рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рдХреЗ рд▓рд┐рдП рдПрдХ рдЕрдкрдбреЗрдЯ рд╣реЛрддрд╛ рд╣реИред рдЬрдм рдЪрдХреНрд░ рдкреВрд░рд╛ рд╣реЛ рдЬрд╛рддрд╛ рд╣реИ, рддреЛ рд╣рдо рдЙрдкрдпреЛрдЧрдХрд░реНрддрд╛ рдХреЛ рдЗрд╕рдХреЗ рдмрд╛рд░реЗ рдореЗрдВ рд╕реВрдЪрд┐рдд рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рд╣рдорд╛рд░реЗ рдЖрд╡реЗрджрди рдХреЛ рдЕрдВрддрд┐рдо рд╕рдВрджреЗрд╢ рднреЗрдЬрддреЗ рд╣реИрдВред

Copy Source | Copy HTML
  1. ################################################## ######################
  2. рдХреНрд▓рд╛рд╕ рдЯреЗрд╕реНрдЯрд╣реНрд░реЗрдб (рдереНрд░реЗрдб):
  3. "" "рдЯреЗрд╕реНрдЯ рд╡рд░реНрдХрд░ рдереНрд░реЗрдб рдХреНрд▓рд╛рд╕ред" ""
  4. # ------------------------------------------------- ---------------------
  5. def __init__ (рд╕реНрд╡):
  6. "" рдЗрдирд┐рдЯ рд╡рд░реНрдХрд░ рдереНрд░реЗрдб рдХреНрд▓рд╛рд╕ред ""
  7. рдереНрд░реЗрдбред __in__ (рд╕реНрд╡)
  8. self .start () # рдереНрд░реЗрдб рдкреНрд░рд╛рд░рдВрдн рдХрд░реЗрдВ
  9. # ------------------------------------------------- ---------------------
  10. рдбреАрдИрдПрдл рд░рди (рд╕реНрд╡):
  11. "" "рд╡рд░реНрдХрд░ рдереНрд░реЗрдб рдЪрд▓рд╛рдПрдБред" "
  12. # рдпрд╣ рдирдП рдереНрд░реЗрдб рдореЗрдВ рдХреЛрдб рдирд┐рд╖реНрдкрд╛рджрд┐рдд рд╣реИред
  13. рдореИрдВ рд╕реАрдорд╛ рдореЗрдВ ( 6 ):
  14. рд╕рдордпред рд╕реЛ ( 10 )
  15. wx.CallAfter ( рд╕реНрд╡ ред рдкреЛрд╕реНрдЯрдЯрд╛рдЗрдо , i)
  16. рд╕рдордпред рд╕реНрд▓реАрдк ( 5 )
  17. wx.CallAfter (рдкреНрд░рдХрд╛рд╢рдХ) (ред sendMessage, "update" , "рдереНрд░реЗрдб рд╕рдорд╛рдкреНрдд!"
  18. # ------------------------------------------------- ---------------------
  19. рдбреАрдИрдЯреА рдкреЛрд╕реНрдЯрдЯрд╛рдЗрдо (рд╕реНрд╡рдпрдВ, рдПрдордЯреА ):
  20. "" " <br/> GUI рдХреЛ рд╕рдордп рднреЗрдЬреЗрдВ <br/> " "
  21. amtOfTime = (amt + 1 ) * резреж
  22. рдкреНрд░рдХрд╛рд╢рдХ ()ред SendMessage ( "рдЕрдкрдбреЗрдЯ" , amtOfTime)


рд╣рдорд╛рд░реЗ рдХреЛрдб рдореЗрдВ, рдПрдХ рдмрдЯрди рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ рдПрдХ рдереНрд░реЗрдб рд╢реБрд░реВ рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред рдЙрд╕реА рд╕рдордп, рд╣рдо рдЗрд╕реЗ рдирд┐рд╖реНрдХреНрд░рд┐рдп рдХрд░ рджреЗрддреЗ рд╣реИрдВ рддрд╛рдХрд┐ рдЧрд▓рддреА рд╕реЗ рдЕрддрд┐рд░рд┐рдХреНрдд рдзрд╛рдЧреЗ рд╢реБрд░реВ рди рдХрд░реЗрдВ, рдЕрдиреНрдпрдерд╛ рд╡рд┐рднрд┐рдиреНрди рдереНрд░реЗрдбреНрд╕ рд╕реЗ рд╡рд┐рднрд┐рдиреНрди рдЧрдВрджреЗ рд╕рдВрджреЗрд╢ рджрд┐рдЦрд╛рдИ рджреЗрдВрдЧреЗ рдФрд░ рдпрд╣ рдХреЗрд╡рд▓ рд╣рдореЗрдВ рднреНрд░рдорд┐рдд рдХрд░реЗрдЧрд╛ред рд╣рд╛рд▓рд╛рдВрдХрд┐ рдЗрд╕реЗ рдЕрдЪреНрдЫреЗ рдЙрдкрдпреЛрдЧ рдХреЗ рд▓рд┐рдП рдЗрд╕реНрддреЗрдорд╛рд▓ рдХрд┐рдпрд╛ рдЬрд╛ рд╕рдХрддрд╛ рд╣реИред рдЖрдк рд╕реНрдЯреНрд░реАрдо рдХреЗ рдкреАрдЖрдИрдбреА тАЛтАЛрдХреЛ рдпрд╣ рдЬрд╛рдирдиреЗ рдХреЗ рд▓рд┐рдП рджрд┐рдЦрд╛ рд╕рдХрддреЗ рд╣реИрдВ рдХрд┐ рдХреМрди рд╕рд╛ рд╣реИ рдФрд░ рдПрдХ рд╕реНрдХреНрд░реЙрд▓рд┐рдВрдЧ рд▓рд╛рдЗрди рдореЗрдВ рд╕реВрдЪрдирд╛ рдХреЛ рдПрдХ рд╕рд╛рде рдХрдИ рдзрд╛рд░рд╛рдУрдВ рдХреЗ рд╕рдВрдЪрд╛рд▓рди рдХреЗ рд▓рд┐рдП рдкреНрд░рджрд░реНрд╢рд┐рдд рдХрд░рддрд╛ рд╣реИред

рд╣рдорд╛рд░реЗ рдХреЛрдб рдХрд╛ рдЕрдВрддрд┐рдо рджрд┐рд▓рдЪрд╕реНрдк рд╣рд┐рд╕реНрд╕рд╛ PubSub рд╣реИ, рдЬреЛ рдИрд╡реЗрдВрдЯ рдФрд░ рдЗрд╡реЗрдВрдЯ рд╣реИрдВрдбрд▓рд░ рдХреЛ рд╕реНрд╡реАрдХрд╛рд░ рдХрд░рддрд╛ рд╣реИ:

Copy Source | Copy HTML
  1. рдбреАрдИрдПрдлрд╝ рдЕрдкрдбреЗрдЯ рдбрд┐рд╕реЗрдкреНрд▓реЗ (рд╕реНрд╡рдпрдВ, рд╕рдВрджреЗрд╢):
  2. "" " <br/> рдереНрд░реЗрдб рд╕реЗ рдбреЗрдЯрд╛ рдкреНрд░рд╛рдкреНрдд рдХрд░рддрд╛ рд╣реИ рдФрд░ рдбрд┐рд╕реНрдкреНрд▓реЗ рдХреЛ рдЕрдкрдбреЗрдЯ рдХрд░рддрд╛ рд╣реИ <br/> " "
  3. t = msg.data
  4. рдпрджрд┐ рдкреНрд░рддрд┐рдкреВрд░реНрддрд┐ (рдЯреА, рдЗрдВрдЯ):
  5. рд╕реНрд╡рдпрдВ .displayLbl.SetLabel ( "рдереНрд░реЗрдб рд╢реБрд░реВ рд╣реЛрдиреЗ рдХрд╛ рд╕рдордп:% s рд╕реЗрдХрдВрдб" % t)
  6. рдФрд░ :
  7. рд╕реНрд╡рдпрдВ .displayLbl.SetLabel ( "% s" % t)
  8. рд╕реНрд╡ .btn.Enable ()


рдЗрд╕рд▓рд┐рдП, рд╣рдо рд╕реНрдЯреНрд░реАрдо рд╕реЗ рд╕рдВрджреЗрд╢ рдирд┐рдХрд╛рд▓рддреЗ рд╣реИрдВ рдФрд░ рдЕрдкрдирд╛ рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рдЕрдкрдбреЗрдЯ рдХрд░рддреЗ рд╣реИрдВред рдРрд╕рд╛ рдХрд░рдиреЗ рдореЗрдВ, рд╣рдо рдЙрдкрдпреЛрдЧрдХрд░реНрддрд╛ рдХреЛ рджрд┐рдЦрд╛рдиреЗ рдХреЗ рд▓рд┐рдП рдирд┐рд░реНрдзрд╛рд░рд┐рдд рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рд╕рдВрджреЗрд╢ рдХреЗ рдбреЗрдЯрд╛ рдкреНрд░рдХрд╛рд░ рдХреА рдЬрд╛рдВрдЪ рдХрд░рддреЗ рд╣реИрдВред рдЕрдм рдПрдХ рд╕реНрддрд░ рдиреАрдЪреЗ рдЬрд╛рддреЗ рд╣реИрдВ рдФрд░ wx.PostEvent рдХреЗ рд╕рд╛рде рднреА рдРрд╕рд╛ рд╣реА рдХрд░рдиреЗ рдХреА рдХреЛрд╢рд┐рд╢ рдХрд░рддреЗ рд╣реИрдВред

рдзрд╛рд░рд╛рдПрдБ рдФрд░ wx.PostEvent


рдиреАрдЪреЗ рджрд┐рдпрд╛ рдЧрдпрд╛ рдХреЛрдб рдЗрд╕ wxPython wiki рдЙрджрд╛рд╣рд░рдг рдкрд░ рдЖрдзрд╛рд░рд┐рдд рд╣реИред рдпрд╣ рдХреЛрдб рдкрд╣рд▓реЗ рджрд┐рдП рдЧрдП рдХреА рддреБрд▓рдирд╛ рдореЗрдВ рдереЛрдбрд╝рд╛ рдЕрдзрд┐рдХ рдЬрдЯрд┐рд▓ рд╣реИ, рд▓реЗрдХрд┐рди рдореБрдЭреЗ рд▓рдЧрддрд╛ рд╣реИ рдХрд┐ рдЗрд╕реЗ рд╕рдордЭрдирд╛ рдореБрд╢реНрдХрд┐рд▓ рдирд╣реАрдВ рд╣реИред

Copy Source | Copy HTML
  1. рдЖрдпрд╛рдд рд╕рдордп
  2. рдЖрдпрд╛рдд wx
  3. рдЗрдореНрдкреЛрд░реНрдЯ рдереНрд░реЗрдбрд┐рдВрдЧ рд╕реЗ
  4. # рдзрд╛рдЧрд╛ рдкреВрд░рд╛ рд╣реЛрдиреЗ рдХреЗ рд▓рд┐рдП рдЕрдзрд┐рд╕реВрдЪрдирд╛ рдШрдЯрдирд╛ рдХреЛ рдкрд░рд┐рднрд╛рд╖рд┐рдд рдХрд░реЗрдВ
  5. EVT_RESULT_ID = wx.NewId ()
  6. EVT_RESULT рдХреЛ рд╣рд░рд╛рдпрд╛ (рдЬреАрдд, рджреБрд░реНрдЧрдВрдз ):
  7. "" "рдкрд░рд┐рдгрд╛рдо рдШрдЯрдирд╛ рдХреЛ рдкрд░рд┐рднрд╛рд╖рд┐рдд рдХрд░реЗрдВред" ""
  8. win.Connect (- 1 , - 1 , EVT_RESULT_ID, func)
  9. рд╡рд░реНрдЧ рдкрд░рд┐рдгрд╛рдо (wx.PyEvent):
  10. "" "рдордирдорд╛рдирд╛ рдкрд░рд┐рдгрд╛рдо рдбреЗрдЯрд╛ рд▓реЗ рдЬрд╛рдиреЗ рдХреЗ рд▓рд┐рдП рд╕рд░рд▓ рдШрдЯрдирд╛ред" "
  11. def __init__ (рд╕реНрд╡, рдбреЗрдЯрд╛):
  12. "" "Init Result Eventред" "
  13. wx.PyEventред __in__ (рд╕реНрд╡)
  14. рд╕реНрд╡рдпрдВ .SEEventType (EVT_RESULT_ID)
  15. рд╕реНрд╡ .рдбрд╛рдЯрд╛ = рдбреЗрдЯрд╛
  16. ################################################## ######################
  17. рдХреНрд▓рд╛рд╕ рдЯреЗрд╕реНрдЯрд╣реНрд░реЗрдб (рдереНрд░реЗрдб):
  18. "" "рдЯреЗрд╕реНрдЯ рд╡рд░реНрдХрд░ рдереНрд░реЗрдб рдХреНрд▓рд╛рд╕ред" ""
  19. # ------------------------------------------------- ---------------------
  20. def __init__ (рд╕реНрд╡, wxObject):
  21. "" рдЗрдирд┐рдЯ рд╡рд░реНрдХрд░ рдереНрд░реЗрдб рдХреНрд▓рд╛рд╕ред ""
  22. рдереНрд░реЗрдбред __in__ (рд╕реНрд╡)
  23. self .wxObject = wxObject
  24. self .start () # рдереНрд░реЗрдб рдкреНрд░рд╛рд░рдВрдн рдХрд░реЗрдВ
  25. # ------------------------------------------------- ---------------------
  26. рдбреАрдИрдПрдл рд░рди (рд╕реНрд╡):
  27. "" "рд╡рд░реНрдХрд░ рдереНрд░реЗрдб рдЪрд▓рд╛рдПрдБред" "
  28. # рдпрд╣ рдирдП рдереНрд░реЗрдб рдореЗрдВ рдХреЛрдб рдирд┐рд╖реНрдкрд╛рджрд┐рдд рд╣реИред
  29. рдореИрдВ рд╕реАрдорд╛ рдореЗрдВ ( 6 ):
  30. рд╕рдордпред рд╕реЛ ( 10 )
  31. amtOfTime = (i + 1 ) * 10
  32. wx.PostEvent ( рд╕реНрд╡рдпрдВ .wxObject, рдкрд░рд┐рдгрд╛рдо (amtOfTime))
  33. рд╕рдордпред рд╕реНрд▓реАрдк ( 5 )
  34. wx.PostEvent ( рдЖрддреНрдо .wxObject, рдкрд░рд┐рдгрд╛рдо) ( "рдереНрд░реЗрдб рд╕рдорд╛рдкреНрдд!" ) !
  35. ################################################## ######################
  36. рд╡рд░реНрдЧ MyForm (wx.Frame):
  37. # ------------------------------------------------- ---------------------
  38. def __init__ (рд╕реНрд╡):
  39. wx.Frameред __in__ (рд╕реНрд╡рдпрдВ, рдХреЛрдИ рдирд╣реАрдВ, wx.ID_ANY, "рдЯреНрдпреВрдЯреЛрд░рд┐рдпрд▓" )
  40. # рдПрдХ рдкреИрдирд▓ рдЬреЛрдбрд╝реЗрдВ рддрд╛рдХрд┐ рдпрд╣ рд╕рднреА рдкреНрд▓реЗрдЯрдлрд╛рд░реНрдореЛрдВ рдкрд░ рд╕рд╣реА рд▓рдЧреЗ
  41. рдкреИрдирд▓ = wx.Panel (рд╕реНрд╡рдпрдВ, wx.ID_ANY)
  42. рд╕реНрд╡ред displayLbl = wx.StaticText (рдкреИрдирд▓, рд▓реЗрдмрд▓ = "рдереНрд░реЗрдб рд╢реБрд░реВ рд╣реЛрдиреЗ рдХреЗ рдмрд╛рдж рдХреА рд╕рдордп рдХреА рдорд╛рддреНрд░рд╛ рдпрд╣рд╛рдБ" )
  43. рдЖрддреНрдо .btn = btn = wx.Button (рдкреИрдирд▓, рд▓реЗрдмрд▓ = "рдереНрд░реЗрдб рдкреНрд░рд╛рд░рдВрдн рдХрд░реЗрдВ" )
  44. btn.Bind (wx.EVT_BUTTON, рд╕реНрд╡ ред рдСрдирдмрдЯрди )
  45. sizer = wx.BoxSizer (wx.VERTICAL)
  46. sizer.Add ( рд╕реНрд╡рдпрдВ .displayLbl, 0 , wx.ALL | wx.CENTER, 5 )
  47. sizer.Add (btn, 0 , wx.ALL | wx.CENTER, 5 )
  48. рдкреИрдирд▓ред
  49. # рдХрд┐рд╕реА рднреА рд╡рд░реНрдХрд░ рдереНрд░реЗрдб рд░рд┐рдЬрд▓реНрдЯ рдХреЗ рд▓рд┐рдП рдЗрд╡реЗрдВрдЯ рд╣реИрдВрдбрд▓рд░ рд╕реЗрдЯ рдХрд░реЗрдВ
  50. EVT_RESULT (рд╕реНрд╡рдпрдВ, рд╕реНрд╡ ред рдЕрдкрдбреЗрдЯрдбрд┐рд╕рдкреНрд▓реЗ )
  51. # ------------------------------------------------- ---------------------
  52. рдмреАрдЯ рдСрдирдЯрди (рд╕реНрд╡рдпрдВ, рдШрдЯрдирд╛):
  53. "" " <br/> рдереНрд░реЗрдб рдЪрд▓рд╛рддрд╛ рд╣реИ <br/> " "
  54. рдЯреЗрд╕реНрдЯрдереНрд░реЗрдб (рд╕реНрд╡)
  55. рд╕реНрд╡рдпрдВ .displayLbl.SetLabel ( "рдереНрд░реЗрдб рдкреНрд░рд╛рд░рдВрдн!"
  56. btn = event.GetEventObject ()
  57. btn.Disable ()
  58. # ------------------------------------------------- ---------------------
  59. рдбреАрдИрдПрдлрд╝ рдЕрдкрдбреЗрдЯ рдбрд┐рд╕реЗрдкреНрд▓реЗ (рд╕реНрд╡рдпрдВ, рд╕рдВрджреЗрд╢):
  60. "" " <br/> рдереНрд░реЗрдб рд╕реЗ рдбреЗрдЯрд╛ рдкреНрд░рд╛рдкреНрдд рдХрд░рддрд╛ рд╣реИ рдФрд░ рдбрд┐рд╕реНрдкреНрд▓реЗ рдХреЛ рдЕрдкрдбреЗрдЯ рдХрд░рддрд╛ рд╣реИ <br/> " "
  61. t = msg.data
  62. рдпрджрд┐ рдкреНрд░рддрд┐рдкреВрд░реНрддрд┐ (рдЯреА, рдЗрдВрдЯ):
  63. рд╕реНрд╡рдпрдВ .displayLbl.SetLabel ( "рдереНрд░реЗрдб рд╢реБрд░реВ рд╣реЛрдиреЗ рдХрд╛ рд╕рдордп:% s рд╕реЗрдХрдВрдб" % t)
  64. рдФрд░ :
  65. рд╕реНрд╡рдпрдВ .displayLbl.SetLabel ( "% s" % t)
  66. рд╕реНрд╡ .btn.Enable ()
  67. # ------------------------------------------------- ---------------------
  68. # рдкреНрд░реЛрдЧреНрд░рд╛рдо рдЪрд▓рд╛рдПрдВ
  69. рдЕрдЧрд░ __name__ == "__main__" :
  70. app = wx.PySimpleApp ()
  71. рдлреНрд░реЗрдо = MyForm () .Show ()
  72. app.MainLoop ()


рдЪрд▓реЛ рдЗрд╕реЗ рдереЛрдбрд╝рд╛ рд▓реЗ рд▓реЛред рдореЗрд░реЗ рд▓рд┐рдП рдкрд╣рд▓реЗ рддреАрди рднрд╛рдЧ рд╕рдмрд╕реЗ рдЕрдзрд┐рдХ рднреНрд░рдорд┐рдд рдХрд░рдиреЗ рд╡рд╛рд▓реЗ рд╣реИрдВ:

Copy Source | Copy HTML
  1. # рдзрд╛рдЧрд╛ рдкреВрд░рд╛ рд╣реЛрдиреЗ рдХреЗ рд▓рд┐рдП рдЕрдзрд┐рд╕реВрдЪрдирд╛ рдШрдЯрдирд╛ рдХреЛ рдкрд░рд┐рднрд╛рд╖рд┐рдд рдХрд░реЗрдВ
  2. EVT_RESULT_ID = wx.NewId ()
  3. EVT_RESULT рдХреЛ рд╣рд░рд╛рдпрд╛ (рдЬреАрдд, рджреБрд░реНрдЧрдВрдз ):
  4. "" "рдкрд░рд┐рдгрд╛рдо рдШрдЯрдирд╛ рдХреЛ рдкрд░рд┐рднрд╛рд╖рд┐рдд рдХрд░реЗрдВред" ""
  5. win.Connect (- 1 , - 1 , EVT_RESULT_ID, func)
  6. рд╡рд░реНрдЧ рдкрд░рд┐рдгрд╛рдо (wx.PyEvent):
  7. "" "рдордирдорд╛рдирд╛ рдкрд░рд┐рдгрд╛рдо рдбреЗрдЯрд╛ рд▓реЗ рдЬрд╛рдиреЗ рдХреЗ рд▓рд┐рдП рд╕рд░рд▓ рдШрдЯрдирд╛ред" "
  8. def __init__ (рд╕реНрд╡, рдбреЗрдЯрд╛):
  9. "" "Init Result Eventред" "
  10. wx.PyEventред __in__ (рд╕реНрд╡)
  11. рд╕реНрд╡рдпрдВ .SEEventType (EVT_RESULT_ID)
  12. рд╕реНрд╡ .рдбрд╛рдЯрд╛ = рдбреЗрдЯрд╛


EVT_RESULT_ID рдпрд╣рд╛рдВ рдХреБрдВрдЬреА рд╣реИ, рдЬреЛ рдХрд┐ EVT_RESULT рдлрд╝рдВрдХреНрд╢рди рдХреЛ рдкрд░рд┐рдгрд╛рдо рд╡рд░реНрдЧ рдХреЗ рд╕рд╛рде рдЬреЛрдбрд╝рддреА рд╣реИред EVT_RESULT рдлрд╝рдВрдХреНрд╢рди рдХрд╛ рдЙрдкрдпреЛрдЧ рдХрд░рдХреЗ, рд╣рдо рдИрд╡реЗрдВрдЯ рд╣реИрдВрдбрд▓рд░ рд╕реЗрдЯ рдХрд░рддреЗ рд╣реИрдВ рдЬреЛ рд╣рдорд╛рд░реА рд╕реНрдЯреНрд░реАрдо рдЬреЗрдирд░реЗрдЯ рдХрд░рддрд╛ рд╣реИред Wx.PostEvent рдлрд╝рдВрдХреНрд╢рди рдкрд░рд┐рдгрд╛рдо рдХреЛ рд╕реНрдЯреНрд░реАрдо рд╕реЗ рдкрд░рд┐рдгрд╛рдо рдкрд░рд┐рдгрд╛рдо рд╡рд░реНрдЧ рддрдХ рд▓реЗ рдЬрд╛рддрд╛ рд╣реИ, рдЬреЛ рддрдм рдкрд╣рд▓реЗ рд╕реЗ рд╕реНрдерд╛рдкрд┐рдд рдИрд╡реЗрдВрдЯ рд╣реИрдВрдбрд▓рд░ рджреНрд╡рд╛рд░рд╛ рд╕рдВрд╕рд╛рдзрд┐рдд рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред

рд╣рдорд╛рд░реА рдЯреЗрд╕реНрдЯрдереНрд░реЗрдб рдХреНрд▓рд╛рд╕ рд▓рдЧрднрдЧ рд╡реИрд╕реА рд╣реА рдХрд╛рдо рдХрд░рддреА рд╣реИ рдЬреИрд╕реА рд╣рдордиреЗ рдкрд╣рд▓реЗ рдХреА рдереА, рд╕рд┐рд╡рд╛рдп рдЗрд╕рдХреЗ рдХрд┐ рд╣рдордиреЗ PubSub рдХреЗ рдмрдЬрд╛рдп wx.PostEvent рдХрд╛ рдЗрд╕реНрддреЗрдорд╛рд▓ рдХрд┐рдпрд╛ред рдЗрдВрдЯрд░рдлрд╝реЗрд╕ рдХреЛ рдЕрдкрдбреЗрдЯ рдХрд░рдиреЗ рд╡рд╛рд▓реЗ рд╣рдорд╛рд░реЗ рдИрд╡реЗрдВрдЯ рд╣реИрдВрдбрд▓рд░ рдХрд╛ рдХреЛрдб рдирд╣реАрдВ рдмрджрд▓рд╛ рд╣реИред

рдирд┐рд╖реНрдХрд░реНрд╖


рдореБрдЭреЗ рдЙрдореНрдореАрдж рд╣реИ рдХрд┐ рдЕрдм рдЖрдк рдЬрд╛рдирддреЗ рд╣реИрдВ рдХрд┐ рдЕрдкрдиреЗ wxPython рдХрд╛рд░реНрдпрдХреНрд░рдореЛрдВ рдореЗрдВ рдореВрд▓ рдкреНрд░рд╡рд╛рд╣ рд╡рд┐рдзрд┐рдпреЛрдВ рдХрд╛ рдЙрдкрдпреЛрдЧ рдХреИрд╕реЗ рдХрд░реЗрдВред рдзрд╛рдЧреЗ рдХреЗ рд╕рд╛рде рдХрд╛рдо рдХрд░рдиреЗ рдХреЗ рд▓рд┐рдП рдХрдИ рдЕрдиреНрдп рддрд░реАрдХреЗ рд╣реИрдВ, рд▓реЗрдХрд┐рди рд╡реЗ рдЗрд╕ рд▓реЗрдЦ рдореЗрдВ рдирд╣реАрдВ рдорд╛рдиреЗ рдЬрд╛рддреЗ рд╣реИрдВ, рдЙрджрд╛рд╣рд░рдг рдХреЗ рд▓рд┐рдП wx.Yield рдпрд╛ Queuesред рд╕реМрднрд╛рдЧреНрдп рд╕реЗ, wxPython рд╡рд┐рдХреА рдЗрди рд╡рд┐рд╖рдпреЛрдВ рдХреЛ рдЕрдЪреНрдЫреА рддрд░рд╣ рд╕реЗ рдХрд╡рд░ рдХрд░рддрд╛ рд╣реИ, рдЗрд╕рд▓рд┐рдП рдпрджрд┐ рдЖрдк рдЗрди рд╡рд┐рдзрд┐рдпреЛрдВ рдореЗрдВ рд░реБрдЪрд┐ рд░рдЦрддреЗ рд╣реИрдВ, рддреЛ рдиреАрдЪреЗ рджрд┐рдП рдЧрдП рд▓рд┐рдВрдХ рдХреА рдЬрд╛рдВрдЪ рдХрд░рдирд╛ рд╕реБрдирд┐рд╢реНрдЪрд┐рдд рдХрд░реЗрдВред

рдЕрддрд┐рд░рд┐рдХреНрдд рд╕рд╛рдордЧреНрд░реА


Source: https://habr.com/ru/post/In118664/


All Articles