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, time
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 cur = self["list"].getCurrent()
109 if event is not None:
110 if self.type != EPG_TYPE_SIMILAR:
111 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
113 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
115 def openSimilarList(self, eventid, refstr):
116 self.session.open(EPGSelection, refstr, None, eventid)
118 def setServices(self, services):
119 self.services = services
122 #just used in multipeg
126 if self.type == EPG_TYPE_MULTI:
127 l.fillMultiEPG(self.services, self.ask_time)
128 elif self.type == EPG_TYPE_SINGLE:
129 l.fillSingleEPG(self.currentService)
131 l.fillSimilarList(self.currentService, self.eventid)
133 def eventViewCallback(self, setEvent, setService, val):
141 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
142 self.eventViewCallback(setEvent, setService, val)
147 def zapTo(self): # just used in multiepg
148 if self.zapFunc and self["key_red"].getText() == "Zap":
150 count = lst.getCurrentChangeCount()
152 self.closeRecursive = True
153 ref = lst.getCurrent()[1]
154 self.zapFunc(ref.ref)
156 def eventSelected(self):
157 self.infoKeyPressed()
159 def yellowButtonPressed(self):
160 if self.type == EPG_TYPE_MULTI:
161 self["list"].updateMultiEPG(-1)
163 def blueButtonPressed(self):
164 if self.type == EPG_TYPE_MULTI:
165 self["list"].updateMultiEPG(1)
168 cur = self["list"].getCurrent()
173 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
174 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
176 def timerEditFinished(self, answer):
178 self.session.nav.RecordTimer.record(answer[1])
180 print "Timeredit aborted"
183 self["list"].moveUp()
186 self["list"].moveDown()
188 def applyButtonState(self, state):
190 self["now_button"].hide()
191 self["now_button_sel"].hide()
192 self["next_button"].hide()
193 self["next_button_sel"].hide()
194 self["more_button"].hide()
195 self["more_button_sel"].hide()
196 self["now_text"].hide()
197 self["next_text"].hide()
198 self["more_text"].hide()
199 self["key_red"].setText("")
202 self["key_red"].setText("Zap")
203 self["now_button_sel"].show()
204 self["now_button"].hide()
206 self["now_button"].show()
207 self["now_button_sel"].hide()
208 self["key_red"].setText("")
211 self["next_button_sel"].show()
212 self["next_button"].hide()
214 self["next_button"].show()
215 self["next_button_sel"].hide()
218 self["more_button_sel"].show()
219 self["more_button"].hide()
221 self["more_button"].show()
222 self["more_button_sel"].hide()
224 def onSelectionChanged(self):
225 if self.type == EPG_TYPE_MULTI:
226 count = self["list"].getCurrentChangeCount()
227 if self.ask_time != -1:
228 self.applyButtonState(0)
230 self.applyButtonState(3)
232 self.applyButtonState(2)
234 self.applyButtonState(1)
235 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
237 event = self["list"].getCurrent()[0]
238 if event is not None:
240 beg = event.getBeginTime()
241 nowTime = localtime(now)
242 begTime = localtime(beg)
243 if nowTime[2] != begTime[2]:
244 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
246 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
247 self["date"].setText(datestr)