1 from Converter import Converter
3 from enigma import iPlayableService
4 from Components.Element import cached, ElementError
6 class ServicePosition(Poll, Converter, object):
12 def __init__(self, type):
14 Converter.__init__(self, type)
16 args = type.split(',')
19 self.negate = 'Negate' in args
20 self.detailed = 'Detailed' in args
21 self.showHours = 'ShowHours' in args
22 self.showNoSeconds = 'ShowNoSeconds' in args
25 self.type = self.TYPE_LENGTH
26 elif type == "Position":
27 self.type = self.TYPE_POSITION
28 elif type == "Remaining":
29 self.type = self.TYPE_REMAINING
31 self.type = self.TYPE_GAUGE
33 raise ElementError("type must be {Length|Position|Remaining|Gauge} with optional arguments {Negate|Detailed|ShowHours|ShowNoSeconds} for ServicePosition converter")
36 self.poll_interval = 100
37 elif self.type == self.TYPE_LENGTH:
38 self.poll_interval = 2000
40 self.poll_interval = 500
42 self.poll_enabled = True
45 s = self.source.service
49 def getPosition(self):
53 pos = seek.getPlayPosition()
63 length = seek.getLength()
70 service = self.source.service
71 cue = service and service.cueSheet()
72 return cue and cue.getCutList()
80 if self.type == self.TYPE_LENGTH:
82 elif self.type == self.TYPE_POSITION:
84 elif self.type == self.TYPE_REMAINING:
85 l = self.length - self.position
90 if self.negate: l = -l
100 if self.showNoSeconds:
101 return sign + "%d:%02d" % (l/3600, l%3600/60)
103 return sign + "%d:%02d:%02d" % (l/3600, l%3600/60, l%60)
105 if self.showNoSeconds:
106 return sign + "%d" % (l/60)
108 return sign + "%d:%02d" % (l/60, l%60)
111 return sign + "%d:%02d:%02d:%03d" % ((l/3600/90000), (l/90000)%3600/60, (l/90000)%60, (l%90000)/90)
113 return sign + "%d:%02d:%03d" % ((l/60/90000), (l/90000)%60, (l%90000)/90)
115 # range/value are for the Progress renderer
122 if pos is None or len is None or len <= 0:
124 return pos * 10000 / len
126 position = property(getPosition)
127 length = property(getLength)
128 cutlist = property(getCutlist)
129 text = property(getText)
130 value = property(getValue)
132 def changed(self, what):
133 cutlist_refresh = what[0] != self.CHANGED_SPECIFIC or what[1] in (iPlayableService.evCuesheetChanged,)
134 time_refresh = what[0] == self.CHANGED_POLL or what[0] == self.CHANGED_SPECIFIC and what[1] in (iPlayableService.evCuesheetChanged,)
137 if self.type == self.TYPE_GAUGE:
138 self.downstream_elements.cutlist_changed()
141 self.downstream_elements.changed(what)