1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
4 from enigma import eEPGCache, eListbox, eListboxPythonMultiContent, gFont, loadPNG, \
5 RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_HALIGN_CENTER, RT_VALIGN_CENTER
7 from time import localtime, time
8 from ServiceReference import ServiceReference
9 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
16 def __init__(self, x, y, width, height):
20 self.__height = height
34 class EPGList(HTMLComponent, GUIComponent):
35 def __init__(self, type=EPG_TYPE_SINGLE, selChangedCB=None, timer = None):
36 self.days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
38 self.onSelChanged = [ ]
39 if selChangedCB is not None:
40 self.onSelChanged.append(selChangedCB)
41 GUIComponent.__init__(self)
43 self.l = eListboxPythonMultiContent()
44 if type == EPG_TYPE_SINGLE:
45 self.l.setBuildFunc(self.buildSingleEntry)
46 elif type == EPG_TYPE_MULTI:
47 self.l.setBuildFunc(self.buildMultiEntry)
49 assert(type == EPG_TYPE_SIMILAR)
50 self.l.setBuildFunc(self.buildSimilarEntry)
51 self.epgcache = eEPGCache.getInstance()
52 self.clock_pixmap = loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, 'epgclock-fs8.png'))
54 def getEventFromId(self, service, eventid):
56 if self.epgcache is not None and eventid is not None:
57 event = self.epgcache.lookupEventId(service.ref, eventid)
60 def getCurrentChangeCount(self):
61 if self.type == EPG_TYPE_MULTI:
62 return self.l.getCurrentSelection()[0]
67 if self.type == EPG_TYPE_MULTI:
69 tmp = self.l.getCurrentSelection()
73 service = ServiceReference(tmp[idx])
74 event = self.getEventFromId(service, eventid)
75 return ( event, service )
78 self.instance.moveSelection(self.instance.moveUp)
81 self.instance.moveSelection(self.instance.moveDown)
83 def connectSelectionChanged(func):
84 if not self.onSelChanged.count(func):
85 self.onSelChanged.append(func)
87 def disconnectSelectionChanged(func):
88 self.onSelChanged.remove(func)
90 def selectionChanged(self):
91 for x in self.onSelChanged:
96 print "FIXME in EPGList.selectionChanged"
101 def postWidgetCreate(self, instance):
102 instance.setWrapAround(True)
103 instance.selectionChanged.get().append(self.selectionChanged)
104 instance.setContent(self.l)
106 def recalcEntrySize(self):
107 esize = self.l.getItemSize()
108 self.l.setFont(0, gFont("Regular", 22))
109 self.l.setFont(1, gFont("Regular", 16))
110 width = esize.width()
111 height = esize.height()
112 if self.type == EPG_TYPE_SINGLE:
113 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
114 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
115 self.descr_rect = Rect(width/20*7, 0, width/20*13, height)
116 elif self.type == EPG_TYPE_MULTI:
119 self.service_rect = Rect(xpos, 0, w-10, height)
122 self.start_end_rect = Rect(xpos, 0, w-10, height)
123 self.progress_rect = Rect(xpos, 4, w-10, height-8)
126 self.descr_rect = Rect(xpos, 0, width, height)
127 else: # EPG_TYPE_SIMILAR
128 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
129 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
130 self.service_rect = Rect(width/20*7, 0, width/20*13, height)
132 def buildSingleEntry(self, service, eventId, beginTime, duration, EventName):
133 rec=(self.timer.isInTimer(eventId, beginTime, duration, service) > ((duration/10)*8))
135 r2=self.datetime_rect
137 res = [ None ] # no private data needed
138 t = localtime(beginTime)
139 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]))
140 res.append((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])))
142 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, self.clock_pixmap))
143 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
145 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
148 def buildSimilarEntry(self, service, eventId, beginTime, service_name, duration):
149 rec=(self.timer.isInTimer(eventId, beginTime, duration, service) > ((duration/10)*8))
151 r2=self.datetime_rect
153 res = [ None ] # no private data needed
154 t = localtime(beginTime)
155 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]))
156 res.append((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])))
158 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, self.clock_pixmap))
159 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
161 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
164 def buildMultiEntry(self, changecount, service, eventId, begTime, duration, EventName, nowTime, service_name):
165 rec=begTime and (self.timer.isInTimer(eventId, begTime, duration, service) > ((duration/10)*8))
167 r2=self.progress_rect
169 r4=self.start_end_rect
170 res = [ None ] # no private data needed
172 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-21, r1.height(), 0, RT_HALIGN_LEFT, service_name))
173 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, self.clock_pixmap))
175 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, service_name))
176 if begTime is not None:
177 if nowTime < begTime:
178 begin = localtime(begTime)
179 end = localtime(begTime+duration)
180 # print "begin", begin
182 res.append((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])));
183 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
185 percent = (nowTime - begTime) * 100 / duration
186 res.append((eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent));
187 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
190 def queryEPG(self, list, buildFunc=None):
191 if self.epgcache is not None:
192 if buildFunc is not None:
193 return self.epgcache.lookupEvent(list, buildFunc)
195 return self.epgcache.lookupEvent(list)
198 def fillMultiEPG(self, services, stime=-1):
200 test = [ (service.ref.toString(), 0, stime) for service in services ]
201 test.insert(0, '0RIBDTCn')
202 self.list = self.queryEPG(test)
203 self.l.setList(self.list)
205 self.selectionChanged()
207 def updateMultiEPG(self, direction):
209 test = [ x[3] and (x[1], direction, x[3]) or (x[1], direction, 0) for x in self.list ]
210 test.insert(0, 'RIBDTCn')
211 tmp = self.queryEPG(test)
214 changecount = self.list[cnt][0] + direction
217 self.list[cnt]=(changecount, x[0], x[1], x[2], x[3], x[4], x[5], x[6])
219 self.l.setList(self.list)
221 self.selectionChanged()
223 def fillSingleEPG(self, service):
225 test = [ 'RIBDT', (service.ref.toString(), 0, -1, -1) ]
226 self.list = self.queryEPG(test)
227 self.l.setList(self.list)
229 self.selectionChanged()
231 def sortSingleEPG(self, type):
234 self.list.sort(key=lambda x: (x[4].lower(), x[2]))
235 self.l.setList(self.list)
236 self.selectionChanged()
239 self.list.sort(key=lambda x: x[2])
240 self.l.setList(self.list)
241 self.selectionChanged()
243 def fillSimilarList(self, refstr, event_id):
245 # search similar broadcastings
248 l = self.epgcache.search(('RIBND', 1024, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, event_id))
250 l.sort(self.sort_func)
252 self.selectionChanged()