fix typo and resize text in image upgrade wizard
[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.setEvent(self.event)
43                 self.setService(self.currentService)
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                 self.currentService=service
66                 if self.isRecording:
67                         self["channel"].setText(_("Recording"))
68                 else:
69                         name = self.currentService.getServiceName()
70                         if name is not None:
71                                 self["channel"].setText(name)
72                         else:
73                                 self["channel"].setText(_("unknown service"))
74
75         def sort_func(self,x,y):
76                 if x[1] < y[1]:
77                         return -1
78                 elif x[1] == y[1]:
79                         return 0
80                 else:
81                         return 1
82
83         def setEvent(self, event):
84                 self.event = event
85                 id = event.getEventId()
86
87                 refstr = str(self.currentService)
88                 epgcache = eEPGCache.getInstance()
89                 text = event.getEventName()
90                 short = event.getShortDescription()
91                 ext = event.getExtendedDescription()
92                 if len(short) > 0 and short != text:
93                         text = text + '\n\n' + short
94                 if len(ext) > 0:
95                         if len(text) > 0:
96                                 text = text + '\n\n'
97                         text = text + ext
98
99          # search similar broadcastings
100                 ret = epgcache.search(('NB', 100, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, id))
101                 if ret is not None:
102                         text += '\n\n' + _('Similar broadcasts:')
103                         ret.sort(self.sort_func)
104                         for x in ret:
105                                 t = localtime(x[1])
106                                 text += '\n%d.%d.%d, %02d:%02d  -  %s'%(t[2], t[1], t[0], t[3], t[4], x[0])
107
108                 self.setTitle(event.getEventName())
109                 self["epg_description"].setText(text)
110                 self["datetime"].setText(event.getBeginTimeString())
111                 self["duration"].setText(_("%d min")%(event.getDuration()/60))
112
113         def pageUp(self):
114                 self["epg_description"].pageUp()
115
116         def pageDown(self):
117                 self["epg_description"].pageDown()
118
119 class EventViewSimple(Screen, EventViewBase):
120         def __init__(self, session, Event, Ref, callback=None):
121                 Screen.__init__(self, session)
122                 self.skinName = "EventView"
123                 EventViewBase.__init__(self, Event, Ref, callback)
124
125 class EventViewEPGSelect(Screen, EventViewBase):
126         def __init__(self, session, Event, Ref, callback=None, singleEPGCB=None, multiEPGCB=None):
127                 Screen.__init__(self, session)
128                 self.skinName = "EventView"
129                 EventViewBase.__init__(self, Event, Ref, callback)
130                 self["key_yellow"].setText(_("Single EPG"))
131                 self["key_blue"].setText(_("Multi EPG"))
132                 self["epgactions"] = ActionMap(["EventViewEPGActions"],
133                         {
134                                 "openSingleServiceEPG": singleEPGCB,
135                                 "openMultiServiceEPG": multiEPGCB
136                         })