- use timer also without handler
git-svn-id: http://moon:8086/svn/projects/HendiControl@257 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
+18
-11
@@ -26,6 +26,17 @@ class Timer(object):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def isElapsed(self):
|
||||
result = False
|
||||
now = time.time()
|
||||
if self.isActive:
|
||||
if self.elapseTime <= now:
|
||||
result = True
|
||||
if 'periodic' in self.mode:
|
||||
self.start(self.interval, self.mode)
|
||||
|
||||
return result
|
||||
|
||||
class TimerListener(abc.ABC):
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -44,17 +55,13 @@ class TimerManager(object):
|
||||
|
||||
def process(self):
|
||||
for timer in self.timers:
|
||||
now = time.time()
|
||||
if timer.isActive:
|
||||
if timer.elapseTime <= now:
|
||||
if timer.listener:
|
||||
if 'periodic' in timer.mode:
|
||||
timer.start(timer.interval)
|
||||
timer.listener.onTimer(timer)
|
||||
timer.count += 1
|
||||
if timer.isElapsed():
|
||||
if timer.listener is not None:
|
||||
timer.listener.onTimer(timer)
|
||||
timer.count += 1
|
||||
|
||||
def getMinTimeout(self):
|
||||
minTimeout = None
|
||||
def getMinTimeout(self, default=1.0):
|
||||
minTimeout = default
|
||||
timeouts = []
|
||||
for timer in self.timers:
|
||||
now = time.time()
|
||||
@@ -90,7 +97,7 @@ if __name__ == '__main__':
|
||||
|
||||
def run(self):
|
||||
while(True):
|
||||
wait = self.timerMgr.getMinTimeout()
|
||||
wait = self.timerMgr.getMinTimeout(None)
|
||||
if wait is None:
|
||||
break
|
||||
time.sleep(wait)
|
||||
|
||||
Reference in New Issue
Block a user