fix servicePosition
[enigma2.git] / lib / python / Components / ServicePosition.py
1 from PerServiceDisplay import *
2 from enigma import eTimer
3
4
5 from enigma import pNavigation, iSeekableServicePtr
6
7 class ServicePosition(PerServiceDisplay):
8         TYPE_LENGTH = 0,
9         TYPE_POSITION = 1,
10         TYPE_REMAINING = 2
11         
12         def __init__(self, navcore, type):
13                 self.updateTimer = eTimer()
14                 self.updateTimer.timeout.get().append(self.update)
15                 PerServiceDisplay.__init__(self, navcore,
16                         {
17                                 pNavigation.evNewService: self.newService,
18                                 pNavigation.evStopService: self.stopEvent
19                         })
20                 self.type = type
21 #               self.setType(type)
22
23         def newService(self):
24                 self.setType(self.type)
25         
26         def setType(self, type):
27                 self.type = type
28                 
29                 seek = iSeekableServicePtr()
30                 service = self.navcore.getCurrentService()
31                 
32                 self.updateTimer.stop()
33                 self.available = 0
34                 
35                 if service != None:
36                         seek = service.seek()
37                         if seek != None:
38                                 if self.type != self.TYPE_LENGTH:
39                                         self.updateTimer.start(500)
40                                 
41                                 self.length = self.get(self.TYPE_LENGTH)
42                                 self.available = 1
43
44                 self.update()
45         
46         def get(self, what):
47                 service = self.navcore.getCurrentService()
48                 
49                 if service != None:
50                         seek = service.seek()
51                         if seek != None:
52                                 if what == self.TYPE_LENGTH:
53                                         r = seek.getLength()
54                                 elif what == self.TYPE_POSITION:
55                                         r = seek.getPlayPosition()
56                                 if not r[0]:
57                                         return r[1] / 90000
58                 
59                 return -1
60         
61         def update(self):
62                 if self.available:
63                         if self.type == self.TYPE_LENGTH:
64                                 l = self.length
65                         elif self.type == self.TYPE_POSITION:
66                                 l = self.get(self.TYPE_POSITION)
67                         elif self.type == self.TYPE_REMAINING:
68                                 l = self.length - self.get(self.TYPE_POSITION)
69                         
70                         self.setText("%d:%02d" % (l/60, l%60))
71                 else:
72                         self.setText("-:--")
73         
74         def stopEvent(self):
75                 self.updateTimer.stop()
76                 self.setText("");