1 from Screen import Screen
2 from Components.config import config, ConfigClock
3 from Components.Button import Button
4 from Components.Pixmap import Pixmap
5 from Components.Label import Label
6 from Components.EpgList import EPGList, EPG_TYPE_SINGLE, EPG_TYPE_SIMILAR, EPG_TYPE_MULTI
7 from Components.ActionMap import ActionMap
8 from Components.TimerSanityCheck import TimerSanityCheck
9 from Components.UsageConfig import preferredTimerPath
10 from Components.Sources.ServiceEvent import ServiceEvent
11 from Components.Sources.Event import Event
12 from Screens.TimerEdit import TimerSanityConflict
13 from Screens.EventView import EventViewSimple
14 from Screens.MessageBox import MessageBox
15 from TimeDateInput import TimeDateInput
16 from enigma import eServiceReference
17 from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
18 from TimerEntry import TimerEntry
19 from ServiceReference import ServiceReference
20 from time import localtime, time
22 mepg_config_initialized = False
24 class EPGSelection(Screen):
31 def __init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None, serviceChangeCB=None):
32 Screen.__init__(self, session)
33 self.bouquetChangeCB = bouquetChangeCB
34 self.serviceChangeCB = serviceChangeCB
35 self.ask_time = -1 #now
36 self["key_red"] = Button("")
37 self.closeRecursive = False
38 self.saved_title = None
39 self["Service"] = ServiceEvent()
40 self["Event"] = Event()
41 if isinstance(service, str) and eventid != None:
42 self.type = EPG_TYPE_SIMILAR
43 self["key_yellow"] = Button()
44 self["key_blue"] = Button()
45 self["key_red"] = Button()
46 self.currentService=service
47 self.eventid = eventid
49 elif isinstance(service, eServiceReference) or isinstance(service, str):
50 self.type = EPG_TYPE_SINGLE
51 self["key_yellow"] = Button()
52 self["key_blue"] = Button()
53 self.currentService=ServiceReference(service)
56 self.setSortDescription()
58 self.skinName = "EPGSelectionMulti"
59 self.type = EPG_TYPE_MULTI
60 self["key_yellow"] = Button(_("Prev"))
61 self["key_blue"] = Button(_("Next"))
62 self["now_button"] = Pixmap()
63 self["next_button"] = Pixmap()
64 self["more_button"] = Pixmap()
65 self["now_button_sel"] = Pixmap()
66 self["next_button_sel"] = Pixmap()
67 self["more_button_sel"] = Pixmap()
68 self["now_text"] = Label()
69 self["next_text"] = Label()
70 self["more_text"] = Label()
71 self["date"] = Label()
72 self.services = service
73 self.zapFunc = zapFunc
75 self["key_green"] = Button(_("Add timer"))
76 self.key_green_choice = self.ADD_TIMER
77 self.key_red_choice = self.EMPTY
78 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = session.nav.RecordTimer)
80 self["actions"] = ActionMap(["EPGSelectActions", "OkCancelActions"],
82 "cancel": self.closeScreen,
83 "ok": self.eventSelected,
84 "timerAdd": self.timerAdd,
85 "yellow": self.yellowButtonPressed,
86 "blue": self.blueButtonPressed,
87 "info": self.infoKeyPressed,
89 "input_date_time": self.enterDateTime,
90 "nextBouquet": self.nextBouquet, # just used in multi epg yet
91 "prevBouquet": self.prevBouquet, # just used in multi epg yet
92 "nextService": self.nextService, # just used in single epg yet
93 "prevService": self.prevService, # just used in single epg yet
95 self["actions"].csel = self
96 self.onLayoutFinish.append(self.onCreate)
98 def nextBouquet(self):
99 if self.bouquetChangeCB:
100 self.bouquetChangeCB(1, self)
102 def prevBouquet(self):
103 if self.bouquetChangeCB:
104 self.bouquetChangeCB(-1, self)
106 def nextService(self):
107 if self.serviceChangeCB:
108 self.serviceChangeCB(1, self)
110 def prevService(self):
111 if self.serviceChangeCB:
112 self.serviceChangeCB(-1, self)
114 def enterDateTime(self):
115 if self.type == EPG_TYPE_MULTI:
116 global mepg_config_initialized
117 if not mepg_config_initialized:
118 config.misc.prev_mepg_time=ConfigClock(default = time())
119 mepg_config_initialized = True
120 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput, config.misc.prev_mepg_time )
122 def onDateTimeInputClosed(self, ret):
126 self["list"].fillMultiEPG(self.services, ret[1])
128 def closeScreen(self):
129 self.close(self.closeRecursive)
131 def infoKeyPressed(self):
132 cur = self["list"].getCurrent()
135 if event is not None:
136 if self.type != EPG_TYPE_SIMILAR:
137 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
139 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
141 def openSimilarList(self, eventid, refstr):
142 self.session.open(EPGSelection, refstr, None, eventid)
144 def setServices(self, services):
145 self.services = services
148 def setService(self, service):
149 self.currentService = service
152 #just used in multipeg
156 if self.type == EPG_TYPE_MULTI:
157 l.fillMultiEPG(self.services, self.ask_time)
158 l.moveToService(self.session.nav.getCurrentlyPlayingServiceReference())
159 elif self.type == EPG_TYPE_SINGLE:
160 service = self.currentService
161 self["Service"].newService(service.ref)
162 if self.saved_title is None:
163 self.saved_title = self.instance.getTitle()
164 title = self.saved_title + ' - ' + service.getServiceName()
165 self.instance.setTitle(title)
166 l.fillSingleEPG(service)
168 l.fillSimilarList(self.currentService, self.eventid)
170 def eventViewCallback(self, setEvent, setService, val):
178 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
179 self.eventViewCallback(setEvent, setService, val)
184 def zapTo(self): # just used in multiepg
185 if self.zapFunc and self.key_red_choice == self.ZAP:
187 count = lst.getCurrentChangeCount()
189 self.closeRecursive = True
190 ref = lst.getCurrent()[1]
191 self.zapFunc(ref.ref)
193 def eventSelected(self):
194 self.infoKeyPressed()
196 def yellowButtonPressed(self):
197 if self.type == EPG_TYPE_MULTI:
198 self["list"].updateMultiEPG(-1)
199 elif self.type == EPG_TYPE_SINGLE:
200 if self.sort_type == 0:
204 self["list"].sortSingleEPG(self.sort_type)
205 self.setSortDescription()
207 def setSortDescription(self):
208 if self.sort_type == 1:
209 # TRANSLATORS: This must fit into the header button in the EPG-List
210 self["key_yellow"].setText(_("Sort Time"))
212 # TRANSLATORS: This must fit into the header button in the EPG-List
213 self["key_yellow"].setText(_("Sort A-Z"))
215 def blueButtonPressed(self):
216 if self.type == EPG_TYPE_MULTI:
217 self["list"].updateMultiEPG(1)
219 def removeTimer(self, timer):
220 timer.afterEvent = AFTEREVENT.NONE
221 self.session.nav.RecordTimer.removeEntry(timer)
222 self["key_green"].setText(_("Add timer"))
223 self.key_green_choice = self.ADD_TIMER
226 cur = self["list"].getCurrent()
231 eventid = event.getEventId()
232 refstr = serviceref.ref.toString()
233 for timer in self.session.nav.RecordTimer.timer_list:
234 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
235 cb_func = lambda ret : not ret or self.removeTimer(timer)
236 self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
239 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, dirname = preferredTimerPath(), *parseEvent(event))
240 self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
242 def finishedAdd(self, answer):
246 simulTimerList = self.session.nav.RecordTimer.record(entry)
247 if simulTimerList is not None:
248 for x in simulTimerList:
249 if x.setAutoincreaseEnd(entry):
250 self.session.nav.RecordTimer.timeChanged(x)
251 simulTimerList = self.session.nav.RecordTimer.record(entry)
252 if simulTimerList is not None:
253 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
254 self["key_green"].setText(_("Remove timer"))
255 self.key_green_choice = self.REMOVE_TIMER
257 self["key_green"].setText(_("Add timer"))
258 self.key_green_choice = self.ADD_TIMER
259 print "Timeredit aborted"
261 def finishSanityCorrection(self, answer):
262 self.finishedAdd(answer)
265 self["list"].moveUp()
268 self["list"].moveDown()
270 def applyButtonState(self, state):
272 self["now_button"].hide()
273 self["now_button_sel"].hide()
274 self["next_button"].hide()
275 self["next_button_sel"].hide()
276 self["more_button"].hide()
277 self["more_button_sel"].hide()
278 self["now_text"].hide()
279 self["next_text"].hide()
280 self["more_text"].hide()
281 self["key_red"].setText("")
284 self["now_button_sel"].show()
285 self["now_button"].hide()
287 self["now_button"].show()
288 self["now_button_sel"].hide()
291 self["next_button_sel"].show()
292 self["next_button"].hide()
294 self["next_button"].show()
295 self["next_button_sel"].hide()
298 self["more_button_sel"].show()
299 self["more_button"].hide()
301 self["more_button"].show()
302 self["more_button_sel"].hide()
304 def onSelectionChanged(self):
305 cur = self["list"].getCurrent()
307 if self.key_green_choice != self.EMPTY:
308 self["key_green"].setText("")
309 self.key_green_choice = self.EMPTY
310 if self.key_red_choice != self.EMPTY:
311 self["key_red"].setText("")
312 self.key_red_choice = self.EMPTY
315 self["Event"].newEvent(event)
316 if self.type == EPG_TYPE_MULTI:
317 count = self["list"].getCurrentChangeCount()
318 if self.ask_time != -1:
319 self.applyButtonState(0)
321 self.applyButtonState(3)
323 self.applyButtonState(2)
325 self.applyButtonState(1)
326 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
328 if event is not None:
330 beg = event.getBeginTime()
331 nowTime = localtime(now)
332 begTime = localtime(beg)
333 if nowTime[2] != begTime[2]:
334 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
336 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
337 self["date"].setText(datestr)
339 self["Service"].newService(None)
341 self["Service"].newService(cur[1].ref)
343 if cur[1] is None or cur[1].getServiceName() == "":
344 if self.key_green_choice != self.EMPTY:
345 self["key_green"].setText("")
346 self.key_green_choice = self.EMPTY
347 if self.key_red_choice != self.EMPTY:
348 self["key_red"].setText("")
349 self.key_red_choice = self.EMPTY
351 elif self.key_red_choice != self.ZAP and self.type == EPG_TYPE_MULTI:
352 self["key_red"].setText("Zap")
353 self.key_red_choice = self.ZAP
356 if self.key_green_choice != self.EMPTY:
357 self["key_green"].setText("")
358 self.key_green_choice = self.EMPTY
362 eventid = event.getEventId()
363 refstr = serviceref.ref.toString()
364 isRecordEvent = False
365 for timer in self.session.nav.RecordTimer.timer_list:
366 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
369 if isRecordEvent and self.key_green_choice != self.REMOVE_TIMER:
370 self["key_green"].setText(_("Remove timer"))
371 self.key_green_choice = self.REMOVE_TIMER
372 elif not isRecordEvent and self.key_green_choice != self.ADD_TIMER:
373 self["key_green"].setText(_("Add timer"))
374 self.key_green_choice = self.ADD_TIMER