fix cancel handling
[enigma2.git] / lib / python / Components / ServicePosition.py
1 from PerServiceDisplay import *
2 from enigma import eTimer
3
4
5 from enigma import iPlayableService, 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                                 iPlayableService.evStart: self.newService,
18                                 iPlayableService.evEnd: 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                 self.updateTimer.start(500)
30                 self.update()
31         
32         def get(self, what):
33                 service = self.navcore.getCurrentService()
34                 
35                 if service != None:
36                         seek = service.seek()
37                         if seek != None:
38                                 if what == self.TYPE_LENGTH:
39                                         r = seek.getLength()
40                                 elif what == self.TYPE_POSITION:
41                                         r = seek.getPlayPosition()
42                                 if not r[0]:
43                                         return r[1] / 90000
44                 
45                 return -1
46         
47         def update(self):
48                 seek = None
49                 service = self.navcore.getCurrentService()
50                 if service != None:
51                         seek = service.seek()
52
53                 if seek is not None:
54                         if self.type == self.TYPE_LENGTH:
55                                 l = self.get(self.TYPE_LENGTH)
56                         elif self.type == self.TYPE_POSITION:
57                                 l = self.get(self.TYPE_POSITION)
58                         elif self.type == self.TYPE_REMAINING:
59                                 l = self.get(self.TYPE_LENGTH) - self.get(self.TYPE_POSITION)
60                         
61                         self.setText("%d:%02d" % (l/60, l%60))
62                         self.updateTimer.start(500)
63                 else:
64                         self.updateTimer.start(10000)
65                         self.setText("-:--")
66         
67         def stopEvent(self):
68                 self.updateTimer.stop()
69                 self.setText("");