make length and position return pts-based values
[enigma2.git] / lib / python / Components / Converter / ServicePosition.py
1 from Converter import Converter
2 from Poll import Poll
3 from enigma import iPlayableService
4
5 class ServicePosition(Converter, Poll, object):
6         TYPE_LENGTH = 0,
7         TYPE_POSITION = 1,
8         TYPE_REMAINING = 2,
9         TYPE_GAUGE = 3
10         
11         def __init__(self, type, *args, **kwargs):
12                 Poll.__init__(self)
13                 Converter.__init__(self)
14                 if type == "Length":
15                         self.type = self.TYPE_LENGTH
16                 elif type == "Position":
17                         self.type = self.TYPE_POSITION
18                 elif type == "Remaining":
19                         self.type = self.TYPE_REMAINING
20                 elif type == "Gauge":
21                         self.type = self.TYPE_GAUGE
22
23                 self.poll_interval = 500
24                 self.poll_enabled = self.type != self.TYPE_LENGTH
25         
26         def getSeek(self):
27                 s = self.source.service
28                 return s and s.seek()
29         
30         def getPosition(self):
31                 seek = self.getSeek()
32                 if seek is None:
33                         return None
34                 pos = seek.getPlayPosition()
35                 if pos[0]:
36                         return 0
37                 return pos[1]
38         
39         def getLength(self):
40                 seek = self.getSeek()
41                 if seek is None:
42                         return None
43                 length = seek.getLength()
44                 if length[0]:
45                         return 0
46                 return length[1]
47         
48         def getCutlist(self):
49                 service = self.source.service
50                 cue = service and service.cueSheet()
51                 return cue and cue.getCutList()
52         
53         def getText(self):
54                 seek = self.getSeek()
55                 if seek is None:
56                         return ""
57                 else:
58                         if self.type == self.TYPE_LENGTH:
59                                 l = self.length
60                         elif self.type == self.TYPE_POSITION:
61                                 l = self.position
62                         elif self.type == self.TYPE_REMAINING:
63                                 l = self.length - self.position
64                         
65                         l /= 90000
66                         return "%d:%02d" % (l/60, l%60)
67
68         position = property(getPosition)
69         length = property(getLength)
70         cutlist = property(getCutlist)
71         text = property(getText)
72         
73         def changed(self, *args):
74                 cutlist_refresh = len(args) and args[0] in [iPlayableService.evCuesheetChanged, iPlayableService.evStart, iPlayableService.evEnd]
75                 time_refresh = not len(args) or args[0] in [iPlayableService.evStart, iPlayableService.evEnd]
76                 
77                 if cutlist_refresh:
78                         if self.type == self.TYPE_GAUGE:
79                                 self.downstream_elements.cutlist_changed()
80
81                 if time_refresh:
82                         self.downstream_elements.changed()