- 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):
|
def __str__(self):
|
||||||
return self.name
|
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):
|
class TimerListener(abc.ABC):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
@@ -44,17 +55,13 @@ class TimerManager(object):
|
|||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
for timer in self.timers:
|
for timer in self.timers:
|
||||||
now = time.time()
|
if timer.isElapsed():
|
||||||
if timer.isActive:
|
if timer.listener is not None:
|
||||||
if timer.elapseTime <= now:
|
timer.listener.onTimer(timer)
|
||||||
if timer.listener:
|
timer.count += 1
|
||||||
if 'periodic' in timer.mode:
|
|
||||||
timer.start(timer.interval)
|
|
||||||
timer.listener.onTimer(timer)
|
|
||||||
timer.count += 1
|
|
||||||
|
|
||||||
def getMinTimeout(self):
|
def getMinTimeout(self, default=1.0):
|
||||||
minTimeout = None
|
minTimeout = default
|
||||||
timeouts = []
|
timeouts = []
|
||||||
for timer in self.timers:
|
for timer in self.timers:
|
||||||
now = time.time()
|
now = time.time()
|
||||||
@@ -90,7 +97,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while(True):
|
while(True):
|
||||||
wait = self.timerMgr.getMinTimeout()
|
wait = self.timerMgr.getMinTimeout(None)
|
||||||
if wait is None:
|
if wait is None:
|
||||||
break
|
break
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
|
|||||||
Reference in New Issue
Block a user