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
35 elif isinstance(service, eServiceReference) or isinstance(service, str):
36 self.type = EPG_TYPE_SINGLE
37 self["key_yellow"] = Button()
38 self["key_blue"] = Button()
39 self.currentService=ServiceReference(service)
41 self.skinName = "EPGSelectionMulti"
42 self.type = EPG_TYPE_MULTI
43 self["key_yellow"] = Button(_("Prev"))
44 self["key_blue"] = Button(_("Next"))
45 self["now_button"] = Pixmap()
46 self["next_button"] = Pixmap()
47 self["more_button"] = Pixmap()
48 self["now_button_sel"] = Pixmap()
49 self["next_button_sel"] = Pixmap()
50 self["more_button_sel"] = Pixmap()
51 self["now_text"] = Label()
52 self["next_text"] = Label()
53 self["more_text"] = Label()
54 self["date"] = Label()
55 self.services = service
56 self.zapFunc = zapFunc
58 self["key_green"] = Button(_("Add timer"))
59 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
61 class ChannelActionMap(ActionMap):
62 def action(self, contexts, action):
63 return ActionMap.action(self, contexts, action)
65 self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
67 "cancel": self.closeScreen,
68 "ok": self.eventSelected,
69 "timerAdd": self.timerAdd,
70 "yellow": self.yellowButtonPressed,
71 "blue": self.blueButtonPressed,
72 "info": self.infoKeyPressed,
74 "input_date_time": self.enterDateTime,
75 "nextBouquet": self.nextBouquet,
76 "prevBouquet": self.prevBouquet
78 self["actions"].csel = self
80 self.onLayoutFinish.append(self.onCreate)
82 def nextBouquet(self):
83 if self.bouquetChangeCB:
84 self.bouquetChangeCB(1, self)
86 def prevBouquet(self):
87 if self.bouquetChangeCB:
88 self.bouquetChangeCB(-1, self)
90 def enterDateTime(self):
91 if self.type == EPG_TYPE_MULTI:
92 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput)
94 def onDateTimeInputClosed(self, ret):
98 self["list"].fillMultiEPG(self.services, ret[1])
100 def closeScreen(self):
101 self.close(self.closeRecursive)
103 def infoKeyPressed(self):
104 if self.type == EPG_TYPE_MULTI or self.type == EPG_TYPE_SIMILAR:
105 cur = self["list"].getCurrent()
109 event = self["list"].getCurrent()
110 service = self.currentService
111 if event is not None:
112 if self.type != EPG_TYPE_SIMILAR:
113 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
115 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
117 def openSimilarList(self, eventid, refstr):
118 self.session.open(EPGSelection, refstr, None, eventid)
120 def setServices(self, services):
121 self.services = services
124 #just used in multipeg
127 if self.type == EPG_TYPE_MULTI:
129 l.fillMultiEPG(self.services, self.ask_time)
130 elif self.type == EPG_TYPE_SINGLE:
133 l.fillSingleEPG(self.currentService)
136 l.fillSimilarList(self.currentService, self.eventid)
138 def eventViewCallback(self, setEvent, setService, val):
146 if self.type == EPG_TYPE_SINGLE:
149 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
150 self.eventViewCallback(setEvent, setService, val)
155 def zapTo(self): # just used in multiepg
156 if self.zapFunc and self["key_red"].getText() == "Zap":
158 count = lst.getCurrentChangeCount()
160 self.closeRecursive = True
161 ref = lst.getCurrent()[1]
162 self.zapFunc(ref.ref)
164 def eventSelected(self):
165 self.infoKeyPressed()
167 def yellowButtonPressed(self):
168 if self.type == EPG_TYPE_MULTI:
169 self["list"].updateMultiEPG(-1)
171 def blueButtonPressed(self):
172 if self.type == EPG_TYPE_MULTI:
173 self["list"].updateMultiEPG(1)
176 if self.type == EPG_TYPE_SINGLE:
177 event = self["list"].getCurrent()
178 serviceref = self.currentService
180 cur = self["list"].getCurrent()
185 newEntry = RecordTimerEntry(serviceref, *parseEvent(event))
186 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
188 def timerEditFinished(self, answer):
190 self.session.nav.RecordTimer.record(answer[1])
192 print "Timeredit aborted"
195 self["list"].moveUp()
198 self["list"].moveDown()
200 def applyButtonState(self, state):
202 self["now_button"].hide()
203 self["now_button_sel"].hide()
204 self["next_button"].hide()
205 self["next_button_sel"].hide()
206 self["more_button"].hide()
207 self["more_button_sel"].hide()
208 self["now_text"].hide()
209 self["next_text"].hide()
210 self["more_text"].hide()
211 self["key_red"].setText("")
214 self["key_red"].setText("Zap")
215 self["now_button_sel"].show()
216 self["now_button"].hide()
218 self["now_button"].show()
219 self["now_button_sel"].hide()
220 self["key_red"].setText("")
223 self["next_button_sel"].show()
224 self["next_button"].hide()
226 self["next_button"].show()
227 self["next_button_sel"].hide()
230 self["more_button_sel"].show()
231 self["more_button"].hide()
233 self["more_button"].show()
234 self["more_button_sel"].hide()
236 def onSelectionChanged(self):
237 if self.type == EPG_TYPE_MULTI:
238 count = self["list"].getCurrentChangeCount()
239 if self.ask_time != -1:
240 self.applyButtonState(0)
242 self.applyButtonState(3)
244 self.applyButtonState(2)
246 self.applyButtonState(1)
247 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
249 event = self["list"].getCurrent()[0]
250 if event is not None:
252 beg = event.getBeginTime()
253 nowTime = localtime(now)
254 begTime = localtime(beg)
255 if nowTime[2] != begTime[2]:
256 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
258 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
259 self["date"].setText(datestr)