16 def __init__(self, begin, end):
18 self.prepare_time = 10
24 return self.begin - self.prepare_time
31 return self.getTime() < o.getTime()
33 def activate(self, event):
34 print "timer %s got activated (%d)!" % (self.description, event)
42 self.processed_timers = [ ]
45 self.timer.timeout.get().append(self.calcNextActivation)
47 self.calcNextActivation()
49 def addTimerEntry(self, entry):
50 bisect.insort(self.timer_list, entry)
51 self.calcNextActivation()
53 def setNextActivation(self, when):
54 delay = int((when - time()) * 1000)
55 print "next activation: %d (in %d seconds)" % (when, delay)
57 self.timer.start(delay, 1)
60 def calcNextActivation(self):
61 self.processActivation()
63 min = int(time()) + self.MaxWaitTime
65 # calculate next activation point
66 if len(self.timer_list):
67 w = self.timer_list[0].getTime()
71 self.setNextActivation(min)
73 def doActivate(self, w):
75 self.timer_list.remove(w)
77 if w.state < TimerEntry.StateEnded:
78 bisect.insort(self.timer_list, w)
80 bisect.insort(self.processed_timers, w)
82 def processActivation(self):
85 # we keep on processing the first entry until it goes into the future.
86 while len(self.timer_list) and self.timer_list[0].getTime() < t:
87 self.doActivate(self.timer_list[0])
91 #t.addTimerEntry(TimerEntry(base+10, base+20, None, None, "test #1: 10 - 20"))
92 #t.addTimerEntry(TimerEntry(base+10, base+30, None, None, "test #2: 10 - 30"))
93 #t.addTimerEntry(TimerEntry(base+15, base+20, None, None, "test #3: 15 - 20"))
94 #t.addTimerEntry(TimerEntry(base+20, base+35, None, None, "test #4: 20 - 35"))