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_SKIN_IMAGE
18 def __init__(self, x, y, width, height):
22 self.__height = height
36 class EPGList(HTMLComponent, GUIComponent):
37 def __init__(self, type=EPG_TYPE_SINGLE, selChangedCB=None, timer = None):
38 self.days = (_("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun"))
40 self.onSelChanged = [ ]
41 if selChangedCB is not None:
42 self.onSelChanged.append(selChangedCB)
43 GUIComponent.__init__(self)
45 self.l = eListboxPythonMultiContent()
46 self.l.setFont(0, gFont("Regular", 22))
47 self.l.setFont(1, gFont("Regular", 16))
48 if type == EPG_TYPE_SINGLE:
49 self.l.setBuildFunc(self.buildSingleEntry)
50 elif type == EPG_TYPE_MULTI:
51 self.l.setBuildFunc(self.buildMultiEntry)
53 assert(type == EPG_TYPE_SIMILAR)
54 self.l.setBuildFunc(self.buildSimilarEntry)
55 self.epgcache = eEPGCache.getInstance()
56 self.clock_pixmap = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/icons/epgclock.png'))
57 self.clock_add_pixmap = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/icons/epgclock_add.png'))
58 self.clock_pre_pixmap = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/icons/epgclock_pre.png'))
59 self.clock_post_pixmap = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/icons/epgclock_post.png'))
60 self.clock_prepost_pixmap = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, 'skin_default/icons/epgclock_prepost.png'))
62 def getEventFromId(self, service, eventid):
64 if self.epgcache is not None and eventid is not None:
65 event = self.epgcache.lookupEventId(service.ref, eventid)
68 def getCurrentChangeCount(self):
69 if self.type == EPG_TYPE_MULTI and self.l.getCurrentSelection() is not None:
70 return self.l.getCurrentSelection()[0]
75 if self.type == EPG_TYPE_MULTI:
77 tmp = self.l.getCurrentSelection()
81 service = ServiceReference(tmp[idx])
82 event = self.getEventFromId(service, eventid)
83 return ( event, service )
86 self.instance.moveSelection(self.instance.moveUp)
89 self.instance.moveSelection(self.instance.moveDown)
91 def connectSelectionChanged(func):
92 if not self.onSelChanged.count(func):
93 self.onSelChanged.append(func)
95 def disconnectSelectionChanged(func):
96 self.onSelChanged.remove(func)
98 def selectionChanged(self):
99 for x in self.onSelChanged:
105 # print "FIXME in EPGList.selectionChanged"
108 GUI_WIDGET = eListbox
110 def postWidgetCreate(self, instance):
111 instance.setWrapAround(True)
112 instance.selectionChanged.get().append(self.selectionChanged)
113 instance.setContent(self.l)
115 def preWidgetRemove(self, instance):
116 instance.selectionChanged.get().remove(self.selectionChanged)
117 instance.setContent(None)
119 def recalcEntrySize(self):
120 esize = self.l.getItemSize()
121 width = esize.width()
122 height = esize.height()
123 if self.type == EPG_TYPE_SINGLE:
124 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
125 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
126 self.descr_rect = Rect(width/20*7, 0, width/20*13, height)
127 elif self.type == EPG_TYPE_MULTI:
130 self.service_rect = Rect(xpos, 0, w-10, height)
133 self.start_end_rect = Rect(xpos, 0, w-10, height)
134 self.progress_rect = Rect(xpos, 4, w-10, height-8)
137 self.descr_rect = Rect(xpos, 0, width, height)
138 else: # EPG_TYPE_SIMILAR
139 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
140 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
141 self.service_rect = Rect(width/20*7, 0, width/20*13, height)
143 def getClockPixmap(self, refstr, beginTime, duration, eventId):
147 endTime = beginTime + duration
148 for x in self.timer.timer_list:
149 if x.service_ref.ref.toString() == refstr:
151 return self.clock_pixmap
154 if beginTime > beg and beginTime < end and endTime > end:
155 clock_type |= pre_clock
156 elif beginTime < beg and endTime > beg and endTime < end:
157 clock_type |= post_clock
159 return self.clock_add_pixmap
160 elif clock_type == pre_clock:
161 return self.clock_pre_pixmap
162 elif clock_type == post_clock:
163 return self.clock_post_pixmap
165 return self.clock_prepost_pixmap
167 def getPixmapForEntry(self, service, eventId, beginTime, duration):
168 rec=beginTime and (self.timer.isInTimer(eventId, beginTime, duration, service))
170 clock_pic = self.getClockPixmap(service, beginTime, duration, eventId)
173 return (clock_pic, rec)
175 def buildSingleEntry(self, service, eventId, beginTime, duration, EventName):
176 (clock_pic, rec) = self.getPixmapForEntry(service, eventId, beginTime, duration)
178 r2=self.datetime_rect
180 t = localtime(beginTime)
182 None, # no private data needed
183 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]),
184 (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]))
188 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
189 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)
192 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
195 def buildSimilarEntry(self, service, eventId, beginTime, service_name, duration):
196 (clock_pic, rec) = self.getPixmapForEntry(service, eventId, beginTime, duration)
198 r2=self.datetime_rect
200 t = localtime(beginTime)
202 None, # no private data needed
203 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]),
204 (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]))
208 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, clock_pic),
209 (eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name)
212 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
215 def buildMultiEntry(self, changecount, service, eventId, beginTime, duration, EventName, nowTime, service_name):
216 (clock_pic, rec) = self.getPixmapForEntry(service, eventId, beginTime, duration)
218 r2=self.progress_rect
220 r4=self.start_end_rect
221 res = [ None ] # no private data needed
224 (eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-21, r1.height(), 0, RT_HALIGN_LEFT, service_name),
225 (eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, clock_pic)
228 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, service_name))
229 if beginTime is not None:
230 if nowTime < beginTime:
231 begin = localtime(beginTime)
232 end = localtime(beginTime+duration)
233 # print "begin", begin
236 (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])),
237 (eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)
240 percent = (nowTime - beginTime) * 100 / duration
242 (eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent),
243 (eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName)
247 def queryEPG(self, list, buildFunc=None):
248 if self.epgcache is not None:
249 if buildFunc is not None:
250 return self.epgcache.lookupEvent(list, buildFunc)
252 return self.epgcache.lookupEvent(list)
255 def fillMultiEPG(self, services, stime=-1):
257 test = [ (service.ref.toString(), 0, stime) for service in services ]
258 test.insert(0, 'X0RIBDTCn')
259 self.list = self.queryEPG(test)
260 self.l.setList(self.list)
262 self.selectionChanged()
264 def updateMultiEPG(self, direction):
266 test = [ x[3] and (x[1], direction, x[3]) or (x[1], direction, 0) for x in self.list ]
267 test.insert(0, 'XRIBDTCn')
268 tmp = self.queryEPG(test)
271 changecount = self.list[cnt][0] + direction
274 self.list[cnt]=(changecount, x[0], x[1], x[2], x[3], x[4], x[5], x[6])
276 self.l.setList(self.list)
278 self.selectionChanged()
280 def fillSingleEPG(self, service):
282 test = [ 'RIBDT', (service.ref.toString(), 0, -1, -1) ]
283 self.list = self.queryEPG(test)
284 self.l.setList(self.list)
286 self.selectionChanged()
288 def sortSingleEPG(self, type):
291 event_id = self.getSelectedEventId()
293 list.sort(key=lambda x: (x[4] and x[4].lower(), x[2]))
296 list.sort(key=lambda x: x[2])
298 self.moveToEventId(event_id)
300 def getSelectedEventId(self):
301 x = self.l.getCurrentSelection()
304 def moveToService(self,serviceref):
308 refstr = serviceref.toString()
311 self.instance.moveSelectionTo(index)
315 def moveToEventId(self, eventId):
321 self.instance.moveSelectionTo(index)
325 def fillSimilarList(self, refstr, event_id):
327 # search similar broadcastings
330 l = self.epgcache.search(('RIBND', 1024, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, event_id))
332 l.sort(key=lambda x: x[2])
334 self.selectionChanged()