1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
# Author: Prabhu Ramachandran
# Copyright (c) 2006-2018, Enthought, Inc.
# License: BSD Style.
"""
Event-loop based timers that perform actions periodically.
Note that if a timer goes out of scope without a reference to being saved,
there is nothing keeping the underlying toolkit timer alive and it will be
garbage collected, meaning that the timer will stop firing (or indeed, may
never fire).
"""
from pyface.toolkit import toolkit_object
from pyface.timer.i_timer import MCallbackTimer, MEventTimer
PyfaceTimer = toolkit_object('timer.timer:PyfaceTimer')
class EventTimer(MEventTimer, PyfaceTimer):
pass
class CallbackTimer(MCallbackTimer, PyfaceTimer):
pass
class Timer(CallbackTimer):
""" Subclass of CallbackTimer that matches the old API """
def __init__(self, millisecs, callable, *args, **kwargs):
""" Initialize and start the timer.
Initialize instance to invoke the given `callable` with given
arguments and keyword args after every `millisecs` (milliseconds).
"""
interval = millisecs / 1000.0
super(Timer, self).__init__(
interval=interval,
callback=callable,
args=args,
kwargs=kwargs,
)
self.start()
def Notify(self):
""" Alias for `perform` to match old API.
"""
self.perform()
def Start(self, millisecs=None):
""" Alias for `start` to match old API.
"""
if millisecs is not None:
self.interval = millisecs / 1000.0
self.start()
def Stop(self):
""" Alias for `stop` to match old API.
"""
self.stop()
def IsRunning(self):
""" Alias for is_running property to match old API.
"""
return self._active
|