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
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.skinName = "EPGSelectionMulti"
41 self.type = EPG_TYPE_MULTI
42 self["key_yellow"] = Button(_("Prev"))
43 self["key_blue"] = Button(_("Next"))
44 self["now_button"] = Pixmap()
45 self["next_button"] = Pixmap()
46 self["more_button"] = Pixmap()
47 self["now_button_sel"] = Pixmap()
48 self["next_button_sel"] = Pixmap()
49 self["more_button_sel"] = Pixmap()
50 self["now_text"] = Label()
51 self["next_text"] = Label()
52 self["more_text"] = Label()
53 self["date"] = Label()
54 self.services = service
55 self.zapFunc = zapFunc
57 self["key_green"] = Button(_("Add timer"))
58 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
60 class ChannelActionMap(ActionMap):
61 def action(self, contexts, action):
62 return ActionMap.action(self, contexts, action)
64 self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
66 "cancel": self.closeScreen,
67 "ok": self.eventSelected,
68 "timerAdd": self.timerAdd,
69 "yellow": self.yellowButtonPressed,
70 "blue": self.blueButtonPressed,
71 "info": self.infoKeyPressed,
73 "input_date_time": self.enterDateTime,
74 "nextBouquet": self.nextBouquet,
75 "prevBouquet": self.prevBouquet
77 self["actions"].csel = self
79 self.onLayoutFinish.append(self.onCreate)
81 def nextBouquet(self):
82 if self.bouquetChangeCB:
83 self.bouquetChangeCB(1, self)
85 def prevBouquet(self):
86 if self.bouquetChangeCB:
87 self.bouquetChangeCB(-1, self)
89 def enterDateTime(self):
90 if self.type == EPG_TYPE_MULTI:
91 global mepg_config_initialized
92 if not mepg_config_initialized:
93 config.misc.prev_mepg_time=ConfigClock(default = time())
94 mepg_config_initialized = True
95 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput, config.misc.prev_mepg_time )
97 def onDateTimeInputClosed(self, ret):
101 self["list"].fillMultiEPG(self.services, ret[1])
103 def closeScreen(self):
104 self.close(self.closeRecursive)
106 def infoKeyPressed(self):
107 cur = self["list"].getCurrent()
110 if event is not None:
111 if self.type != EPG_TYPE_SIMILAR:
112 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
114 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
116 def openSimilarList(self, eventid, refstr):
117 self.session.open(EPGSelection, refstr, None, eventid)
119 def setServices(self, services):
120 self.services = services
123 #just used in multipeg
127 if self.type == EPG_TYPE_MULTI:
128 l.fillMultiEPG(self.services, self.ask_time)
129 elif self.type == EPG_TYPE_SINGLE:
130 l.fillSingleEPG(self.currentService)
132 l.fillSimilarList(self.currentService, self.eventid)
134 def eventViewCallback(self, setEvent, setService, val):
142 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
143 self.eventViewCallback(setEvent, setService, val)
148 def zapTo(self): # just used in multiepg
149 if self.zapFunc and self["key_red"].getText() == "Zap":
151 count = lst.getCurrentChangeCount()
153 self.closeRecursive = True
154 ref = lst.getCurrent()[1]
155 self.zapFunc(ref.ref)
157 def eventSelected(self):
158 self.infoKeyPressed()
160 def yellowButtonPressed(self):
161 if self.type == EPG_TYPE_MULTI:
162 self["list"].updateMultiEPG(-1)
164 def blueButtonPressed(self):
165 if self.type == EPG_TYPE_MULTI:
166 self["list"].updateMultiEPG(1)
169 cur = self["list"].getCurrent()
174 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
175 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
177 def timerEditFinished(self, answer):
179 self.session.nav.RecordTimer.record(answer[1])
181 print "Timeredit aborted"
184 self["list"].moveUp()
187 self["list"].moveDown()
189 def applyButtonState(self, state):
191 self["now_button"].hide()
192 self["now_button_sel"].hide()
193 self["next_button"].hide()
194 self["next_button_sel"].hide()
195 self["more_button"].hide()
196 self["more_button_sel"].hide()
197 self["now_text"].hide()
198 self["next_text"].hide()
199 self["more_text"].hide()
200 self["key_red"].setText("")
203 self["key_red"].setText("Zap")
204 self["now_button_sel"].show()
205 self["now_button"].hide()
207 self["now_button"].show()
208 self["now_button_sel"].hide()
209 self["key_red"].setText("")
212 self["next_button_sel"].show()
213 self["next_button"].hide()
215 self["next_button"].show()
216 self["next_button_sel"].hide()
219 self["more_button_sel"].show()
220 self["more_button"].hide()
222 self["more_button"].show()
223 self["more_button_sel"].hide()
225 def onSelectionChanged(self):
226 if self.type == EPG_TYPE_MULTI:
227 count = self["list"].getCurrentChangeCount()
228 if self.ask_time != -1:
229 self.applyButtonState(0)
231 self.applyButtonState(3)
233 self.applyButtonState(2)
235 self.applyButtonState(1)
236 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
238 event = self["list"].getCurrent()[0]
239 if event is not None:
241 beg = event.getBeginTime()
242 nowTime = localtime(now)
243 begTime = localtime(beg)
244 if nowTime[2] != begTime[2]:
245 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
247 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
248 self["date"].setText(datestr)