1 from Screen import Screen
2 from Components.Button import Button
3 from Components.Pixmap import Pixmap
4 from Components.Label import Label
5 from Components.EpgList import *
6 from Components.ActionMap import ActionMap
7 from Components.ScrollLabel import ScrollLabel
8 from Screens.EventView import EventViewSimple
9 from TimeDateInput import TimeDateInput
10 from enigma import eServiceReference, eServiceEventPtr
11 from Screens.FixedMenu import FixedMenu
12 from RecordTimer import RecordTimerEntry, parseEvent
13 from TimerEdit import TimerEditList
14 from TimerEntry import TimerEntry
15 from ServiceReference import ServiceReference
16 from Components.config import config, currentConfigSelectionElement
17 from time import localtime
19 import xml.dom.minidom
21 class EPGSelection(Screen):
22 def __init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None):
23 Screen.__init__(self, session)
24 self.bouquetChangeCB = bouquetChangeCB
25 self.ask_time = -1 #now
26 self["key_red"] = Button("")
27 self.closeRecursive = False
28 if isinstance(service, str) and eventid != None:
29 self.type = EPG_TYPE_SIMILAR
30 self["key_yellow"] = Button()
31 self["key_blue"] = Button()
32 self["key_red"] = Button()
33 self.currentService=service
34 self.eventid = eventid
36 elif isinstance(service, eServiceReference) or isinstance(service, str):
37 self.type = EPG_TYPE_SINGLE
38 self["key_yellow"] = Button()
39 self["key_blue"] = Button()
40 self.currentService=ServiceReference(service)
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 class ChannelActionMap(ActionMap):
64 def action(self, contexts, action):
65 return ActionMap.action(self, contexts, action)
67 self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
69 "cancel": self.closeScreen,
70 "ok": self.eventSelected,
71 "timerAdd": self.timerAdd,
72 "yellow": self.yellowButtonPressed,
73 "blue": self.blueButtonPressed,
74 "info": self.infoKeyPressed,
76 "input_date_time": self.enterDateTime,
77 "nextBouquet": self.nextBouquet,
78 "prevBouquet": self.prevBouquet
80 self["actions"].csel = self
82 self.onLayoutFinish.append(self.onCreate)
84 def nextBouquet(self):
85 if self.bouquetChangeCB:
86 self.bouquetChangeCB(1, self)
88 def prevBouquet(self):
89 if self.bouquetChangeCB:
90 self.bouquetChangeCB(-1, self)
92 def enterDateTime(self):
93 if self.type == EPG_TYPE_MULTI:
94 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput)
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 if self.type == EPG_TYPE_MULTI or self.type == EPG_TYPE_SIMILAR:
107 cur = self["list"].getCurrent()
111 event = self["list"].getCurrent()
112 service = self.currentService
113 if event is not None:
114 if self.type != EPG_TYPE_SIMILAR:
115 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
117 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
119 def openSimilarList(self, eventid, refstr):
120 self.session.open(EPGSelection, refstr, None, eventid)
122 def setServices(self, services):
123 self.services = services
126 #just used in multipeg
129 if self.type == EPG_TYPE_MULTI:
131 l.fillMultiEPG(self.services, self.ask_time)
132 elif self.type == EPG_TYPE_SINGLE:
135 l.fillSingleEPG(self.currentService)
138 l.fillSimilarList(self.currentService, self.eventid)
140 def eventViewCallback(self, setEvent, setService, val):
148 if self.type == EPG_TYPE_SINGLE:
151 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
152 self.eventViewCallback(setEvent, setService, val)
157 def zapTo(self): # just used in multiepg
158 if self.zapFunc and self["key_red"].getText() == "Zap":
160 count = lst.getCurrentChangeCount()
162 self.closeRecursive = True
163 ref = lst.getCurrent()[1]
164 self.zapFunc(ref.ref)
166 def eventSelected(self):
167 self.infoKeyPressed()
169 def yellowButtonPressed(self):
170 if self.type == EPG_TYPE_MULTI:
171 self["list"].updateMultiEPG(-1)
173 def blueButtonPressed(self):
174 if self.type == EPG_TYPE_MULTI:
175 self["list"].updateMultiEPG(1)
178 if self.type == EPG_TYPE_SINGLE:
179 event = self["list"].getCurrent()
180 serviceref = self.currentService
182 cur = self["list"].getCurrent()
187 newEntry = RecordTimerEntry(serviceref, *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)