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):
25 def __init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None):
26 Screen.__init__(self, session)
27 self.bouquetChangeCB = bouquetChangeCB
28 self.ask_time = -1 #now
29 self["key_red"] = Button("")
30 self.closeRecursive = False
31 if isinstance(service, str) and eventid != None:
32 self.type = EPG_TYPE_SIMILAR
33 self["key_yellow"] = Button()
34 self["key_blue"] = Button()
35 self["key_red"] = Button()
36 self.currentService=service
37 self.eventid = eventid
39 elif isinstance(service, eServiceReference) or isinstance(service, str):
40 self.type = EPG_TYPE_SINGLE
41 self["key_yellow"] = Button()
42 self["key_blue"] = Button()
43 self.currentService=ServiceReference(service)
46 self.setSortDescription()
48 self.skinName = "EPGSelectionMulti"
49 self.type = EPG_TYPE_MULTI
50 self["key_yellow"] = Button(_("Prev"))
51 self["key_blue"] = Button(_("Next"))
52 self["now_button"] = Pixmap()
53 self["next_button"] = Pixmap()
54 self["more_button"] = Pixmap()
55 self["now_button_sel"] = Pixmap()
56 self["next_button_sel"] = Pixmap()
57 self["more_button_sel"] = Pixmap()
58 self["now_text"] = Label()
59 self["next_text"] = Label()
60 self["more_text"] = Label()
61 self["date"] = Label()
62 self.services = service
63 self.zapFunc = zapFunc
65 self["key_green"] = Button(_("Add timer"))
66 self.key_green_choice = self.ADD_TIMER
67 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
69 self["actions"] = ActionMap(["EPGSelectActions", "OkCancelActions"],
71 "cancel": self.closeScreen,
72 "ok": self.eventSelected,
73 "timerAdd": self.timerAdd,
74 "yellow": self.yellowButtonPressed,
75 "blue": self.blueButtonPressed,
76 "info": self.infoKeyPressed,
78 "input_date_time": self.enterDateTime,
79 "nextBouquet": self.nextBouquet,
80 "prevBouquet": self.prevBouquet
82 self["actions"].csel = self
84 self.onLayoutFinish.append(self.onCreate)
86 def nextBouquet(self):
87 if self.bouquetChangeCB:
88 self.bouquetChangeCB(1, self)
90 def prevBouquet(self):
91 if self.bouquetChangeCB:
92 self.bouquetChangeCB(-1, self)
94 def enterDateTime(self):
95 if self.type == EPG_TYPE_MULTI:
96 global mepg_config_initialized
97 if not mepg_config_initialized:
98 config.misc.prev_mepg_time=ConfigClock(default = time())
99 mepg_config_initialized = True
100 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput, config.misc.prev_mepg_time )
102 def onDateTimeInputClosed(self, ret):
106 self["list"].fillMultiEPG(self.services, ret[1])
108 def closeScreen(self):
109 self.close(self.closeRecursive)
111 def infoKeyPressed(self):
112 cur = self["list"].getCurrent()
115 if event is not None:
116 if self.type != EPG_TYPE_SIMILAR:
117 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
119 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
121 def openSimilarList(self, eventid, refstr):
122 self.session.open(EPGSelection, refstr, None, eventid)
124 def setServices(self, services):
125 self.services = services
128 #just used in multipeg
132 if self.type == EPG_TYPE_MULTI:
133 l.fillMultiEPG(self.services, self.ask_time)
134 elif self.type == EPG_TYPE_SINGLE:
135 l.fillSingleEPG(self.currentService)
137 l.fillSimilarList(self.currentService, self.eventid)
139 def eventViewCallback(self, setEvent, setService, val):
147 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
148 self.eventViewCallback(setEvent, setService, val)
153 def zapTo(self): # just used in multiepg
154 if self.zapFunc and self["key_red"].getText() == "Zap":
156 count = lst.getCurrentChangeCount()
158 self.closeRecursive = True
159 ref = lst.getCurrent()[1]
160 self.zapFunc(ref.ref)
162 def eventSelected(self):
163 self.infoKeyPressed()
165 def yellowButtonPressed(self):
166 if self.type == EPG_TYPE_MULTI:
167 self["list"].updateMultiEPG(-1)
168 elif self.type == EPG_TYPE_SINGLE:
169 if self.sort_type == 0:
173 self["list"].sortSingleEPG(self.sort_type)
174 self.setSortDescription()
176 def setSortDescription(self):
177 if self.sort_type == 1:
178 # TRANSLATORS: This must fit into the header button in the EPG-List
179 self["key_yellow"].setText(_("Sort Time"))
181 # TRANSLATORS: This must fit into the header button in the EPG-List
182 self["key_yellow"].setText(_("Sort A-Z"))
184 def blueButtonPressed(self):
185 if self.type == EPG_TYPE_MULTI:
186 self["list"].updateMultiEPG(1)
188 def removeTimer(self, timer):
189 timer.afterEvent = AFTEREVENT.NONE
190 self.session.nav.RecordTimer.removeEntry(timer)
191 self["key_green"].setText(_("Add timer"))
192 self.key_green_choice = self.ADD_TIMER
195 cur = self["list"].getCurrent()
200 eventid = event.getEventId()
201 refstr = serviceref.ref.toString()
202 for timer in self.session.nav.RecordTimer.timer_list:
203 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
204 cb_func = lambda ret : not ret or self.removeTimer(timer)
205 self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
208 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
209 self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
211 def finishedAdd(self, answer):
215 simulTimerList = self.session.nav.RecordTimer.record(entry)
216 if simulTimerList is not None:
217 if (len(simulTimerList) == 2) and (simulTimerList[1].dontSave) and (simulTimerList[1].autoincrease):
218 simulTimerList[1].end = entry.begin - 30
219 self.session.nav.RecordTimer.timeChanged(simulTimerList[1])
220 self.session.nav.RecordTimer.record(entry)
222 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
223 self["key_green"].setText(_("Remove timer"))
224 self.key_green_choice = self.REMOVE_TIMER
226 self["key_green"].setText(_("Add timer"))
227 self.key_green_choice = self.ADD_TIMER
228 print "Timeredit aborted"
230 def finishSanityCorrection(self, answer):
231 self.finishedAdd(answer)
234 self["list"].moveUp()
237 self["list"].moveDown()
239 def applyButtonState(self, state):
241 self["now_button"].hide()
242 self["now_button_sel"].hide()
243 self["next_button"].hide()
244 self["next_button_sel"].hide()
245 self["more_button"].hide()
246 self["more_button_sel"].hide()
247 self["now_text"].hide()
248 self["next_text"].hide()
249 self["more_text"].hide()
250 self["key_red"].setText("")
253 self["key_red"].setText("Zap")
254 self["now_button_sel"].show()
255 self["now_button"].hide()
257 self["now_button"].show()
258 self["now_button_sel"].hide()
259 self["key_red"].setText("")
262 self["next_button_sel"].show()
263 self["next_button"].hide()
265 self["next_button"].show()
266 self["next_button_sel"].hide()
269 self["more_button_sel"].show()
270 self["more_button"].hide()
272 self["more_button"].show()
273 self["more_button_sel"].hide()
275 def onSelectionChanged(self):
276 cur = self["list"].getCurrent()
277 if self.type == EPG_TYPE_MULTI:
278 count = self["list"].getCurrentChangeCount()
279 if self.ask_time != -1:
280 self.applyButtonState(0)
282 self.applyButtonState(3)
284 self.applyButtonState(2)
286 self.applyButtonState(1)
287 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
290 if event is not None:
292 beg = event.getBeginTime()
293 nowTime = localtime(now)
294 begTime = localtime(beg)
295 if nowTime[2] != begTime[2]:
296 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
298 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
299 self["date"].setText(datestr)
307 eventid = event.getEventId()
308 refstr = serviceref.ref.toString()
310 for timer in self.session.nav.RecordTimer.timer_list:
311 if self.key_green_choice != self.REMOVE_TIMER:
312 if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
313 self["key_green"].setText(_("Remove timer"))
314 self.key_green_choice = self.REMOVE_TIMER
317 if self.key_green_choice != self.ADD_TIMER:
318 self["key_green"].setText(_("Add timer"))
319 self.key_green_choice = self.ADD_TIMER