add InfoBarTimeshiftState, fix timeshift after zap, fix seekactions
[enigma2.git] / lib / python / Components / EventInfo.py
1 from PerServiceDisplay import *
2 from time import strftime
3 from time import localtime, time
4
5 from enigma import iServiceInformationPtr, eServiceEventPtr
6
7 class EventInfo(PerServiceDisplay):
8         Now = 0
9         Next = 1
10         Now_Duration = 2
11         Next_Duration = 3
12         Now_StartTime = 4
13         Next_StartTime = 5
14         Now_Remaining = 6
15         
16         def __init__(self, navcore, now_or_next):
17                 # listen to evUpdatedEventInfo and evEnd
18                 # note that evEnd will be called once to establish a known state
19                 self.now_or_next = now_or_next
20                 PerServiceDisplay.__init__(self, navcore, 
21                         { 
22                                 iPlayableService.evUpdatedEventInfo: self.ourEvent, 
23                                 iPlayableService.evEnd: self.stopEvent 
24                         })
25                 
26                 if now_or_next in [self.Now_Remaining]:
27                         self.enablePolling()
28
29         def ourEvent(self):
30                 info = iServiceInformationPtr()
31                 service = self.navcore.getCurrentService()
32                 
33                 if service != None:
34                         info = service.info()
35                         if info is not None: 
36                                 ev = info.getEvent(self.now_or_next & 1)
37                                 if ev is not None:
38                                         self.update(ev)
39
40         def update(self, ev):
41                 if self.now_or_next == self.Now_Remaining and ev.getBeginTime() <= time() <= (ev.getBeginTime() + ev.getDuration()):
42                         self.setText("+%d min" % ((ev.getBeginTime() + ev.getDuration() - time()) / 60))
43                 elif self.now_or_next in [self.Now_Duration, self.Next_Duration, self.Now_Remaining]:
44                         self.setText("%d min" % (ev.getDuration() / 60))
45                 elif self.now_or_next in [self.Now_StartTime, self.Next_StartTime]:
46                         self.setText(strftime("%H:%M", localtime(ev.getBeginTime())))
47                 elif self.now_or_next in [self.Now, self.Next]:
48                         self.setText(ev.getEventName())         
49
50         def stopEvent(self):
51                 self.setText(
52                         ("", "", "",  "", "--:--", "--:--", "")[self.now_or_next]);
53
54         def poll(self):
55                 self.ourEvent()
56
57 class EventInfoProgress(PerServiceDisplayProgress, EventInfo):
58         def __init__(self, navcore, now_or_next):
59                 self.now_or_next = now_or_next
60                 PerServiceDisplayProgress.__init__(self, navcore, 
61                         { 
62                                 iPlayableService.evUpdatedEventInfo: self.ourEvent, 
63                                 iPlayableService.evEnd: self.stopEvent 
64                         })
65
66         def update(self, ev):
67                 self.g.setRange(0, ev.getDuration())
68                 progress = int(time() - ev.getBeginTime())
69
70                 self.setValue(progress)
71                 
72         def stopEvent(self):
73                 self.setValue(0)