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
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 time import localtime, time
18 import xml.dom.minidom
20 class EPGSelection(Screen):
21 def __init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None):
22 Screen.__init__(self, session)
23 self.bouquetChangeCB = bouquetChangeCB
24 self.ask_time = -1 #now
25 self["key_red"] = Button("")
26 self.closeRecursive = False
27 if isinstance(service, str) and eventid != None:
28 self.type = EPG_TYPE_SIMILAR
29 self["key_yellow"] = Button()
30 self["key_blue"] = Button()
31 self["key_red"] = Button()
32 self.currentService=service
33 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)
42 self.skinName = "EPGSelectionMulti"
43 self.type = EPG_TYPE_MULTI
44 self["key_yellow"] = Button(_("Prev"))
45 self["key_blue"] = Button(_("Next"))
46 self["now_button"] = Pixmap()
47 self["next_button"] = Pixmap()
48 self["more_button"] = Pixmap()
49 self["now_button_sel"] = Pixmap()
50 self["next_button_sel"] = Pixmap()
51 self["more_button_sel"] = Pixmap()
52 self["now_text"] = Label()
53 self["next_text"] = Label()
54 self["more_text"] = Label()
55 self["date"] = Label()
56 self.services = service
57 self.zapFunc = zapFunc
59 self["key_green"] = Button(_("Add timer"))
60 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
62 class ChannelActionMap(ActionMap):
63 def action(self, contexts, action):
64 return ActionMap.action(self, contexts, action)
66 self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
68 "cancel": self.closeScreen,
69 "ok": self.eventSelected,
70 "timerAdd": self.timerAdd,
71 "yellow": self.yellowButtonPressed,
72 "blue": self.blueButtonPressed,
73 "info": self.infoKeyPressed,
75 "input_date_time": self.enterDateTime,
76 "nextBouquet": self.nextBouquet,
77 "prevBouquet": self.prevBouquet
79 self["actions"].csel = self
81 self.onLayoutFinish.append(self.onCreate)
83 def nextBouquet(self):
84 if self.bouquetChangeCB:
85 self.bouquetChangeCB(1, self)
87 def prevBouquet(self):
88 if self.bouquetChangeCB:
89 self.bouquetChangeCB(-1, self)
91 def enterDateTime(self):
92 if self.type == EPG_TYPE_MULTI:
93 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput)
95 def onDateTimeInputClosed(self, ret):
99 self["list"].fillMultiEPG(self.services, ret[1])
101 def closeScreen(self):
102 self.close(self.closeRecursive)
104 def infoKeyPressed(self):
105 cur = self["list"].getCurrent()
108 if event is not None:
109 if self.type != EPG_TYPE_SIMILAR:
110 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
112 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
114 def openSimilarList(self, eventid, refstr):
115 self.session.open(EPGSelection, refstr, None, eventid)
117 def setServices(self, services):
118 self.services = services
121 #just used in multipeg
125 if self.type == EPG_TYPE_MULTI:
126 l.fillMultiEPG(self.services, self.ask_time)
127 elif self.type == EPG_TYPE_SINGLE:
128 l.fillSingleEPG(self.currentService)
130 l.fillSimilarList(self.currentService, self.eventid)
132 def eventViewCallback(self, setEvent, setService, val):
140 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
141 self.eventViewCallback(setEvent, setService, val)
146 def zapTo(self): # just used in multiepg
147 if self.zapFunc and self["key_red"].getText() == "Zap":
149 count = lst.getCurrentChangeCount()
151 self.closeRecursive = True
152 ref = lst.getCurrent()[1]
153 self.zapFunc(ref.ref)
155 def eventSelected(self):
156 self.infoKeyPressed()
158 def yellowButtonPressed(self):
159 if self.type == EPG_TYPE_MULTI:
160 self["list"].updateMultiEPG(-1)
162 def blueButtonPressed(self):
163 if self.type == EPG_TYPE_MULTI:
164 self["list"].updateMultiEPG(1)
167 cur = self["list"].getCurrent()
172 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
173 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
175 def timerEditFinished(self, answer):
177 self.session.nav.RecordTimer.record(answer[1])
179 print "Timeredit aborted"
182 self["list"].moveUp()
185 self["list"].moveDown()
187 def applyButtonState(self, state):
189 self["now_button"].hide()
190 self["now_button_sel"].hide()
191 self["next_button"].hide()
192 self["next_button_sel"].hide()
193 self["more_button"].hide()
194 self["more_button_sel"].hide()
195 self["now_text"].hide()
196 self["next_text"].hide()
197 self["more_text"].hide()
198 self["key_red"].setText("")
201 self["key_red"].setText("Zap")
202 self["now_button_sel"].show()
203 self["now_button"].hide()
205 self["now_button"].show()
206 self["now_button_sel"].hide()
207 self["key_red"].setText("")
210 self["next_button_sel"].show()
211 self["next_button"].hide()
213 self["next_button"].show()
214 self["next_button_sel"].hide()
217 self["more_button_sel"].show()
218 self["more_button"].hide()
220 self["more_button"].show()
221 self["more_button_sel"].hide()
223 def onSelectionChanged(self):
224 if self.type == EPG_TYPE_MULTI:
225 count = self["list"].getCurrentChangeCount()
226 if self.ask_time != -1:
227 self.applyButtonState(0)
229 self.applyButtonState(3)
231 self.applyButtonState(2)
233 self.applyButtonState(1)
234 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
236 event = self["list"].getCurrent()[0]
237 if event is not None:
239 beg = event.getBeginTime()
240 nowTime = localtime(now)
241 begTime = localtime(beg)
242 if nowTime[2] != begTime[2]:
243 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
245 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
246 self["date"].setText(datestr)