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 enigma import eServiceReference, eServiceEventPtr
10 from Screens.FixedMenu import FixedMenu
11 from RecordTimer import RecordTimerEntry, parseEvent
12 from TimerEdit import TimerEditList
13 from TimerEntry import TimerEntry
14 from ServiceReference import ServiceReference
15 from Components.config import config, currentConfigSelectionElement
16 from time import localtime
18 import xml.dom.minidom
20 class EPGSelection(Screen):
21 def __init__(self, session, service, zapFunc=None, eventid=None):
22 Screen.__init__(self, session)
23 self["key_red"] = Button("")
24 self.closeRecursive = False
25 if isinstance(service, str) and eventid != None:
26 self.type = EPG_TYPE_SIMILAR
27 self["key_yellow"] = Button()
28 self["key_blue"] = Button()
29 self["key_red"] = Button()
30 self.currentService=service
31 self.eventid = eventid
32 elif isinstance(service, eServiceReference) or isinstance(service, str):
33 self.type = EPG_TYPE_SINGLE
34 self["key_yellow"] = Button()
35 self["key_blue"] = Button()
36 self.currentService=ServiceReference(service)
38 self.skinName = "EPGSelectionMulti"
39 self.type = EPG_TYPE_MULTI
40 self["key_yellow"] = Button(_("Prev"))
41 self["key_blue"] = Button(_("Next"))
42 self["now_button"] = Pixmap()
43 self["next_button"] = Pixmap()
44 self["more_button"] = Pixmap()
45 self["now_button_sel"] = Pixmap()
46 self["next_button_sel"] = Pixmap()
47 self["more_button_sel"] = Pixmap()
48 self["now_text"] = Label()
49 self["next_text"] = Label()
50 self["more_text"] = Label()
51 self["date"] = Label()
52 self.services = service
53 self.zapFunc = zapFunc
55 self["key_green"] = Button(_("Add timer"))
56 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
58 class ChannelActionMap(ActionMap):
59 def action(self, contexts, action):
60 return ActionMap.action(self, contexts, action)
62 self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
64 "cancel": self.closeScreen,
65 "ok": self.eventSelected,
66 "timerAdd": self.timerAdd,
67 "yellow": self.yellowButtonPressed,
68 "blue": self.blueButtonPressed,
69 "info": self.infoKeyPressed,
72 self["actions"].csel = self
74 self.onLayoutFinish.append(self.onCreate)
76 def closeScreen(self):
77 self.close(self.closeRecursive)
79 def infoKeyPressed(self):
80 if self.type == EPG_TYPE_MULTI or self.type == EPG_TYPE_SIMILAR:
81 cur = self["list"].getCurrent()
85 event = self["list"].getCurrent()
86 service = self.currentService
88 if self.type != EPG_TYPE_SIMILAR:
89 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
91 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
93 def openSimilarList(self, eventid, refstr):
94 self.session.open(EPGSelection, refstr, None, eventid)
96 #just used in multipeg
99 if self.type == EPG_TYPE_MULTI:
101 l.fillMultiEPG(self.services)
102 elif self.type == EPG_TYPE_SINGLE:
105 l.fillSingleEPG(self.currentService)
108 l.fillSimilarList(self.currentService, self.eventid)
110 def eventViewCallback(self, setEvent, setService, val):
118 if self.type == EPG_TYPE_SINGLE:
121 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
122 self.eventViewCallback(setEvent, setService, val)
127 def zapTo(self): # just used in multiepg
128 if self.zapFunc != None:
129 self.closeRecursive = True
130 ref = self["list"].getCurrent()[1]
131 self.zapFunc(ref.ref)
133 def eventSelected(self):
134 if self.type == EPG_TYPE_MULTI:
137 self.infoKeyPressed()
139 def yellowButtonPressed(self):
140 if self.type == EPG_TYPE_MULTI:
141 self["list"].updateMultiEPG(-1)
143 def blueButtonPressed(self):
144 if self.type == EPG_TYPE_MULTI:
145 self["list"].updateMultiEPG(1)
148 if self.type == EPG_TYPE_SINGLE:
149 event = self["list"].getCurrent()
150 serviceref = self.currentService
152 cur = self["list"].getCurrent()
157 newEntry = RecordTimerEntry(serviceref, *parseEvent(event))
158 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
160 def timerEditFinished(self, answer):
162 self.session.nav.RecordTimer.record(answer[1])
164 print "Timeredit aborted"
167 self["list"].moveUp()
170 self["list"].moveDown()
172 def applyButtonState(self, state):
174 self["now_button_sel"].show()
175 self["now_button"].hide()
177 self["now_button"].show()
178 self["now_button_sel"].hide()
181 self["next_button_sel"].show()
182 self["next_button"].hide()
184 self["next_button"].show()
185 self["next_button_sel"].hide()
188 self["more_button_sel"].show()
189 self["more_button"].hide()
191 self["more_button"].show()
192 self["more_button_sel"].hide()
194 def onSelectionChanged(self):
195 if self.type == EPG_TYPE_MULTI:
196 count = self["list"].getCurrentChangeCount()
198 self.applyButtonState(3)
200 self.applyButtonState(2)
202 self.applyButtonState(1)
203 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
205 event = self["list"].getCurrent()[0]
206 if event is not None:
208 beg = event.getBeginTime()
209 nowTime = localtime(now)
210 begTime = localtime(beg)
211 if nowTime[2] != begTime[2]:
212 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
214 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
215 self["date"].setText(datestr)