1 from Converter import Converter
4 from Components.Element import cached
6 class EventTime(Poll, Converter, object):
13 def __init__(self, type):
14 Converter.__init__(self, type)
17 self.type = self.ENDTIME
18 elif type == "Remaining":
19 self.type = self.REMAINING
20 self.poll_interval = 60*1000
21 self.poll_enabled = True
22 elif type == "StartTime":
23 self.type = self.STARTTIME
24 elif type == "Duration":
25 self.type = self.DURATION
26 elif type == "Progress":
27 self.type = self.PROGRESS
28 self.poll_interval = 30*1000
29 self.poll_enabled = True
31 raise str("'%s' is not <StartTime|EndTime|Remaining|Duration|Progress> for EventTime converter" % type)
35 assert self.type != self.PROGRESS
37 event = self.source.event
41 if self.type == self.STARTTIME:
42 return event.getBeginTime()
43 elif self.type == self.ENDTIME:
44 return event.getBeginTime() + event.getDuration()
45 elif self.type == self.DURATION:
46 return event.getDuration()
47 elif self.type == self.REMAINING:
49 start_time = event.getBeginTime()
50 duration = event.getDuration()
51 end_time = start_time + duration
52 if start_time <= now <= end_time:
53 return (duration, end_time - now)
55 return (duration, None)
59 assert self.type == self.PROGRESS
61 event = self.source.event
66 start_time = event.getBeginTime()
67 duration = event.getDuration()
68 if start_time <= now <= (start_time + duration) and duration > 0:
69 return (now - start_time) * 1000 / duration
73 time = property(getTime)
74 value = property(getValue)
77 def changed(self, what):
78 Converter.changed(self, what)
79 if self.type == self.PROGRESS and len(self.downstream_elements):
80 if not self.source.event and self.downstream_elements[0].visible:
81 self.downstream_elements[0].visible = False
82 elif self.source.event and not self.downstream_elements[0].visible:
83 self.downstream_elements[0].visible = True