1 from Screen import Screen
2 from Screens.TimerEdit import TimerSanityConflict
3 from Screens.MessageBox import MessageBox
4 from Components.ActionMap import ActionMap
5 from Components.Button import Button
6 from Components.Label import Label
7 from Components.ScrollLabel import ScrollLabel
8 from Components.TimerList import TimerList
9 from enigma import eEPGCache, eTimer, eServiceReference
10 from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
11 from TimerEntry import TimerEntry
12 from time import localtime
13 from Components.config import config
19 def __init__(self, Event, Ref, callback=None, similarEPGCB=None):
20 self.similarEPGCB = similarEPGCB
21 self.cbFunc = callback
22 self.currentService=Ref
23 self.isRecording = (not Ref.ref.flags & eServiceReference.isGroup) and Ref.ref.getPath()
25 self["epg_description"] = ScrollLabel()
26 self["datetime"] = Label()
27 self["channel"] = Label()
28 self["duration"] = Label()
29 self["key_red"] = Button("")
30 if similarEPGCB is not None:
31 self.SimilarBroadcastTimer = eTimer()
32 self.SimilarBroadcastTimer.callback.append(self.getSimilarEvents)
34 self.SimilarBroadcastTimer = None
35 self.key_green_choice = self.ADD_TIMER
37 self["key_green"] = Button("")
39 self["key_green"] = Button(_("Add timer"))
40 self["key_yellow"] = Button("")
41 self["key_blue"] = Button("")
42 self["actions"] = ActionMap(["OkCancelActions", "EventViewActions"],
46 "pageUp": self.pageUp,
47 "pageDown": self.pageDown,
48 "prevEvent": self.prevEvent,
49 "nextEvent": self.nextEvent,
50 "timerAdd": self.timerAdd,
51 "openSimilarList": self.openSimilarList
53 self.onShown.append(self.onCreate)
56 self.setService(self.currentService)
57 self.setEvent(self.event)
60 if self.cbFunc is not None:
61 self.cbFunc(self.setEvent, self.setService, -1)
64 if self.cbFunc is not None:
65 self.cbFunc(self.setEvent, self.setService, +1)
67 def removeTimer(self, timer):
68 timer.afterEvent = AFTEREVENT.NONE
69 self.session.nav.RecordTimer.removeEntry(timer)
70 self["key_green"].setText(_("Add timer"))
71 self.key_green_choice = self.ADD_TIMER
77 serviceref = self.currentService
80 eventid = event.getEventId()
81 refstr = serviceref.ref.toString()
82 for timer in self.session.nav.RecordTimer.timer_list:
83 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
84 cb_func = lambda ret : not ret or self.removeTimer(timer)
85 self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
88 newEntry = RecordTimerEntry(self.currentService, checkOldTimers = True, *parseEvent(self.event))
89 self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
91 def finishedAdd(self, answer):
95 simulTimerList = self.session.nav.RecordTimer.record(entry)
96 if simulTimerList is not None:
97 for x in simulTimerList:
98 if x.setAutoincreaseEnd(entry):
99 self.session.nav.RecordTimer.timeChanged(x)
100 simulTimerList = self.session.nav.RecordTimer.record(entry)
101 if simulTimerList is not None:
102 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
103 self["key_green"].setText(_("Remove timer"))
104 self.key_green_choice = self.REMOVE_TIMER
106 self["key_green"].setText(_("Add timer"))
107 self.key_green_choice = self.ADD_TIMER
108 print "Timeredit aborted"
110 def finishSanityCorrection(self, answer):
111 self.finishedAdd(answer)
113 def setService(self, service):
114 self.currentService=service
116 self["channel"].setText(_("Recording"))
118 name = self.currentService.getServiceName()
120 self["channel"].setText(name)
122 self["channel"].setText(_("unknown service"))
124 def sort_func(self,x,y):
132 def setEvent(self, event):
136 text = event.getEventName()
137 short = event.getShortDescription()
138 ext = event.getExtendedDescription()
139 if short and short != text:
140 text += '\n\n' + short
146 self.setTitle(event.getEventName())
147 self["epg_description"].setText(text)
148 self["datetime"].setText(event.getBeginTimeString())
149 self["duration"].setText(_("%d min")%(event.getDuration()/60))
150 self["key_red"].setText("")
151 if self.SimilarBroadcastTimer is not None:
152 self.SimilarBroadcastTimer.start(400,True)
154 serviceref = self.currentService
155 eventid = self.event.getEventId()
156 refstr = serviceref.ref.toString()
157 isRecordEvent = False
158 for timer in self.session.nav.RecordTimer.timer_list:
159 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
162 if isRecordEvent and self.key_green_choice != self.REMOVE_TIMER:
163 self["key_green"].setText(_("Remove timer"))
164 self.key_green_choice = self.REMOVE_TIMER
165 elif not isRecordEvent and self.key_green_choice != self.ADD_TIMER:
166 self["key_green"].setText(_("Add timer"))
167 self.key_green_choice = self.ADD_TIMER
171 self["epg_description"].pageUp()
174 self["epg_description"].pageDown()
176 def getSimilarEvents(self):
177 # search similar broadcastings
178 refstr = str(self.currentService)
179 id = self.event.getEventId()
180 epgcache = eEPGCache.getInstance()
181 ret = epgcache.search(('NB', 100, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, id))
183 descr = self["epg_description"]
184 text = descr.getText()
185 text += '\n\n' + _('Similar broadcasts:')
186 ret.sort(self.sort_func)
189 text += '\n%d.%d.%d, %02d:%02d - %s'%(t[2], t[1], t[0], t[3], t[4], x[0])
191 self["key_red"].setText(_("Similar"))
193 def openSimilarList(self):
194 if self.similarEPGCB is not None and self["key_red"].getText():
195 id = self.event and self.event.getEventId()
196 refstr = str(self.currentService)
198 self.similarEPGCB(id, refstr)
200 class EventViewSimple(Screen, EventViewBase):
201 def __init__(self, session, Event, Ref, callback=None, similarEPGCB=None):
202 Screen.__init__(self, session)
203 self.skinName = "EventView"
204 EventViewBase.__init__(self, Event, Ref, callback, similarEPGCB)
206 class EventViewEPGSelect(Screen, EventViewBase):
207 def __init__(self, session, Event, Ref, callback=None, singleEPGCB=None, multiEPGCB=None, similarEPGCB=None):
208 Screen.__init__(self, session)
209 self.skinName = "EventView"
210 EventViewBase.__init__(self, Event, Ref, callback, similarEPGCB)
211 self["key_yellow"].setText(_("Single EPG"))
212 self["key_blue"].setText(_("Multi EPG"))
213 self["epgactions"] = ActionMap(["EventViewEPGActions"],
215 "openSingleServiceEPG": singleEPGCB,
216 "openMultiServiceEPG": multiEPGCB,