5f905f38ef9f694c33c87b452dcf16824c914a22
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Sources / EventInfo.py
1 from Components.PerServiceDisplay import PerServiceBase
2 from Components.Element import cached
3 from enigma import iPlayableService, iServiceInformation, eServiceReference, eEPGCache
4 from Source import Source
5
6 class EventInfo(PerServiceBase, Source, object):
7         NOW = 0
8         NEXT = 1
9
10         def __init__(self, navcore, now_or_next):
11                 Source.__init__(self)
12                 PerServiceBase.__init__(self, navcore,
13                         {
14                                 iPlayableService.evStart: self.gotEvent,
15                                 iPlayableService.evUpdatedEventInfo: self.gotEvent,
16                                 iPlayableService.evEnd: self.gotEvent
17                         }, with_event=True)
18                 self.now_or_next = now_or_next
19                 self.epgQuery = eEPGCache.getInstance().lookupEventTime
20
21         @cached
22         def getEvent(self):
23                 service = self.navcore.getCurrentService()
24                 info = service and service.info()
25                 ret = info and info.getEvent(self.now_or_next)
26                 if not ret and info:
27                         refstr = info.getInfoString(iServiceInformation.sServiceref)
28                         ret = self.epgQuery(eServiceReference(refstr), -1, self.now_or_next and 1 or 0)
29                 return ret
30
31         event = property(getEvent)
32
33         def gotEvent(self, what):
34                 if what == iPlayableService.evEnd:
35                         self.changed((self.CHANGED_CLEAR,))
36                 else:
37                         self.changed((self.CHANGED_ALL,))
38
39         def destroy(self):
40                 PerServiceBase.destroy(self)
41                 Source.destroy(self)
42