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.EventView import EventViewSimple
9 from TimeDateInput import TimeDateInput
10 from enigma import eServiceReference
11 from RecordTimer import RecordTimerEntry, parseEvent
12 from TimerEntry import TimerEntry
13 from ServiceReference import ServiceReference
14 from time import localtime, time
16 mepg_config_initialized = False
18 class EPGSelection(Screen):
19 def __init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None):
20 Screen.__init__(self, session)
21 self.bouquetChangeCB = bouquetChangeCB
22 self.ask_time = -1 #now
23 self["key_red"] = Button("")
24 self.closeRecursive = False
25 if isinstance(service, str) and eventid != None:
26 self.type = EPG_TYPE_SIMILAR
27 self["key_yellow"] = Button()
28 self["key_blue"] = Button()
29 self["key_red"] = Button()
30 self.currentService=service
31 self.eventid = eventid
33 elif isinstance(service, eServiceReference) or isinstance(service, str):
34 self.type = EPG_TYPE_SINGLE
35 self["key_yellow"] = Button()
36 self["key_blue"] = Button()
37 self.currentService=ServiceReference(service)
40 self.setSortDescription()
42 self.skinName = "EPGSelectionMulti"
43 self.type = EPG_TYPE_MULTI
44 self["key_yellow"] = Button(_("Prev"))
45 self["key_blue"] = Button(_("Next"))
46 self["now_button"] = Pixmap()
47 self["next_button"] = Pixmap()
48 self["more_button"] = Pixmap()
49 self["now_button_sel"] = Pixmap()
50 self["next_button_sel"] = Pixmap()
51 self["more_button_sel"] = Pixmap()
52 self["now_text"] = Label()
53 self["next_text"] = Label()
54 self["more_text"] = Label()
55 self["date"] = Label()
56 self.services = service
57 self.zapFunc = zapFunc
59 self["key_green"] = Button(_("Add timer"))
60 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
62 self["actions"] = ActionMap(["EPGSelectActions", "OkCancelActions"],
64 "cancel": self.closeScreen,
65 "ok": self.eventSelected,
66 "timerAdd": self.timerAdd,
67 "yellow": self.yellowButtonPressed,
68 "blue": self.blueButtonPressed,
69 "info": self.infoKeyPressed,
71 "input_date_time": self.enterDateTime,
72 "nextBouquet": self.nextBouquet,
73 "prevBouquet": self.prevBouquet
75 self["actions"].csel = self
77 self.onLayoutFinish.append(self.onCreate)
79 def nextBouquet(self):
80 if self.bouquetChangeCB:
81 self.bouquetChangeCB(1, self)
83 def prevBouquet(self):
84 if self.bouquetChangeCB:
85 self.bouquetChangeCB(-1, self)
87 def enterDateTime(self):
88 if self.type == EPG_TYPE_MULTI:
89 global mepg_config_initialized
90 if not mepg_config_initialized:
91 config.misc.prev_mepg_time=ConfigClock(default = time())
92 mepg_config_initialized = True
93 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput, config.misc.prev_mepg_time )
95 def onDateTimeInputClosed(self, ret):
99 self["list"].fillMultiEPG(self.services, ret[1])
101 def closeScreen(self):
102 self.close(self.closeRecursive)
104 def infoKeyPressed(self):
105 cur = self["list"].getCurrent()
108 if event is not None:
109 if self.type != EPG_TYPE_SIMILAR:
110 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
112 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
114 def openSimilarList(self, eventid, refstr):
115 self.session.open(EPGSelection, refstr, None, eventid)
117 def setServices(self, services):
118 self.services = services
121 #just used in multipeg
125 if self.type == EPG_TYPE_MULTI:
126 l.fillMultiEPG(self.services, self.ask_time)
127 elif self.type == EPG_TYPE_SINGLE:
128 l.fillSingleEPG(self.currentService)
130 l.fillSimilarList(self.currentService, self.eventid)
132 def eventViewCallback(self, setEvent, setService, val):
140 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
141 self.eventViewCallback(setEvent, setService, val)
146 def zapTo(self): # just used in multiepg
147 if self.zapFunc and self["key_red"].getText() == "Zap":
149 count = lst.getCurrentChangeCount()
151 self.closeRecursive = True
152 ref = lst.getCurrent()[1]
153 self.zapFunc(ref.ref)
155 def eventSelected(self):
156 self.infoKeyPressed()
158 def yellowButtonPressed(self):
159 if self.type == EPG_TYPE_MULTI:
160 self["list"].updateMultiEPG(-1)
161 elif self.type == EPG_TYPE_SINGLE:
162 if self.sort_type == 0:
166 self["list"].sortSingleEPG(self.sort_type)
167 self.setSortDescription()
169 def setSortDescription(self):
170 if self.sort_type == 1:
171 # TRANSLATORS: This must fit into the header button in the EPG-List
172 self["key_yellow"].setText(_("Sort Time"))
174 # TRANSLATORS: This must fit into the header button in the EPG-List
175 self["key_yellow"].setText(_("Sort A-Z"))
177 def blueButtonPressed(self):
178 if self.type == EPG_TYPE_MULTI:
179 self["list"].updateMultiEPG(1)
182 cur = self["list"].getCurrent()
187 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
188 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
190 def timerEditFinished(self, answer):
192 self.session.nav.RecordTimer.record(answer[1])
194 print "Timeredit aborted"
197 self["list"].moveUp()
200 self["list"].moveDown()
202 def applyButtonState(self, state):
204 self["now_button"].hide()
205 self["now_button_sel"].hide()
206 self["next_button"].hide()
207 self["next_button_sel"].hide()
208 self["more_button"].hide()
209 self["more_button_sel"].hide()
210 self["now_text"].hide()
211 self["next_text"].hide()
212 self["more_text"].hide()
213 self["key_red"].setText("")
216 self["key_red"].setText("Zap")
217 self["now_button_sel"].show()
218 self["now_button"].hide()
220 self["now_button"].show()
221 self["now_button_sel"].hide()
222 self["key_red"].setText("")
225 self["next_button_sel"].show()
226 self["next_button"].hide()
228 self["next_button"].show()
229 self["next_button_sel"].hide()
232 self["more_button_sel"].show()
233 self["more_button"].hide()
235 self["more_button"].show()
236 self["more_button_sel"].hide()
238 def onSelectionChanged(self):
239 if self.type == EPG_TYPE_MULTI:
240 count = self["list"].getCurrentChangeCount()
241 if self.ask_time != -1:
242 self.applyButtonState(0)
244 self.applyButtonState(3)
246 self.applyButtonState(2)
248 self.applyButtonState(1)
249 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
251 event = self["list"].getCurrent()[0]
252 if event is not None:
254 beg = event.getBeginTime()
255 nowTime = localtime(now)
256 begTime = localtime(beg)
257 if nowTime[2] != begTime[2]:
258 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
260 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
261 self["date"].setText(datestr)