1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
4 from enigma import eEPGCache, eListbox, eListboxPythonMultiContent, gFont, \
5 RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_HALIGN_CENTER, RT_VALIGN_CENTER
7 from Tools.LoadPixmap import LoadPixmap
9 from time import localtime, time
10 from ServiceReference import ServiceReference
11 from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN
19 def __init__(self, x, y, width, height):
23 self.__height = height
37 class EPGList(HTMLComponent, GUIComponent):
38 def __init__(self, type=EPG_TYPE_SINGLE, selChangedCB=None, timer = None):
39 self.days = (_("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun"))
41 self.onSelChanged = [ ]
42 if selChangedCB is not None:
43 self.onSelChanged.append(selChangedCB)
44 GUIComponent.__init__(self)
46 self.l = eListboxPythonMultiContent()
47 font = skin.fonts.get("EPGList0", ("Regular", 22))
48 self.l.setFont(0, gFont(font[0], font[1]))
49 font = skin.fonts.get("EPGList1", ("Regular", 16))
50 self.l.setFont(1, gFont(font[0], font[1]))
51 if type == EPG_TYPE_SINGLE:
52 self.l.setBuildFunc(self.buildSingleEntry)
53 elif type == EPG_TYPE_MULTI:
54 self.l.setBuildFunc(self.buildMultiEntry)
56 assert(type == EPG_TYPE_SIMILAR)
57 self.l.setBuildFunc(self.buildSimilarEntry)
58 self.epgcache = eEPGCache.getInstance()
59 self.clock_pixmap = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'skin_default/icons/epgclock.png'))
60 self.clock_add_pixmap = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'skin_default/icons/epgclock_add.png'))
61 self.clock_pre_pixmap = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'skin_default/icons/epgclock_pre.png'))
62 self.clock_post_pixmap = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'skin_default/icons/epgclock_post.png'))
63 self.clock_prepost_pixmap = LoadPixmap(cached=True, path=resolveFilename(SCOPE_CURRENT_SKIN, 'skin_default/icons/epgclock_prepost.png'))
65 def getEventFromId(self, service, eventid):
67 if self.epgcache is not None and eventid is not None:
68 event = self.epgcache.lookupEventId(service.ref, eventid)
71 def getCurrentChangeCount(self):
72 if self.type == EPG_TYPE_MULTI and self.l.getCurrentSelection() is not None:
73 return self.l.getCurrentSelection()[0]
78 if self.type == EPG_TYPE_MULTI:
80 tmp = self.l.getCurrentSelection()
84 service = ServiceReference(tmp[idx])
85 event = self.getEventFromId(service, eventid)
86 return ( event, service )
89 self.instance.moveSelection(self.instance.moveUp)
92 self.instance.moveSelection(self.instance.moveDown)
94 def connectSelectionChanged(func):
95 if not self.onSelChanged.count(func):
96 self.onSelChanged.append(func)
98 def disconnectSelectionChanged(func):
99 self.onSelChanged.remove(func)
101 def selectionChanged(self):
102 for x in self.onSelChanged:
108 # print "FIXME in EPGList.selectionChanged"
111 GUI_WIDGET = eListbox
113 def postWidgetCreate(self, instance):
114 instance.setWrapAround(True)
115 instance.selectionChanged.get().append(self.selectionChanged)
116 instance.setContent(self.l)
118 def preWidgetRemove(self, instance):
119 instance.selectionChanged.get().remove(self.selectionChanged)
120 instance.setContent(None)
122 def recalcEntrySize(self):
123 esize = self.l.getItemSize()
124 width = esize.width()
125 height = esize.height()
126 if self.type == EPG_TYPE_SINGLE:
127 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
128 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
129 self.descr_rect = Rect(width/20*7, 0, width/20*13, height)
130 elif self.type == EPG_TYPE_MULTI:
133 self.service_rect = Rect(xpos, 0, w-10, height)
136 self.start_end_rect = Rect(xpos, 0, w-10, height)
137 self.progress_rect = Rect(xpos, 4, w-10, height-8)
140 self.descr_rect = Rect(xpos, 0, width, height)
141 else: # EPG_TYPE_SIMILAR
142 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
143 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
144 self.service_rect = Rect(width/20*7, 0, width/20*13, height)
146 def getClockPixmap(self, refstr, beginTime, duration, eventId):
150 endTime = beginTime + duration
151 for x in self.timer.timer_list:
152 if x.service_ref.ref.toString() == refstr:
154 return self.clock_pixmap
157 if beginTime > beg and beginTime < end and endTime > end:
158 clock_type |= pre_clock
159 elif beginTime < beg and endTime > beg and endTime < end:
160 clock_type |= post_clock
162 return self.clock_add_pixmap
163 elif clock_type == pre_clock:
164 return self.clock_pre_pixmap
165 elif clock_type == post_clock:
166 return self.clock_post_pixmap
168 return self.clock_prepost_pixmap
170 def getPixmapForEntry(self, service, eventId, beginTime, duration):
171 rec=beginTime and (self.timer.isInTimer(eventId, beginTime, duration, service))
173 clock_pic = self.getClockPixmap(service, beginTime, duration, eventId)
176 return (clock_pic, rec)
178 def buildSingleEntry(self, service, eventId, beginTime, duration, EventName):
179 (clock_pic, rec) = self.getPixmapForEntry(service, eventId, beginTime, duration)
181 r2=self.datetime_rect
183 t = localtime(beginTime)
185 None, # no private data needed
186 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]),
187 (eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r1.height(), 0, RT_HALIGN_RIGHT, "%02d.%02d, %02d:%02d"%(t[2],t[1],t[3],t[4]))
191 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
192 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)
195 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
198 def buildSimilarEntry(self, service, eventId, beginTime, service_name, duration):
199 (clock_pic, rec) = self.getPixmapForEntry(service, eventId, beginTime, duration)
201 r2=self.datetime_rect
203 t = localtime(beginTime)
205 None, # no private data needed
206 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]),
207 (eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r1.height(), 0, RT_HALIGN_RIGHT, "%02d.%02d, %02d:%02d"%(t[2],t[1],t[3],t[4]))
211 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
212 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name)
215 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
218 def buildMultiEntry(self, changecount, service, eventId, beginTime, duration, EventName, nowTime, service_name):
219 (clock_pic, rec) = self.getPixmapForEntry(service, eventId, beginTime, duration)
221 r2=self.progress_rect
223 r4=self.start_end_rect
224 res = [ None ] # no private data needed
227 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-21, r1.height(), 0, RT_HALIGN_LEFT, service_name),
228 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, clock_pic)
231 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, service_name))
232 if beginTime is not None:
233 if nowTime < beginTime:
234 begin = localtime(beginTime)
235 end = localtime(beginTime+duration)
236 # print "begin", begin
239 (eListboxPythonMultiContent.TYPE_TEXT, r4.left(), r4.top(), r4.width(), r4.height(), 1, RT_HALIGN_CENTER|RT_VALIGN_CENTER, "%02d.%02d - %02d.%02d"%(begin[3],begin[4],end[3],end[4])),
240 (eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)
243 percent = (nowTime - beginTime) * 100 / duration
245 (eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent),
246 (eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)
250 def queryEPG(self, list, buildFunc=None):
251 if self.epgcache is not None:
252 if buildFunc is not None:
253 return self.epgcache.lookupEvent(list, buildFunc)
255 return self.epgcache.lookupEvent(list)
258 def fillMultiEPG(self, services, stime=-1):
260 test = [ (service.ref.toString(), 0, stime) for service in services ]
261 test.insert(0, 'X0RIBDTCn')
262 self.list = self.queryEPG(test)
263 self.l.setList(self.list)
265 self.selectionChanged()
267 def updateMultiEPG(self, direction):
269 test = [ x[3] and (x[1], direction, x[3]) or (x[1], direction, 0) for x in self.list ]
270 test.insert(0, 'XRIBDTCn')
271 tmp = self.queryEPG(test)
274 changecount = self.list[cnt][0] + direction
277 self.list[cnt]=(changecount, x[0], x[1], x[2], x[3], x[4], x[5], x[6])
279 self.l.setList(self.list)
281 self.selectionChanged()
283 def fillSingleEPG(self, service):
285 test = [ 'RIBDT', (service.ref.toString(), 0, -1, -1) ]
286 self.list = self.queryEPG(test)
287 self.l.setList(self.list)
289 self.selectionChanged()
291 def sortSingleEPG(self, type):
294 event_id = self.getSelectedEventId()
296 list.sort(key=lambda x: (x[4] and x[4].lower(), x[2]))
299 list.sort(key=lambda x: x[2])
301 self.moveToEventId(event_id)
303 def getSelectedEventId(self):
304 x = self.l.getCurrentSelection()
307 def moveToService(self,serviceref):
311 refstr = serviceref.toString()
314 self.instance.moveSelectionTo(index)
318 def moveToEventId(self, eventId):
324 self.instance.moveSelectionTo(index)
328 def fillSimilarList(self, refstr, event_id):
330 # search similar broadcastings
333 l = self.epgcache.search(('RIBND', 1024, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, event_id))
335 l.sort(key=lambda x: x[2])
337 self.selectionChanged()