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):
23 Screen.__init__(self, session)
24 self.asked_specific_time = False
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
34 elif isinstance(service, eServiceReference) or isinstance(service, str):
35 self.type = EPG_TYPE_SINGLE
36 self["key_yellow"] = Button()
37 self["key_blue"] = Button()
38 self.currentService=ServiceReference(service)
40 self.skinName = "EPGSelectionMulti"
41 self.type = EPG_TYPE_MULTI
42 self["key_yellow"] = Button(_("Prev"))
43 self["key_blue"] = Button(_("Next"))
44 self["now_button"] = Pixmap()
45 self["next_button"] = Pixmap()
46 self["more_button"] = Pixmap()
47 self["now_button_sel"] = Pixmap()
48 self["next_button_sel"] = Pixmap()
49 self["more_button_sel"] = Pixmap()
50 self["now_text"] = Label()
51 self["next_text"] = Label()
52 self["more_text"] = Label()
53 self["date"] = Label()
54 self.services = service
55 self.zapFunc = zapFunc
57 self["key_green"] = Button(_("Add timer"))
58 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
60 class ChannelActionMap(ActionMap):
61 def action(self, contexts, action):
62 return ActionMap.action(self, contexts, action)
64 self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
66 "cancel": self.closeScreen,
67 "ok": self.eventSelected,
68 "timerAdd": self.timerAdd,
69 "yellow": self.yellowButtonPressed,
70 "blue": self.blueButtonPressed,
71 "info": self.infoKeyPressed,
73 "input_date_time": self.enterDateTime
75 self["actions"].csel = self
77 self.onLayoutFinish.append(self.onCreate)
79 def enterDateTime(self):
80 if self.type == EPG_TYPE_MULTI:
81 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput)
83 def onDateTimeInputClosed(self, ret):
86 self.asked_specific_time=True
87 self["list"].fillMultiEPG(self.services, ret[1])
89 def closeScreen(self):
90 self.close(self.closeRecursive)
92 def infoKeyPressed(self):
93 if self.type == EPG_TYPE_MULTI or self.type == EPG_TYPE_SIMILAR:
94 cur = self["list"].getCurrent()
98 event = self["list"].getCurrent()
99 service = self.currentService
100 if event is not None:
101 if self.type != EPG_TYPE_SIMILAR:
102 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
104 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
106 def openSimilarList(self, eventid, refstr):
107 self.session.open(EPGSelection, refstr, None, eventid)
109 #just used in multipeg
112 if self.type == EPG_TYPE_MULTI:
114 l.fillMultiEPG(self.services)
115 elif self.type == EPG_TYPE_SINGLE:
118 l.fillSingleEPG(self.currentService)
121 l.fillSimilarList(self.currentService, self.eventid)
123 def eventViewCallback(self, setEvent, setService, val):
131 if self.type == EPG_TYPE_SINGLE:
134 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
135 self.eventViewCallback(setEvent, setService, val)
140 def zapTo(self): # just used in multiepg
141 if self.zapFunc != None:
142 self.closeRecursive = True
143 ref = self["list"].getCurrent()[1]
144 self.zapFunc(ref.ref)
146 def eventSelected(self):
147 if self.type == EPG_TYPE_MULTI:
150 self.infoKeyPressed()
152 def yellowButtonPressed(self):
153 if self.type == EPG_TYPE_MULTI:
154 self["list"].updateMultiEPG(-1)
156 def blueButtonPressed(self):
157 if self.type == EPG_TYPE_MULTI:
158 self["list"].updateMultiEPG(1)
161 if self.type == EPG_TYPE_SINGLE:
162 event = self["list"].getCurrent()
163 serviceref = self.currentService
165 cur = self["list"].getCurrent()
170 newEntry = RecordTimerEntry(serviceref, *parseEvent(event))
171 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
173 def timerEditFinished(self, answer):
175 self.session.nav.RecordTimer.record(answer[1])
177 print "Timeredit aborted"
180 self["list"].moveUp()
183 self["list"].moveDown()
185 def applyButtonState(self, state):
187 self["now_button"].hide()
188 self["now_button_sel"].hide()
189 self["next_button"].hide()
190 self["next_button_sel"].hide()
191 self["more_button"].hide()
192 self["more_button_sel"].hide()
193 self["now_text"].hide()
194 self["next_text"].hide()
195 self["more_text"].hide()
198 self["now_button_sel"].show()
199 self["now_button"].hide()
201 self["now_button"].show()
202 self["now_button_sel"].hide()
205 self["next_button_sel"].show()
206 self["next_button"].hide()
208 self["next_button"].show()
209 self["next_button_sel"].hide()
212 self["more_button_sel"].show()
213 self["more_button"].hide()
215 self["more_button"].show()
216 self["more_button_sel"].hide()
218 def onSelectionChanged(self):
219 if self.type == EPG_TYPE_MULTI:
220 count = self["list"].getCurrentChangeCount()
221 if self.asked_specific_time:
222 self.applyButtonState(0)
224 self.applyButtonState(3)
226 self.applyButtonState(2)
228 self.applyButtonState(1)
229 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
231 event = self["list"].getCurrent()[0]
232 if event is not None:
234 beg = event.getBeginTime()
235 nowTime = localtime(now)
236 begTime = localtime(beg)
237 if nowTime[2] != begTime[2]:
238 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
240 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
241 self["date"].setText(datestr)