<s> import logging <EOL> from rx . disposables import Disposable , SingleAssignmentDisposable , CompositeDisposable <EOL> from rx . concurrency . scheduler import Scheduler <EOL> log = logging . getLogger ( "<STR_LIT>" ) <EOL> class QtScheduler ( Scheduler ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , qtcore ) : <EOL> self . qtcore = qtcore <EOL> self . _timers = set ( ) <EOL> def _qtimer_schedule ( self , time , action , state , periodic = False ) : <EOL> scheduler = self <EOL> msecs = self . to_relative ( time ) <EOL> disposable = SingleAssignmentDisposable ( ) <EOL> periodic_state = [ state ] <EOL> def interval ( ) : <EOL> if periodic : <EOL> periodic_state [ <NUM_LIT:0> ] = action ( periodic_state [ <NUM_LIT:0> ] ) <EOL> else : <EOL> disposable . disposable = action ( scheduler , state ) <EOL> log . debug ( "<STR_LIT>" , msecs ) <EOL> timer = self . qtcore . QTimer ( ) <EOL> timer . setSingleShot ( not periodic ) <EOL> timer . timeout . connect ( interval ) <EOL> timer . setInterval ( msecs ) <EOL> timer . start ( ) <EOL> self . _timers . add ( timer ) <EOL> def dispose ( ) : <EOL> timer . stop ( ) <EOL> self . _timers . remove ( timer ) <EOL> return CompositeDisposable ( disposable , Disposable ( dispose ) ) <EOL> def schedule ( self , action , state = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _qtimer_schedule ( <NUM_LIT:0> , action , state ) <EOL> def schedule_relative ( self , duetime , action , state = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _qtimer_schedule ( duetime , action , state ) <EOL> def schedule_absolute ( self , duetime , action , state = None ) : <EOL> """<STR_LIT>""" <EOL> duetime = self . to_datetime ( duetime ) <EOL> return self . _qtimer_schedule ( duetime , action , state ) <EOL> def schedule_periodic ( self , period , action , state = None ) : <EOL> """<STR_LIT>""" <EOL> return self . _qtimer_schedule ( period , action , state , periodic = True ) </s>
