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 Screens.TimerEdit import TimerSanityConflict
10 from Screens.EventView import EventViewSimple
11 from Screens.MessageBox import MessageBox
12 from TimeDateInput import TimeDateInput
13 from enigma import eServiceReference
14 from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
15 from TimerEntry import TimerEntry
16 from ServiceReference import ServiceReference
17 from time import localtime, time
19 mepg_config_initialized = False
21 class EPGSelection(Screen):
28 def __init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None):
29 Screen.__init__(self, session)
30 self.bouquetChangeCB = bouquetChangeCB
31 self.ask_time = -1 #now
32 self["key_red"] = Button("")
33 self.closeRecursive = False
34 if isinstance(service, str) and eventid != None:
35 self.type = EPG_TYPE_SIMILAR
36 self["key_yellow"] = Button()
37 self["key_blue"] = Button()
38 self["key_red"] = Button()
39 self.currentService=service
40 self.eventid = eventid
42 elif isinstance(service, eServiceReference) or isinstance(service, str):
43 self.type = EPG_TYPE_SINGLE
44 self["key_yellow"] = Button()
45 self["key_blue"] = Button()
46 self.currentService=ServiceReference(service)
49 self.setSortDescription()
51 self.skinName = "EPGSelectionMulti"
52 self.type = EPG_TYPE_MULTI
53 self["key_yellow"] = Button(_("Prev"))
54 self["key_blue"] = Button(_("Next"))
55 self["now_button"] = Pixmap()
56 self["next_button"] = Pixmap()
57 self["more_button"] = Pixmap()
58 self["now_button_sel"] = Pixmap()
59 self["next_button_sel"] = Pixmap()
60 self["more_button_sel"] = Pixmap()
61 self["now_text"] = Label()
62 self["next_text"] = Label()
63 self["more_text"] = Label()
64 self["date"] = Label()
65 self.services = service
66 self.zapFunc = zapFunc
68 self["key_green"] = Button(_("Add timer"))
69 self.key_green_choice = self.ADD_TIMER
70 self.key_red_choice = self.EMPTY
71 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
73 self["actions"] = ActionMap(["EPGSelectActions", "OkCancelActions"],
75 "cancel": self.closeScreen,
76 "ok": self.eventSelected,
77 "timerAdd": self.timerAdd,
78 "yellow": self.yellowButtonPressed,
79 "blue": self.blueButtonPressed,
80 "info": self.infoKeyPressed,
82 "input_date_time": self.enterDateTime,
83 "nextBouquet": self.nextBouquet,
84 "prevBouquet": self.prevBouquet
86 self["actions"].csel = self
88 self.onLayoutFinish.append(self.onCreate)
90 def nextBouquet(self):
91 if self.bouquetChangeCB:
92 self.bouquetChangeCB(1, self)
94 def prevBouquet(self):
95 if self.bouquetChangeCB:
96 self.bouquetChangeCB(-1, self)
98 def enterDateTime(self):
99 if self.type == EPG_TYPE_MULTI:
100 global mepg_config_initialized
101 if not mepg_config_initialized:
102 config.misc.prev_mepg_time=ConfigClock(default = time())
103 mepg_config_initialized = True
104 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput, config.misc.prev_mepg_time )
106 def onDateTimeInputClosed(self, ret):
110 self["list"].fillMultiEPG(self.services, ret[1])
112 def closeScreen(self):
113 self.close(self.closeRecursive)
115 def infoKeyPressed(self):
116 cur = self["list"].getCurrent()
119 if event is not None:
120 if self.type != EPG_TYPE_SIMILAR:
121 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
123 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
125 def openSimilarList(self, eventid, refstr):
126 self.session.open(EPGSelection, refstr, None, eventid)
128 def setServices(self, services):
129 self.services = services
132 #just used in multipeg
136 if self.type == EPG_TYPE_MULTI:
137 l.fillMultiEPG(self.services, self.ask_time)
138 l.moveToService(self.session.nav.getCurrentlyPlayingServiceReference())
139 elif self.type == EPG_TYPE_SINGLE:
140 l.fillSingleEPG(self.currentService)
142 l.fillSimilarList(self.currentService, self.eventid)
144 def eventViewCallback(self, setEvent, setService, val):
152 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
153 self.eventViewCallback(setEvent, setService, val)
158 def zapTo(self): # just used in multiepg
159 if self.zapFunc and self.key_red_choice == self.ZAP:
161 count = lst.getCurrentChangeCount()
163 self.closeRecursive = True
164 ref = lst.getCurrent()[1]
165 self.zapFunc(ref.ref)
167 def eventSelected(self):
168 self.infoKeyPressed()
170 def yellowButtonPressed(self):
171 if self.type == EPG_TYPE_MULTI:
172 self["list"].updateMultiEPG(-1)
173 elif self.type == EPG_TYPE_SINGLE:
174 if self.sort_type == 0:
178 self["list"].sortSingleEPG(self.sort_type)
179 self.setSortDescription()
181 def setSortDescription(self):
182 if self.sort_type == 1:
183 # TRANSLATORS: This must fit into the header button in the EPG-List
184 self["key_yellow"].setText(_("Sort Time"))
186 # TRANSLATORS: This must fit into the header button in the EPG-List
187 self["key_yellow"].setText(_("Sort A-Z"))
189 def blueButtonPressed(self):
190 if self.type == EPG_TYPE_MULTI:
191 self["list"].updateMultiEPG(1)
193 def removeTimer(self, timer):
194 timer.afterEvent = AFTEREVENT.NONE
195 self.session.nav.RecordTimer.removeEntry(timer)
196 self["key_green"].setText(_("Add timer"))
197 self.key_green_choice = self.ADD_TIMER
200 cur = self["list"].getCurrent()
205 eventid = event.getEventId()
206 refstr = serviceref.ref.toString()
207 for timer in self.session.nav.RecordTimer.timer_list:
208 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
209 cb_func = lambda ret : not ret or self.removeTimer(timer)
210 self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
213 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
214 self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
216 def finishedAdd(self, answer):
220 simulTimerList = self.session.nav.RecordTimer.record(entry)
221 if simulTimerList is not None:
222 for x in simulTimerList:
223 if x.setAutoincreaseEnd(entry):
224 self.session.nav.RecordTimer.timeChanged(x)
225 simulTimerList = self.session.nav.RecordTimer.record(entry)
226 if simulTimerList is not None:
227 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
228 self["key_green"].setText(_("Remove timer"))
229 self.key_green_choice = self.REMOVE_TIMER
231 self["key_green"].setText(_("Add timer"))
232 self.key_green_choice = self.ADD_TIMER
233 print "Timeredit aborted"
235 def finishSanityCorrection(self, answer):
236 self.finishedAdd(answer)
239 self["list"].moveUp()
242 self["list"].moveDown()
244 def applyButtonState(self, state):
246 self["now_button"].hide()
247 self["now_button_sel"].hide()
248 self["next_button"].hide()
249 self["next_button_sel"].hide()
250 self["more_button"].hide()
251 self["more_button_sel"].hide()
252 self["now_text"].hide()
253 self["next_text"].hide()
254 self["more_text"].hide()
255 self["key_red"].setText("")
258 self["now_button_sel"].show()
259 self["now_button"].hide()
261 self["now_button"].show()
262 self["now_button_sel"].hide()
265 self["next_button_sel"].show()
266 self["next_button"].hide()
268 self["next_button"].show()
269 self["next_button_sel"].hide()
272 self["more_button_sel"].show()
273 self["more_button"].hide()
275 self["more_button"].show()
276 self["more_button_sel"].hide()
278 def onSelectionChanged(self):
279 cur = self["list"].getCurrent()
281 if self.key_green_choice != self.EMPTY:
282 self["key_green"].setText("")
283 self.key_green_choice = self.EMPTY
284 if self.key_red_choice != self.EMPTY:
285 self["key_red"].setText("")
286 self.key_red_choice = self.EMPTY
289 if self.type == EPG_TYPE_MULTI:
290 count = self["list"].getCurrentChangeCount()
291 if self.ask_time != -1:
292 self.applyButtonState(0)
294 self.applyButtonState(3)
296 self.applyButtonState(2)
298 self.applyButtonState(1)
299 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
301 if event is not None:
303 beg = event.getBeginTime()
304 nowTime = localtime(now)
305 begTime = localtime(beg)
306 if nowTime[2] != begTime[2]:
307 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
309 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
310 self["date"].setText(datestr)
312 if cur[1] is None or cur[1].getServiceName() == "":
313 if self.key_green_choice != self.EMPTY:
314 self["key_green"].setText("")
315 self.key_green_choice = self.EMPTY
316 if self.key_red_choice != self.EMPTY:
317 self["key_red"].setText("")
318 self.key_red_choice = self.EMPTY
320 elif self.key_red_choice != self.ZAP and self.type == EPG_TYPE_MULTI:
321 self["key_red"].setText("Zap")
322 self.key_red_choice = self.ZAP
325 if self.key_green_choice != self.EMPTY:
326 self["key_green"].setText("")
327 self.key_green_choice = self.EMPTY
331 eventid = event.getEventId()
332 refstr = serviceref.ref.toString()
333 isRecordEvent = False
334 for timer in self.session.nav.RecordTimer.timer_list:
335 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
338 if isRecordEvent and self.key_green_choice != self.REMOVE_TIMER:
339 self["key_green"].setText(_("Remove timer"))
340 self.key_green_choice = self.REMOVE_TIMER
341 elif not isRecordEvent and self.key_green_choice != self.ADD_TIMER:
342 self["key_green"].setText(_("Add timer"))
343 self.key_green_choice = self.ADD_TIMER