minimum backward seek is 16X
[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
7 from ServiceReference import ServiceReference
8 from RecordTimer import RecordTimerEntry, parseEvent
9 from TimerEntry import TimerEntry
10
11 class EventViewBase:
12         def __init__(self, Event, Ref, callback=None):
13                 self.cbFunc = callback
14                 self.currentService=Ref
15                 self.event = Event
16                 self["epg_description"] = ScrollLabel()
17                 self["datetime"] = Label()
18                 self["channel"] = Label()
19                 self["duration"] = Label()
20                 self["key_red"] = Button("")
21                 self["key_green"] = Button(_("Add Timer"))
22                 self["key_yellow"] = Button("")
23                 self["key_blue"] = Button("")
24                 self["actions"] = ActionMap(["OkCancelActions", "EventViewActions"],
25                         {
26                                 "cancel": self.close,
27                                 "ok": self.close,
28                                 "pageUp": self.pageUp,
29                                 "pageDown": self.pageDown,
30                                 "prevEvent": self.prevEvent,
31                                 "nextEvent": self.nextEvent,
32                                 "timerAdd": self.timerAdd
33                         })
34                 self.onShown.append(self.onCreate)
35
36         def onCreate(self):
37                 self.setEvent(self.event)
38                 self.setService(self.currentService)
39
40         def prevEvent(self):
41                 if self.cbFunc is not None:
42                         self.cbFunc(self.setEvent, self.setService, -1)
43
44         def nextEvent(self):
45                 if self.cbFunc is not None:
46                         self.cbFunc(self.setEvent, self.setService, +1)
47
48         def timerAdd(self):
49                 newEntry = RecordTimerEntry(self.currentService, *parseEvent(self.event))
50                 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
51
52         def timerEditFinished(self, answer):
53                 if (answer[0]):
54                         self.session.nav.RecordTimer.record(answer[1])
55                 else:
56                         print "Timeredit aborted"
57
58         def setService(self, service):
59                 self.currentService=service
60                 name = self.currentService.getServiceName()
61                 if name is not None:
62                         self["channel"].setText(name)
63                 else:
64                         self["channel"].setText(_("unknown service"))
65
66         def setEvent(self, event):
67                 self.event = event
68                 text = event.getEventName()
69                 short = event.getShortDescription()
70                 ext = event.getExtendedDescription()
71                 if len(short) > 0 and short != text:
72                         text = text + '\n\n' + short
73                 if len(ext) > 0:
74                         if len(text) > 0:
75                                 text = text + '\n\n'
76                         text = text + ext
77                 self.session.currentDialog.instance.setTitle(event.getEventName())
78                 self["epg_description"].setText(text)
79                 self["datetime"].setText(event.getBeginTimeString())
80                 self["duration"].setText(_("%d min")%(event.getDuration()/60))
81
82         def pageUp(self):
83                 self["epg_description"].pageUp()
84
85         def pageDown(self):
86                 self["epg_description"].pageDown()
87
88 class EventViewSimple(Screen, EventViewBase):
89         def __init__(self, session, Event, Ref, callback=None):
90                 Screen.__init__(self, session)
91                 self.skinName = "EventView"
92                 EventViewBase.__init__(self, Event, Ref, callback)
93
94 class EventViewEPGSelect(Screen, EventViewBase):
95         def __init__(self, session, Event, Ref, callback=None, singleEPGCB=None, multiEPGCB=None):
96                 Screen.__init__(self, session)
97                 self.skinName = "EventView"
98                 EventViewBase.__init__(self, Event, Ref, callback)
99                 self["key_yellow"].setText(_("Single EPG"))
100                 self["key_blue"].setText(_("Multi EPG"))
101                 self["epgactions"] = ActionMap(["EventViewEPGActions"],
102                         {
103                                 "openSingleServiceEPG": singleEPGCB,
104                                 "openMultiServiceEPG": multiEPGCB
105                         })