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.Sources.ServiceEvent import ServiceEvent
10 from Components.Sources.Event import Event
11 from Screens.TimerEdit import TimerSanityConflict
12 from Screens.EventView import EventViewSimple
13 from Screens.MessageBox import MessageBox
14 from TimeDateInput import TimeDateInput
15 from enigma import eServiceReference
16 from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
17 from TimerEntry import TimerEntry
18 from ServiceReference import ServiceReference
19 from time import localtime, time
21 mepg_config_initialized = False
23 class EPGSelection(Screen):
30 def __init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None, serviceChangeCB=None):
31 Screen.__init__(self, session)
32 self.bouquetChangeCB = bouquetChangeCB
33 self.serviceChangeCB = serviceChangeCB
34 self.ask_time = -1 #now
35 self["key_red"] = Button("")
36 self.closeRecursive = False
37 self.saved_title = None
38 self["Service"] = ServiceEvent()
39 self["Event"] = Event()
40 if isinstance(service, str) and eventid != None:
41 self.type = EPG_TYPE_SIMILAR
42 self["key_yellow"] = Button()
43 self["key_blue"] = Button()
44 self["key_red"] = Button()
45 self.currentService=service
46 self.eventid = eventid
48 elif isinstance(service, eServiceReference) or isinstance(service, str):
49 self.type = EPG_TYPE_SINGLE
50 self["key_yellow"] = Button()
51 self["key_blue"] = Button()
52 self.currentService=ServiceReference(service)
55 self.setSortDescription()
57 self.skinName = "EPGSelectionMulti"
58 self.type = EPG_TYPE_MULTI
59 self["key_yellow"] = Button(_("Prev"))
60 self["key_blue"] = Button(_("Next"))
61 self["now_button"] = Pixmap()
62 self["next_button"] = Pixmap()
63 self["more_button"] = Pixmap()
64 self["now_button_sel"] = Pixmap()
65 self["next_button_sel"] = Pixmap()
66 self["more_button_sel"] = Pixmap()
67 self["now_text"] = Label()
68 self["next_text"] = Label()
69 self["more_text"] = Label()
70 self["date"] = Label()
71 self.services = service
72 self.zapFunc = zapFunc
74 self["key_green"] = Button(_("Add timer"))
75 self.key_green_choice = self.ADD_TIMER
76 self.key_red_choice = self.EMPTY
77 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = session.nav.RecordTimer)
79 self["actions"] = ActionMap(["EPGSelectActions", "OkCancelActions"],
81 "cancel": self.closeScreen,
82 "ok": self.eventSelected,
83 "timerAdd": self.timerAdd,
84 "yellow": self.yellowButtonPressed,
85 "blue": self.blueButtonPressed,
86 "info": self.infoKeyPressed,
88 "input_date_time": self.enterDateTime,
89 "nextBouquet": self.nextBouquet, # just used in multi epg yet
90 "prevBouquet": self.prevBouquet, # just used in multi epg yet
91 "nextService": self.nextService, # just used in single epg yet
92 "prevService": self.prevService, # just used in single epg yet
94 self["actions"].csel = self
95 self.onLayoutFinish.append(self.onCreate)
97 def nextBouquet(self):
98 if self.bouquetChangeCB:
99 self.bouquetChangeCB(1, self)
101 def prevBouquet(self):
102 if self.bouquetChangeCB:
103 self.bouquetChangeCB(-1, self)
105 def nextService(self):
106 if self.serviceChangeCB:
107 self.serviceChangeCB(1, self)
109 def prevService(self):
110 if self.serviceChangeCB:
111 self.serviceChangeCB(-1, self)
113 def enterDateTime(self):
114 if self.type == EPG_TYPE_MULTI:
115 global mepg_config_initialized
116 if not mepg_config_initialized:
117 config.misc.prev_mepg_time=ConfigClock(default = time())
118 mepg_config_initialized = True
119 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput, config.misc.prev_mepg_time )
121 def onDateTimeInputClosed(self, ret):
125 self["list"].fillMultiEPG(self.services, ret[1])
127 def closeScreen(self):
128 self.close(self.closeRecursive)
130 def infoKeyPressed(self):
131 cur = self["list"].getCurrent()
134 if event is not None:
135 if self.type != EPG_TYPE_SIMILAR:
136 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
138 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
140 def openSimilarList(self, eventid, refstr):
141 self.session.open(EPGSelection, refstr, None, eventid)
143 def setServices(self, services):
144 self.services = services
147 def setService(self, service):
148 self.currentService = service
151 #just used in multipeg
155 if self.type == EPG_TYPE_MULTI:
156 l.fillMultiEPG(self.services, self.ask_time)
157 l.moveToService(self.session.nav.getCurrentlyPlayingServiceReference())
158 elif self.type == EPG_TYPE_SINGLE:
159 service = self.currentService
160 self["Service"].newService(service.ref)
161 if self.saved_title is None:
162 self.saved_title = self.instance.getTitle()
163 title = self.saved_title + ' - ' + service.getServiceName()
164 self.instance.setTitle(title)
165 l.fillSingleEPG(service)
167 l.fillSimilarList(self.currentService, self.eventid)
169 def eventViewCallback(self, setEvent, setService, val):
177 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
178 self.eventViewCallback(setEvent, setService, val)
183 def zapTo(self): # just used in multiepg
184 if self.zapFunc and self.key_red_choice == self.ZAP:
186 count = lst.getCurrentChangeCount()
188 self.closeRecursive = True
189 ref = lst.getCurrent()[1]
190 self.zapFunc(ref.ref)
192 def eventSelected(self):
193 self.infoKeyPressed()
195 def yellowButtonPressed(self):
196 if self.type == EPG_TYPE_MULTI:
197 self["list"].updateMultiEPG(-1)
198 elif self.type == EPG_TYPE_SINGLE:
199 if self.sort_type == 0:
203 self["list"].sortSingleEPG(self.sort_type)
204 self.setSortDescription()
206 def setSortDescription(self):
207 if self.sort_type == 1:
208 # TRANSLATORS: This must fit into the header button in the EPG-List
209 self["key_yellow"].setText(_("Sort Time"))
211 # TRANSLATORS: This must fit into the header button in the EPG-List
212 self["key_yellow"].setText(_("Sort A-Z"))
214 def blueButtonPressed(self):
215 if self.type == EPG_TYPE_MULTI:
216 self["list"].updateMultiEPG(1)
218 def removeTimer(self, timer):
219 timer.afterEvent = AFTEREVENT.NONE
220 self.session.nav.RecordTimer.removeEntry(timer)
221 self["key_green"].setText(_("Add timer"))
222 self.key_green_choice = self.ADD_TIMER
225 cur = self["list"].getCurrent()
230 eventid = event.getEventId()
231 refstr = serviceref.ref.toString()
232 for timer in self.session.nav.RecordTimer.timer_list:
233 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
234 cb_func = lambda ret : not ret or self.removeTimer(timer)
235 self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
238 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
239 self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
241 def finishedAdd(self, answer):
245 simulTimerList = self.session.nav.RecordTimer.record(entry)
246 if simulTimerList is not None:
247 for x in simulTimerList:
248 if x.setAutoincreaseEnd(entry):
249 self.session.nav.RecordTimer.timeChanged(x)
250 simulTimerList = self.session.nav.RecordTimer.record(entry)
251 if simulTimerList is not None:
252 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
253 self["key_green"].setText(_("Remove timer"))
254 self.key_green_choice = self.REMOVE_TIMER
256 self["key_green"].setText(_("Add timer"))
257 self.key_green_choice = self.ADD_TIMER
258 print "Timeredit aborted"
260 def finishSanityCorrection(self, answer):
261 self.finishedAdd(answer)
264 self["list"].moveUp()
267 self["list"].moveDown()
269 def applyButtonState(self, state):
271 self["now_button"].hide()
272 self["now_button_sel"].hide()
273 self["next_button"].hide()
274 self["next_button_sel"].hide()
275 self["more_button"].hide()
276 self["more_button_sel"].hide()
277 self["now_text"].hide()
278 self["next_text"].hide()
279 self["more_text"].hide()
280 self["key_red"].setText("")
283 self["now_button_sel"].show()
284 self["now_button"].hide()
286 self["now_button"].show()
287 self["now_button_sel"].hide()
290 self["next_button_sel"].show()
291 self["next_button"].hide()
293 self["next_button"].show()
294 self["next_button_sel"].hide()
297 self["more_button_sel"].show()
298 self["more_button"].hide()
300 self["more_button"].show()
301 self["more_button_sel"].hide()
303 def onSelectionChanged(self):
304 cur = self["list"].getCurrent()
306 if self.key_green_choice != self.EMPTY:
307 self["key_green"].setText("")
308 self.key_green_choice = self.EMPTY
309 if self.key_red_choice != self.EMPTY:
310 self["key_red"].setText("")
311 self.key_red_choice = self.EMPTY
314 self["Event"].newEvent(event)
315 if self.type == EPG_TYPE_MULTI:
316 count = self["list"].getCurrentChangeCount()
317 if self.ask_time != -1:
318 self.applyButtonState(0)
320 self.applyButtonState(3)
322 self.applyButtonState(2)
324 self.applyButtonState(1)
325 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
327 if event is not None:
329 beg = event.getBeginTime()
330 nowTime = localtime(now)
331 begTime = localtime(beg)
332 if nowTime[2] != begTime[2]:
333 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
335 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
336 self["date"].setText(datestr)
338 self["Service"].newService(None)
340 self["Service"].newService(cur[1].ref)
342 if cur[1] is None or cur[1].getServiceName() == "":
343 if self.key_green_choice != self.EMPTY:
344 self["key_green"].setText("")
345 self.key_green_choice = self.EMPTY
346 if self.key_red_choice != self.EMPTY:
347 self["key_red"].setText("")
348 self.key_red_choice = self.EMPTY
350 elif self.key_red_choice != self.ZAP and self.type == EPG_TYPE_MULTI:
351 self["key_red"].setText("Zap")
352 self.key_red_choice = self.ZAP
355 if self.key_green_choice != self.EMPTY:
356 self["key_green"].setText("")
357 self.key_green_choice = self.EMPTY
361 eventid = event.getEventId()
362 refstr = serviceref.ref.toString()
363 isRecordEvent = False
364 for timer in self.session.nav.RecordTimer.timer_list:
365 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
368 if isRecordEvent and self.key_green_choice != self.REMOVE_TIMER:
369 self["key_green"].setText(_("Remove timer"))
370 self.key_green_choice = self.REMOVE_TIMER
371 elif not isRecordEvent and self.key_green_choice != self.ADD_TIMER:
372 self["key_green"].setText(_("Add timer"))
373 self.key_green_choice = self.ADD_TIMER