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 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput)
82 def onDateTimeInputClosed(self, ret):
85 self.asked_specific_time=True
86 self["list"].fillMultiEPG(self.services, ret[1])
88 def closeScreen(self):
89 self.close(self.closeRecursive)
91 def infoKeyPressed(self):
92 if self.type == EPG_TYPE_MULTI or self.type == EPG_TYPE_SIMILAR:
93 cur = self["list"].getCurrent()
97 event = self["list"].getCurrent()
98 service = self.currentService
100 if self.type != EPG_TYPE_SIMILAR:
101 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
103 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
105 def openSimilarList(self, eventid, refstr):
106 self.session.open(EPGSelection, refstr, None, eventid)
108 #just used in multipeg
111 if self.type == EPG_TYPE_MULTI:
113 l.fillMultiEPG(self.services)
114 elif self.type == EPG_TYPE_SINGLE:
117 l.fillSingleEPG(self.currentService)
120 l.fillSimilarList(self.currentService, self.eventid)
122 def eventViewCallback(self, setEvent, setService, val):
130 if self.type == EPG_TYPE_SINGLE:
133 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
134 self.eventViewCallback(setEvent, setService, val)
139 def zapTo(self): # just used in multiepg
140 if self.zapFunc != None:
141 self.closeRecursive = True
142 ref = self["list"].getCurrent()[1]
143 self.zapFunc(ref.ref)
145 def eventSelected(self):
146 if self.type == EPG_TYPE_MULTI:
149 self.infoKeyPressed()
151 def yellowButtonPressed(self):
152 if self.type == EPG_TYPE_MULTI:
153 self["list"].updateMultiEPG(-1)
155 def blueButtonPressed(self):
156 if self.type == EPG_TYPE_MULTI:
157 self["list"].updateMultiEPG(1)
160 if self.type == EPG_TYPE_SINGLE:
161 event = self["list"].getCurrent()
162 serviceref = self.currentService
164 cur = self["list"].getCurrent()
169 newEntry = RecordTimerEntry(serviceref, *parseEvent(event))
170 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
172 def timerEditFinished(self, answer):
174 self.session.nav.RecordTimer.record(answer[1])
176 print "Timeredit aborted"
179 self["list"].moveUp()
182 self["list"].moveDown()
184 def applyButtonState(self, state):
186 self["now_button"].hide()
187 self["now_button_sel"].hide()
188 self["next_button"].hide()
189 self["next_button_sel"].hide()
190 self["more_button"].hide()
191 self["more_button_sel"].hide()
192 self["now_text"].hide()
193 self["next_text"].hide()
194 self["more_text"].hide()
197 self["now_button_sel"].show()
198 self["now_button"].hide()
200 self["now_button"].show()
201 self["now_button_sel"].hide()
204 self["next_button_sel"].show()
205 self["next_button"].hide()
207 self["next_button"].show()
208 self["next_button_sel"].hide()
211 self["more_button_sel"].show()
212 self["more_button"].hide()
214 self["more_button"].show()
215 self["more_button_sel"].hide()
217 def onSelectionChanged(self):
218 if self.type == EPG_TYPE_MULTI:
219 count = self["list"].getCurrentChangeCount()
220 if self.asked_specific_time:
221 self.applyButtonState(0)
223 self.applyButtonState(3)
225 self.applyButtonState(2)
227 self.applyButtonState(1)
228 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
230 event = self["list"].getCurrent()[0]
231 if event is not None:
233 beg = event.getBeginTime()
234 nowTime = localtime(now)
235 begTime = localtime(beg)
236 if nowTime[2] != begTime[2]:
237 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
239 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
240 self["date"].setText(datestr)