<s> """<STR_LIT>""" <EOL> import os <EOL> import signal <EOL> import sys <EOL> import time <EOL> from timeit import default_timer as clock <EOL> import wx <EOL> import collections <EOL> if os . name == '<STR_LIT>' : <EOL> import select <EOL> elif sys . platform == '<STR_LIT:win32>' : <EOL> import msvcrt <EOL> def stdin_ready ( ) : <EOL> if os . name == '<STR_LIT>' : <EOL> infds , outfds , erfds = select . select ( [ sys . stdin ] , [ ] , [ ] , <NUM_LIT:0> ) <EOL> if infds : <EOL> return True <EOL> else : <EOL> return False <EOL> elif sys . platform == '<STR_LIT:win32>' : <EOL> return msvcrt . kbhit ( ) <EOL> def inputhook_wx1 ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> app = wx . GetApp ( ) <EOL> if app is not None : <EOL> assert wx . Thread_IsMain ( ) <EOL> evtloop = wx . EventLoop ( ) <EOL> ea = wx . EventLoopActivator ( evtloop ) <EOL> while evtloop . Pending ( ) : <EOL> evtloop . Dispatch ( ) <EOL> app . ProcessIdle ( ) <EOL> del ea <EOL> except KeyboardInterrupt : <EOL> pass <EOL> return <NUM_LIT:0> <EOL> class EventLoopTimer ( wx . Timer ) : <EOL> def __init__ ( self , func ) : <EOL> self . func = func <EOL> wx . Timer . __init__ ( self ) <EOL> def Notify ( self ) : <EOL> self . func ( ) <EOL> class EventLoopRunner ( object ) : <EOL> def Run ( self , time ) : <EOL> self . evtloop = wx . EventLoop ( ) <EOL> self . timer = EventLoopTimer ( self . check_stdin ) <EOL> self . timer . Start ( time ) <EOL> self . evtloop . Run ( ) <EOL> def check_stdin ( self ) : <EOL> if stdin_ready ( ) : <EOL> self . timer . Stop ( ) <EOL> self . evtloop . Exit ( ) <EOL> def inputhook_wx2 ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> app = wx . GetApp ( ) <EOL> if app is not None : <EOL> assert wx . Thread_IsMain ( ) <EOL> elr = EventLoopRunner ( ) <EOL> elr . Run ( time = <NUM_LIT:10> ) <EOL> except KeyboardInterrupt : <EOL> pass <EOL> return <NUM_LIT:0> <EOL> def inputhook_wx3 ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> app = wx . GetApp ( ) <EOL> if app is not None : <EOL> assert wx . Thread_IsMain ( ) <EOL> if not isinstance ( signal . getsignal ( signal . SIGINT ) , collections . Callable ) : <EOL> signal . signal ( signal . SIGINT , signal . default_int_handler ) <EOL> evtloop = wx . EventLoop ( ) <EOL> ea = wx . EventLoopActivator ( evtloop ) <EOL> t = clock ( ) <EOL> while not stdin_ready ( ) : <EOL> while evtloop . Pending ( ) : <EOL> t = clock ( ) <EOL> evtloop . Dispatch ( ) <EOL> app . ProcessIdle ( ) <EOL> used_time = clock ( ) - t <EOL> if used_time > <NUM_LIT:5> * <NUM_LIT> : <EOL> time . sleep ( <NUM_LIT> ) <EOL> elif used_time > <NUM_LIT> : <EOL> time . sleep ( <NUM_LIT:1.0> ) <EOL> elif used_time > <NUM_LIT:0.1> : <EOL> time . sleep ( <NUM_LIT> ) <EOL> else : <EOL> time . sleep ( <NUM_LIT> ) <EOL> del ea <EOL> except KeyboardInterrupt : <EOL> pass <EOL> return <NUM_LIT:0> <EOL> inputhook_wx = inputhook_wx3 </s>
