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 Screens.TimerEdit import TimerSanityConflict
9 from Screens.EventView import EventViewSimple
10 from TimeDateInput import TimeDateInput
11 from enigma import eServiceReference
12 from RecordTimer import RecordTimerEntry, parseEvent
13 from TimerEntry import TimerEntry
14 from ServiceReference import ServiceReference
15 from time import localtime, time
17 mepg_config_initialized = False
19 class EPGSelection(Screen):
20 def __init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None):
21 Screen.__init__(self, session)
22 self.bouquetChangeCB = bouquetChangeCB
23 self.ask_time = -1 #now
24 self["key_red"] = Button("")
25 self.closeRecursive = False
26 if isinstance(service, str) and eventid != None:
27 self.type = EPG_TYPE_SIMILAR
28 self["key_yellow"] = Button()
29 self["key_blue"] = Button()
30 self["key_red"] = Button()
31 self.currentService=service
32 self.eventid = eventid
34 elif isinstance(service, eServiceReference) or isinstance(service, str):
35 self.type = EPG_TYPE_SINGLE
36 self["key_yellow"] = Button()
37 self["key_blue"] = Button()
38 self.currentService=ServiceReference(service)
41 self.setSortDescription()
43 self.skinName = "EPGSelectionMulti"
44 self.type = EPG_TYPE_MULTI
45 self["key_yellow"] = Button(_("Prev"))
46 self["key_blue"] = Button(_("Next"))
47 self["now_button"] = Pixmap()
48 self["next_button"] = Pixmap()
49 self["more_button"] = Pixmap()
50 self["now_button_sel"] = Pixmap()
51 self["next_button_sel"] = Pixmap()
52 self["more_button_sel"] = Pixmap()
53 self["now_text"] = Label()
54 self["next_text"] = Label()
55 self["more_text"] = Label()
56 self["date"] = Label()
57 self.services = service
58 self.zapFunc = zapFunc
60 self["key_green"] = Button(_("Add timer"))
61 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
63 self["actions"] = ActionMap(["EPGSelectActions", "OkCancelActions"],
65 "cancel": self.closeScreen,
66 "ok": self.eventSelected,
67 "timerAdd": self.timerAdd,
68 "yellow": self.yellowButtonPressed,
69 "blue": self.blueButtonPressed,
70 "info": self.infoKeyPressed,
72 "input_date_time": self.enterDateTime,
73 "nextBouquet": self.nextBouquet,
74 "prevBouquet": self.prevBouquet
76 self["actions"].csel = self
78 self.onLayoutFinish.append(self.onCreate)
80 def nextBouquet(self):
81 if self.bouquetChangeCB:
82 self.bouquetChangeCB(1, self)
84 def prevBouquet(self):
85 if self.bouquetChangeCB:
86 self.bouquetChangeCB(-1, self)
88 def enterDateTime(self):
89 if self.type == EPG_TYPE_MULTI:
90 global mepg_config_initialized
91 if not mepg_config_initialized:
92 config.misc.prev_mepg_time=ConfigClock(default = time())
93 mepg_config_initialized = True
94 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput, config.misc.prev_mepg_time )
96 def onDateTimeInputClosed(self, ret):
100 self["list"].fillMultiEPG(self.services, ret[1])
102 def closeScreen(self):
103 self.close(self.closeRecursive)
105 def infoKeyPressed(self):
106 cur = self["list"].getCurrent()
109 if event is not None:
110 if self.type != EPG_TYPE_SIMILAR:
111 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
113 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
115 def openSimilarList(self, eventid, refstr):
116 self.session.open(EPGSelection, refstr, None, eventid)
118 def setServices(self, services):
119 self.services = services
122 #just used in multipeg
126 if self.type == EPG_TYPE_MULTI:
127 l.fillMultiEPG(self.services, self.ask_time)
128 elif self.type == EPG_TYPE_SINGLE:
129 l.fillSingleEPG(self.currentService)
131 l.fillSimilarList(self.currentService, self.eventid)
133 def eventViewCallback(self, setEvent, setService, val):
141 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
142 self.eventViewCallback(setEvent, setService, val)
147 def zapTo(self): # just used in multiepg
148 if self.zapFunc and self["key_red"].getText() == "Zap":
150 count = lst.getCurrentChangeCount()
152 self.closeRecursive = True
153 ref = lst.getCurrent()[1]
154 self.zapFunc(ref.ref)
156 def eventSelected(self):
157 self.infoKeyPressed()
159 def yellowButtonPressed(self):
160 if self.type == EPG_TYPE_MULTI:
161 self["list"].updateMultiEPG(-1)
162 elif self.type == EPG_TYPE_SINGLE:
163 if self.sort_type == 0:
167 self["list"].sortSingleEPG(self.sort_type)
168 self.setSortDescription()
170 def setSortDescription(self):
171 if self.sort_type == 1:
172 # TRANSLATORS: This must fit into the header button in the EPG-List
173 self["key_yellow"].setText(_("Sort Time"))
175 # TRANSLATORS: This must fit into the header button in the EPG-List
176 self["key_yellow"].setText(_("Sort A-Z"))
178 def blueButtonPressed(self):
179 if self.type == EPG_TYPE_MULTI:
180 self["list"].updateMultiEPG(1)
183 cur = self["list"].getCurrent()
188 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
189 self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
191 def finishedAdd(self, answer):
195 simulTimerList = self.session.nav.RecordTimer.record(entry)
196 if simulTimerList is not None:
197 if (len(simulTimerList) == 2) and (simulTimerList[1].dontSave) and (simulTimerList[1].autoincrease):
198 simulTimerList[1].end = entry.begin - 30
199 self.session.nav.RecordTimer.timeChanged(simulTimerList[1])
200 self.session.nav.RecordTimer.record(entry)
202 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
204 print "Timeredit aborted"
206 def finishSanityCorrection(self, answer):
207 self.finishedAdd(answer)
210 self["list"].moveUp()
213 self["list"].moveDown()
215 def applyButtonState(self, state):
217 self["now_button"].hide()
218 self["now_button_sel"].hide()
219 self["next_button"].hide()
220 self["next_button_sel"].hide()
221 self["more_button"].hide()
222 self["more_button_sel"].hide()
223 self["now_text"].hide()
224 self["next_text"].hide()
225 self["more_text"].hide()
226 self["key_red"].setText("")
229 self["key_red"].setText("Zap")
230 self["now_button_sel"].show()
231 self["now_button"].hide()
233 self["now_button"].show()
234 self["now_button_sel"].hide()
235 self["key_red"].setText("")
238 self["next_button_sel"].show()
239 self["next_button"].hide()
241 self["next_button"].show()
242 self["next_button_sel"].hide()
245 self["more_button_sel"].show()
246 self["more_button"].hide()
248 self["more_button"].show()
249 self["more_button_sel"].hide()
251 def onSelectionChanged(self):
252 if self.type == EPG_TYPE_MULTI:
253 count = self["list"].getCurrentChangeCount()
254 if self.ask_time != -1:
255 self.applyButtonState(0)
257 self.applyButtonState(3)
259 self.applyButtonState(2)
261 self.applyButtonState(1)
262 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
264 event = self["list"].getCurrent()[0]
265 if event is not None:
267 beg = event.getBeginTime()
268 nowTime = localtime(now)
269 begTime = localtime(beg)
270 if nowTime[2] != begTime[2]:
271 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
273 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
274 self["date"].setText(datestr)