1 from Screen import Screen
2 from Components.config import config, ConfigClock
3 from Components.Button import Button
4 from Components.Pixmap import Pixmap
5 from Components.Label import Label
6 from Components.EpgList import *
7 from Components.ActionMap import ActionMap
8 from Components.ScrollLabel import ScrollLabel
9 from Screens.EventView import EventViewSimple
10 from TimeDateInput import TimeDateInput
11 from enigma import eServiceReference
12 from Screens.FixedMenu import FixedMenu
13 from RecordTimer import RecordTimerEntry, parseEvent
14 from TimerEdit import TimerEditList
15 from TimerEntry import TimerEntry
16 from ServiceReference import ServiceReference
17 from time import localtime, time
19 import xml.dom.minidom
21 mepg_config_initialized = False
23 class EPGSelection(Screen):
24 def __init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None):
25 Screen.__init__(self, session)
26 self.bouquetChangeCB = bouquetChangeCB
27 self.ask_time = -1 #now
28 self["key_red"] = Button("")
29 self.closeRecursive = False
30 if isinstance(service, str) and eventid != None:
31 self.type = EPG_TYPE_SIMILAR
32 self["key_yellow"] = Button()
33 self["key_blue"] = Button()
34 self["key_red"] = Button()
35 self.currentService=service
36 self.eventid = eventid
38 elif isinstance(service, eServiceReference) or isinstance(service, str):
39 self.type = EPG_TYPE_SINGLE
40 self["key_yellow"] = Button()
41 self["key_blue"] = Button()
42 self.currentService=ServiceReference(service)
45 self.skinName = "EPGSelectionMulti"
46 self.type = EPG_TYPE_MULTI
47 self["key_yellow"] = Button(_("Prev"))
48 self["key_blue"] = Button(_("Next"))
49 self["now_button"] = Pixmap()
50 self["next_button"] = Pixmap()
51 self["more_button"] = Pixmap()
52 self["now_button_sel"] = Pixmap()
53 self["next_button_sel"] = Pixmap()
54 self["more_button_sel"] = Pixmap()
55 self["now_text"] = Label()
56 self["next_text"] = Label()
57 self["more_text"] = Label()
58 self["date"] = Label()
59 self.services = service
60 self.zapFunc = zapFunc
62 self["key_green"] = Button(_("Add timer"))
63 self["list"] = EPGList(type = self.type, selChangedCB = self.onSelectionChanged, timer = self.session.nav.RecordTimer)
65 class ChannelActionMap(ActionMap):
66 def action(self, contexts, action):
67 return ActionMap.action(self, contexts, action)
69 self["actions"] = ChannelActionMap(["EPGSelectActions", "OkCancelActions"],
71 "cancel": self.closeScreen,
72 "ok": self.eventSelected,
73 "timerAdd": self.timerAdd,
74 "yellow": self.yellowButtonPressed,
75 "blue": self.blueButtonPressed,
76 "info": self.infoKeyPressed,
78 "input_date_time": self.enterDateTime,
79 "nextBouquet": self.nextBouquet,
80 "prevBouquet": self.prevBouquet
82 self["actions"].csel = self
84 self.onLayoutFinish.append(self.onCreate)
86 def nextBouquet(self):
87 if self.bouquetChangeCB:
88 self.bouquetChangeCB(1, self)
90 def prevBouquet(self):
91 if self.bouquetChangeCB:
92 self.bouquetChangeCB(-1, self)
94 def enterDateTime(self):
95 if self.type == EPG_TYPE_MULTI:
96 global mepg_config_initialized
97 if not mepg_config_initialized:
98 config.misc.prev_mepg_time=ConfigClock(default = time())
99 mepg_config_initialized = True
100 self.session.openWithCallback(self.onDateTimeInputClosed, TimeDateInput, config.misc.prev_mepg_time )
102 def onDateTimeInputClosed(self, ret):
106 self["list"].fillMultiEPG(self.services, ret[1])
108 def closeScreen(self):
109 self.close(self.closeRecursive)
111 def infoKeyPressed(self):
112 cur = self["list"].getCurrent()
115 if event is not None:
116 if self.type != EPG_TYPE_SIMILAR:
117 self.session.open(EventViewSimple, event, service, self.eventViewCallback, self.openSimilarList)
119 self.session.open(EventViewSimple, event, service, self.eventViewCallback)
121 def openSimilarList(self, eventid, refstr):
122 self.session.open(EPGSelection, refstr, None, eventid)
124 def setServices(self, services):
125 self.services = services
128 #just used in multipeg
132 if self.type == EPG_TYPE_MULTI:
133 l.fillMultiEPG(self.services, self.ask_time)
134 elif self.type == EPG_TYPE_SINGLE:
135 l.fillSingleEPG(self.currentService)
137 l.fillSimilarList(self.currentService, self.eventid)
139 def eventViewCallback(self, setEvent, setService, val):
147 if self.type == EPG_TYPE_MULTI and cur[0] is None and cur[1].ref != old[1].ref:
148 self.eventViewCallback(setEvent, setService, val)
153 def zapTo(self): # just used in multiepg
154 if self.zapFunc and self["key_red"].getText() == "Zap":
156 count = lst.getCurrentChangeCount()
158 self.closeRecursive = True
159 ref = lst.getCurrent()[1]
160 self.zapFunc(ref.ref)
162 def eventSelected(self):
163 self.infoKeyPressed()
165 def yellowButtonPressed(self):
166 if self.type == EPG_TYPE_MULTI:
167 self["list"].updateMultiEPG(-1)
169 def blueButtonPressed(self):
170 if self.type == EPG_TYPE_MULTI:
171 self["list"].updateMultiEPG(1)
174 cur = self["list"].getCurrent()
179 newEntry = RecordTimerEntry(serviceref, checkOldTimers = True, *parseEvent(event))
180 self.session.openWithCallback(self.timerEditFinished, TimerEntry, newEntry)
182 def timerEditFinished(self, answer):
184 self.session.nav.RecordTimer.record(answer[1])
186 print "Timeredit aborted"
189 self["list"].moveUp()
192 self["list"].moveDown()
194 def applyButtonState(self, state):
196 self["now_button"].hide()
197 self["now_button_sel"].hide()
198 self["next_button"].hide()
199 self["next_button_sel"].hide()
200 self["more_button"].hide()
201 self["more_button_sel"].hide()
202 self["now_text"].hide()
203 self["next_text"].hide()
204 self["more_text"].hide()
205 self["key_red"].setText("")
208 self["key_red"].setText("Zap")
209 self["now_button_sel"].show()
210 self["now_button"].hide()
212 self["now_button"].show()
213 self["now_button_sel"].hide()
214 self["key_red"].setText("")
217 self["next_button_sel"].show()
218 self["next_button"].hide()
220 self["next_button"].show()
221 self["next_button_sel"].hide()
224 self["more_button_sel"].show()
225 self["more_button"].hide()
227 self["more_button"].show()
228 self["more_button_sel"].hide()
230 def onSelectionChanged(self):
231 if self.type == EPG_TYPE_MULTI:
232 count = self["list"].getCurrentChangeCount()
233 if self.ask_time != -1:
234 self.applyButtonState(0)
236 self.applyButtonState(3)
238 self.applyButtonState(2)
240 self.applyButtonState(1)
241 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
243 event = self["list"].getCurrent()[0]
244 if event is not None:
246 beg = event.getBeginTime()
247 nowTime = localtime(now)
248 begTime = localtime(beg)
249 if nowTime[2] != begTime[2]:
250 datestr = '%s %d.%d.'%(days[begTime[6]], begTime[2], begTime[1])
252 datestr = '%s %d.%d.'%(_("Today"), begTime[2], begTime[1])
253 self["date"].setText(datestr)