<s> import threading <EOL> import time <EOL> import wx <EOL> from python_toolbox . wx_tools . timing import cute_base_timer <EOL> wxEVT_THREAD_TIMER = wx . NewEventType ( ) <EOL> EVT_THREAD_TIMER = wx . PyEventBinder ( wxEVT_THREAD_TIMER , <NUM_LIT:1> ) <EOL> '''<STR_LIT>''' <EOL> class ThreadTimer ( cute_base_timer . CuteBaseTimer ) : <EOL> '''<STR_LIT>''' <EOL> n = <NUM_LIT:0> <EOL> '''<STR_LIT>''' <EOL> _EventHandlerGrokker__event_code = EVT_THREAD_TIMER <EOL> def __init__ ( self , parent ) : <EOL> '''<STR_LIT>''' <EOL> cute_base_timer . CuteBaseTimer . __init__ ( self , parent ) <EOL> self . parent = parent <EOL> '''<STR_LIT>''' <EOL> ThreadTimer . n += <NUM_LIT:1> <EOL> self . wx_id = wx . NewId ( ) <EOL> '''<STR_LIT>''' <EOL> self . __init_thread ( ) <EOL> self . alive = False <EOL> '''<STR_LIT>''' <EOL> def __init_thread ( self ) : <EOL> '''<STR_LIT>''' <EOL> thread_name = '<STR_LIT>' . join ( ( '<STR_LIT>' , str ( self . n ) ) ) <EOL> self . thread = Thread ( self , name = thread_name ) <EOL> def start ( self , interval ) : <EOL> '''<STR_LIT>''' <EOL> if self . alive : <EOL> self . stop ( ) <EOL> self . interval = interval <EOL> self . alive = True <EOL> self . thread . start ( ) <EOL> def stop ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . alive = False <EOL> self . thread . retired = True <EOL> self . __init_thread ( ) <EOL> Start = start <EOL> Stop = stop <EOL> def GetId ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . wx_id <EOL> class Thread ( threading . Thread ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , parent , name ) : <EOL> threading . Thread . __init__ ( self , name = name ) <EOL> self . parent = parent <EOL> self . retired = False <EOL> def run ( self ) : <EOL> '''<STR_LIT>''' <EOL> interval_in_seconds = self . parent . interval / <NUM_LIT> <EOL> def sleep ( ) : <EOL> time . sleep ( interval_in_seconds ) <EOL> sleep ( ) <EOL> try : <EOL> while self . parent . alive is True and self . retired is False : <EOL> event = wx . PyEvent ( self . parent . wx_id ) <EOL> event . SetEventType ( wxEVT_THREAD_TIMER ) <EOL> wx . PostEvent ( self . parent . parent , event ) <EOL> sleep ( ) <EOL> except : <EOL> return </s>
