fix bug in EpgList.py (line 79, in getCurrent .. TypeError: unscribtable object)
[enigma2.git] / lib / python / Screens / EventView.py
1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.Button import Button
4 from Components.Label import Label
5 from Components.ScrollLabel import ScrollLabel
6 from enigma import eServiceEventPtr, eEPGCachePtr, eEPGCache
7 from ServiceReference import ServiceReference
8 from RecordTimer import RecordTimerEntry, parseEvent
9 from TimerEntry import TimerEntry
10 from time import localtime, asctime
11
12 class EventViewBase:
13         def __init__(self, Event, Ref, callback=None):
14                 self.cbFunc = callback
15                 self.currentService=Ref
16                 self.isRecording = len(Ref.ref.getPath())
17                 self.event = Event
18                 self["epg_description"] = ScrollLabel()
19                 self["datetime"] = Label()
20                 self["channel"] = Label()
21                 self["duration"] = Label()
22                 self["key_red"] = Button("")
23                 if self.isRecording:
24                         self["key_green"] = Button("")
25                 else:
26                         self["key_green"] = Button(_("Add timer"))
27                 self["key_yellow"] = Button("")
28                 self["key_blue"] = Button("")
29                 self["actions"] = ActionMap(["OkCancelActions", "EventViewActions"],
30                         {
31                                 "cancel": self.close,
32                                 "ok": self.close,
33                                 "pageUp": self.pageUp,
34                                 "pageDown": self.pageDown,
35                                 "prevEvent": self.prevEvent,
36                                 "nextEvent": self.nextEvent,
37                                 "timerAdd": self.timerAdd
38                         })
39                 self.onShown.append(self.onCreate)
40
41         def onCreate(self):
42                 self.setService(self.currentService)
43                 self.setEvent(self.event)
44
45         def prevEvent(self):
46                 if self.cbFunc is not None:
47                         self.cbFunc(self.setEvent, self.setService, -1)
48
49         def nextEvent(self):
50                 if self.cbFunc is not None:
51                         self.cbFunc(self.setEvent, self.setService, +1)
52
53         def timerAdd(self):
54                 if not self.isRecording:
55                         newEntry = RecordTimerEntry(self.currentService, *parseEvent(self.event))
56                         self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
57
58         def timerEditFinished(self, answer):
59                 if (answer[0]):
60                         self.session.nav.RecordTimer.record(answer[1])
61                 else:
62                         print "Timeredit aborted"
63
64         def setService(self, service):
65                 
66                 self.currentService=service
67                 if self.isRecording:
68                         self["channel"].setText(_("Recording"))
69                 else:
70                         name = self.currentService.getServiceName()
71                         if name is not None:
72                                 self["channel"].setText(name)
73                         else:
74                                 self["channel"].setText(_("unknown service"))
75
76         def sort_func(self,x,y):
77                 if x[1] < y[1]:
78                         return -1
79                 elif x[1] == y[1]:
80                         return 0
81                 else:
82                         return 1
83
84         def setEvent(self, event):
85                 self.event = event
86                 id = event.getEventId()
87
88                 refstr = str(self.currentService)
89                 epgcache = eEPGCache.getInstance()
90                 text = event.getEventName()
91                 short = event.getShortDescription()
92                 ext = event.getExtendedDescription()
93                 if len(short) > 0 and short != text:
94                         text = text + '\n\n' + short
95                 if len(ext) > 0:
96                         if len(text) > 0:
97                                 text = text + '\n\n'
98                         text = text + ext
99
100          # search similar broadcastings
101                 ret = epgcache.search(('NB', 100, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, id))
102                 if ret is not None:
103                         text += '\n\n' + _('Similar broadcasts:')
104                         ret.sort(self.sort_func)
105                         for x in ret:
106                                 t = localtime(x[1])
107                                 text += '\n%d.%d.%d, %02d:%02d  -  %s'%(t[2], t[1], t[0], t[3], t[4], x[0])
108
109                 self.setTitle(event.getEventName())
110                 self["epg_description"].setText(text)
111                 self["datetime"].setText(event.getBeginTimeString())
112                 self["duration"].setText(_("%d min")%(event.getDuration()/60))
113
114         def pageUp(self):
115                 self["epg_description"].pageUp()
116
117         def pageDown(self):
118                 self["epg_description"].pageDown()
119
120 class EventViewSimple(Screen, EventViewBase):
121         def __init__(self, session, Event, Ref, callback=None):
122                 Screen.__init__(self, session)
123                 self.skinName = "EventView"
124                 EventViewBase.__init__(self, Event, Ref, callback)
125
126 class EventViewEPGSelect(Screen, EventViewBase):
127         def __init__(self, session, Event, Ref, callback=None, singleEPGCB=None, multiEPGCB=None):
128                 Screen.__init__(self, session)
129                 self.skinName = "EventView"
130                 EventViewBase.__init__(self, Event, Ref, callback)
131                 self["key_yellow"].setText(_("Single EPG"))
132                 self["key_blue"].setText(_("Multi EPG"))
133                 self["epgactions"] = ActionMap(["EventViewEPGActions"],
134                         {
135                                 "openSingleServiceEPG": singleEPGCB,
136                                 "openMultiServiceEPG": multiEPGCB
137                         })