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.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 self["actions"] = ActionMap(["EPGSelectActions", "OkCancelActions"],
62 "cancel": self.closeScreen,
63 "ok": self.eventSelected,
64 "timerAdd": self.timerAdd,
65 "yellow": self.yellowButtonPressed,
66 "blue": self.blueButtonPressed,
67 "info": self.infoKeyPressed,
69 "input_date_time": self.enterDateTime,
70 "nextBouquet": self.nextBouquet,
71 "prevBouquet": self.prevBouquet
73 self["actions"].csel = self
75 self.onLayoutFinish.append(self.onCreate)
77 def nextBouquet(self):
78 if self.bouquetChangeCB:
79 self.bouquetChangeCB(1, self)
81 def prevBouquet(self):
82 if self.bouquetChangeCB:
83 self.bouquetChangeCB(-1, self)
85 def enterDateTime(self):
86 if self.type == EPG_TYPE_MULTI:
87 global mepg_config_initialized
88 if not mepg_config_initialized:
89 config.misc.prev_mepg_time=ConfigClock(default = time())
90 mepg_config_initialized = True
91 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput, config.misc.prev_mepg_time )
93 def onDateTimeInputClosed(self, ret):
97 self["list"].fillMultiEPG(self.services, ret[1])
99 def closeScreen(self):
100 self.close(self.closeRecursive)
102 def infoKeyPressed(self):
103 cur = self["list"].getCurrent()
106 if event is not None:
107 if self.type != EPG_TYPE_SIMILAR:
108 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
110 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
112 def openSimilarList(self, eventid, refstr):
113 self.session.open(EPGSelection, refstr, None, eventid)
115 def setServices(self, services):
116 self.services = services
119 #just used in multipeg
123 if self.type == EPG_TYPE_MULTI:
124 l.fillMultiEPG(self.services, self.ask_time)
125 elif self.type == EPG_TYPE_SINGLE:
126 l.fillSingleEPG(self.currentService)
128 l.fillSimilarList(self.currentService, self.eventid)
130 def eventViewCallback(self, setEvent, setService, val):
138 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
139 self.eventViewCallback(setEvent, setService, val)
144 def zapTo(self): # just used in multiepg
145 if self.zapFunc and self["key_red"].getText() == "Zap":
147 count = lst.getCurrentChangeCount()
149 self.closeRecursive = True
150 ref = lst.getCurrent()[1]
151 self.zapFunc(ref.ref)
153 def eventSelected(self):
154 self.infoKeyPressed()
156 def yellowButtonPressed(self):
157 if self.type == EPG_TYPE_MULTI:
158 self["list"].updateMultiEPG(-1)
160 def blueButtonPressed(self):
161 if self.type == EPG_TYPE_MULTI:
162 self["list"].updateMultiEPG(1)
165 cur = self["list"].getCurrent()
170 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
171 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
173 def timerEditFinished(self, answer):
175 self.session.nav.RecordTimer.record(answer[1])
177 print "Timeredit aborted"
180 self["list"].moveUp()
183 self["list"].moveDown()
185 def applyButtonState(self, state):
187 self["now_button"].hide()
188 self["now_button_sel"].hide()
189 self["next_button"].hide()
190 self["next_button_sel"].hide()
191 self["more_button"].hide()
192 self["more_button_sel"].hide()
193 self["now_text"].hide()
194 self["next_text"].hide()
195 self["more_text"].hide()
196 self["key_red"].setText("")
199 self["key_red"].setText("Zap")
200 self["now_button_sel"].show()
201 self["now_button"].hide()
203 self["now_button"].show()
204 self["now_button_sel"].hide()
205 self["key_red"].setText("")
208 self["next_button_sel"].show()
209 self["next_button"].hide()
211 self["next_button"].show()
212 self["next_button_sel"].hide()
215 self["more_button_sel"].show()
216 self["more_button"].hide()
218 self["more_button"].show()
219 self["more_button_sel"].hide()
221 def onSelectionChanged(self):
222 if self.type == EPG_TYPE_MULTI:
223 count = self["list"].getCurrentChangeCount()
224 if self.ask_time != -1:
225 self.applyButtonState(0)
227 self.applyButtonState(3)
229 self.applyButtonState(2)
231 self.applyButtonState(1)
232 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
234 event = self["list"].getCurrent()[0]
235 if event is not None:
237 beg = event.getBeginTime()
238 nowTime = localtime(now)
239 begTime = localtime(beg)
240 if nowTime[2] != begTime[2]:
241 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
243 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
244 self["date"].setText(datestr)