for motor 200ms to powerup before send diseqc command should be enough to
[enigma2.git] / lib / python / Components / Converter / ServicePosition.py
1 from Converter import Converter
2 from Poll import Poll
3 from enigma import iPlayableService
4 from Components.Element import cached
5
6 class ServicePosition(Converter, Poll, object):
7         TYPE_LENGTH = 0
8         TYPE_POSITION = 1
9         TYPE_REMAINING = 2
10         TYPE_GAUGE = 3
11         TYPE_POSITION_DETAILED = 4
12
13         def __init__(self, type):
14                 Poll.__init__(self)
15                 Converter.__init__(self, type)
16
17                 self.poll_interval = 500
18
19                 if type == "Length":
20                         self.type = self.TYPE_LENGTH
21                 elif type == "Position":
22                         self.type = self.TYPE_POSITION
23                 elif type == "PositionDetailed":
24                         self.type = self.TYPE_POSITION_DETAILED
25                         self.poll_interval = 100
26                 elif type == "Remaining":
27                         self.type = self.TYPE_REMAINING
28                 elif type == "Gauge":
29                         self.type = self.TYPE_GAUGE
30
31                 self.poll_enabled = self.type != self.TYPE_LENGTH
32
33         def getSeek(self):
34                 s = self.source.service
35                 return s and s.seek()
36
37         @cached
38         def getPosition(self):
39                 seek = self.getSeek()
40                 if seek is None:
41                         return None
42                 pos = seek.getPlayPosition()
43                 if pos[0]:
44                         return 0
45                 return pos[1]
46
47         @cached
48         def getLength(self):
49                 seek = self.getSeek()
50                 if seek is None:
51                         return None
52                 length = seek.getLength()
53                 if length[0]:
54                         return 0
55                 return length[1]
56
57         @cached
58         def getCutlist(self):
59                 service = self.source.service
60                 cue = service and service.cueSheet()
61                 return cue and cue.getCutList()
62
63         @cached
64         def getText(self):
65                 seek = self.getSeek()
66                 if seek is None:
67                         return ""
68                 else:
69                         if self.type == self.TYPE_LENGTH:
70                                 l = self.length
71                         elif self.type in [self.TYPE_POSITION, self.TYPE_POSITION_DETAILED]:
72                                 l = self.position
73                         elif self.type == self.TYPE_REMAINING:
74                                 l = self.length - self.position
75
76                         if self.type != self.TYPE_POSITION_DETAILED:
77                                 l /= 90000
78
79                         if l > 0:
80                                 sign = ""
81                         else:
82                                 l = -l
83                                 sign = "-"
84
85                         if self.type != self.TYPE_POSITION_DETAILED:
86                                 return sign + "%d:%02d" % (l/60, l%60)
87                         else:
88                                 return sign + "%d:%02d:%03d" % ((l/60/90000), (l/90000)%60, (l%90000)/90)
89
90         position = property(getPosition)
91         length = property(getLength)
92         cutlist = property(getCutlist)
93         text = property(getText)
94
95         def changed(self, what):
96                 cutlist_refresh = what[0] != self.CHANGED_SPECIFIC or what[1] in [iPlayableService.evCuesheetChanged]
97                 time_refresh = what[0] == self.CHANGED_POLL or what[0] == self.CHANGED_SPECIFIC and what[1] in [iPlayableService.evCuesheetChanged]
98
99                 if cutlist_refresh:
100                         if self.type == self.TYPE_GAUGE:
101                                 self.downstream_elements.cutlist_changed()
102
103                 if time_refresh:
104                         self.downstream_elements.changed(what)