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 print "event", cur[0]
110 print "service", cur[1]
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
128 if self.type == EPG_TYPE_MULTI:
129 l.fillMultiEPG(self.services, self.ask_time)
130 elif self.type == EPG_TYPE_SINGLE:
131 l.fillSingleEPG(self.currentService)
133 l.fillSimilarList(self.currentService, self.eventid)
135 def eventViewCallback(self, setEvent, setService, val):
143 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
144 self.eventViewCallback(setEvent, setService, val)
149 def zapTo(self): # just used in multiepg
150 if self.zapFunc and self["key_red"].getText() == "Zap":
152 count = lst.getCurrentChangeCount()
154 self.closeRecursive = True
155 ref = lst.getCurrent()[1]
156 self.zapFunc(ref.ref)
158 def eventSelected(self):
159 self.infoKeyPressed()
161 def yellowButtonPressed(self):
162 if self.type == EPG_TYPE_MULTI:
163 self["list"].updateMultiEPG(-1)
165 def blueButtonPressed(self):
166 if self.type == EPG_TYPE_MULTI:
167 self["list"].updateMultiEPG(1)
170 cur = self["list"].getCurrent()
175 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
176 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
178 def timerEditFinished(self, answer):
180 self.session.nav.RecordTimer.record(answer[1])
182 print "Timeredit aborted"
185 self["list"].moveUp()
188 self["list"].moveDown()
190 def applyButtonState(self, state):
192 self["now_button"].hide()
193 self["now_button_sel"].hide()
194 self["next_button"].hide()
195 self["next_button_sel"].hide()
196 self["more_button"].hide()
197 self["more_button_sel"].hide()
198 self["now_text"].hide()
199 self["next_text"].hide()
200 self["more_text"].hide()
201 self["key_red"].setText("")
204 self["key_red"].setText("Zap")
205 self["now_button_sel"].show()
206 self["now_button"].hide()
208 self["now_button"].show()
209 self["now_button_sel"].hide()
210 self["key_red"].setText("")
213 self["next_button_sel"].show()
214 self["next_button"].hide()
216 self["next_button"].show()
217 self["next_button_sel"].hide()
220 self["more_button_sel"].show()
221 self["more_button"].hide()
223 self["more_button"].show()
224 self["more_button_sel"].hide()
226 def onSelectionChanged(self):
227 if self.type == EPG_TYPE_MULTI:
228 count = self["list"].getCurrentChangeCount()
229 if self.ask_time != -1:
230 self.applyButtonState(0)
232 self.applyButtonState(3)
234 self.applyButtonState(2)
236 self.applyButtonState(1)
237 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
239 event = self["list"].getCurrent()[0]
240 if event is not None:
242 beg = event.getBeginTime()
243 nowTime = localtime(now)
244 begTime = localtime(beg)
245 if nowTime[2] != begTime[2]:
246 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
248 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
249 self["date"].setText(datestr)