1 from HTMLComponent import *
2 from GUIComponent import *
6 from time import localtime, time
7 from ServiceReference import ServiceReference
8 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
28 def __init__(self, x, y, width, height):
32 self.__height = height
46 class EPGList(HTMLComponent, GUIComponent):
47 def __init__(self, type=EPG_TYPE_SINGLE, selChangedCB=None, timer = None):
49 self.onSelChanged = [ ]
50 if selChangedCB is not None:
51 self.onSelChanged.append(selChangedCB)
52 GUIComponent.__init__(self)
54 if type == EPG_TYPE_SINGLE and SINGLE_CPP > 0:
55 self.l = eListboxEPGContent()
57 self.l = eListboxPythonMultiContent()
58 if type == EPG_TYPE_SINGLE:
59 self.l.setBuildFunc(self.buildSingleEntry)
60 elif type == EPG_TYPE_MULTI:
61 self.l.setBuildFunc(self.buildMultiEntry)
63 assert(type == EPG_TYPE_SIMILAR)
64 self.l.setBuildFunc(self.buildSimilarEntry)
65 self.epgcache = eEPGCache.getInstance()
67 def getEventFromId(self, service, eventid):
69 if self.epgcache is not None and eventid is not None:
70 event = self.epgcache.lookupEventId(service.ref, eventid)
73 def getCurrentChangeCount(self):
74 if self.type == EPG_TYPE_SINGLE:
76 return self.l.getCurrentSelection()[0]
79 if self.type == EPG_TYPE_SINGLE:
81 evt = self.l.getCurrent()
83 cur = self.l.getCurrentSelection()
87 evt = self.getEventFromId(self.service, cur[0])
88 elif self.type == EPG_TYPE_MULTI:
89 tmp = self.l.getCurrentSelection()
93 service = ServiceReference(tmp[1])
94 event = self.getEventFromId(service, eventid)
95 evt = ( event, service )
97 tmp = self.l.getCurrentSelection()
101 service = ServiceReference(tmp[0])
102 event = self.getEventFromId(service, eventid)
103 evt = ( event, service )
107 self.instance.moveSelection(self.instance.moveUp)
110 self.instance.moveSelection(self.instance.moveDown)
112 def connectSelectionChanged(func):
113 if not self.onSelChanged.count(func):
114 self.onSelChanged.append(func)
116 def disconnectSelectionChanged(func):
117 self.onSelChanged.remove(func)
119 def selectionChanged(self):
120 for x in self.onSelChanged:
127 def GUIcreate(self, parent):
128 self.instance = eListbox(parent)
129 self.instance.setWrapAround(True)
130 self.instance.selectionChanged.get().append(self.selectionChanged)
131 self.instance.setContent(self.l)
133 self.instance.setItemHeight(25)
138 def recalcEntrySize(self):
140 esize = self.l.getItemSize()
141 self.l.setFont(0, gFont("Regular", 22))
142 self.l.setFont(1, gFont("Regular", 16))
143 width = esize.width()
144 height = esize.height()
145 if self.type == EPG_TYPE_SINGLE:
147 self.datetime_rect = Rect(0,0, w, height)
148 self.descr_rect = Rect(w, 0, width/20*15, height)
149 elif self.type == EPG_TYPE_MULTI:
152 self.service_rect = Rect(xpos, 0, w-10, height)
155 self.start_end_rect = Rect(xpos, 0, w-10, height)
156 self.progress_rect = Rect(xpos, 4, w-10, height-8)
159 self.descr_rect = Rect(xpos, 0, width, height)
160 else: # EPG_TYPE_SIMILAR
163 self.datetime_rect = Rect(xpos, 0, w-10, height)
166 self.service_rect = Rect(xpos, 0, w-10, height)
168 def buildSingleEntry(self, eventId, beginTime, duration, EventName):
169 rec=(self.timer.isInTimer(eventId, beginTime, duration, self.service) > ((duration/10)*8))
170 r1=self.datetime_rect
172 res = [ None ] # no private data needed
173 t = localtime(beginTime)
174 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, "%02d.%02d, %02d:%02d"%(t[2],t[1],t[3],t[4])))
176 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r2.left(), r2.top(), 21, 21, loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, 'epgclock-fs8.png'))))
177 res.append((eListboxPythonMultiContent.TYPE_TEXT, r2.left() + 25, r2.top(), r2.width(), r2.height(), 0, RT_HALIGN_LEFT, EventName))
179 res.append((eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r2.height(), 0, RT_HALIGN_LEFT, EventName))
182 def buildSimilarEntry(self, service, eventId, beginTime, service_name):
183 r1=self.datetime_rect
185 res = [ None ] # no private data needed
186 t = localtime(beginTime)
187 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, "%02d.%02d, %02d:%02d"%(t[2],t[1],t[3],t[4])))
188 res.append((eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r2.height(), 0, RT_HALIGN_LEFT, service_name))
191 def buildMultiEntry(self, changecount, service, eventId, begTime, duration, EventName, nowTime, service_name):
192 rec=begTime and (self.timer.isInTimer(eventId, begTime, duration, service) > ((duration/10)*8))
195 r2=self.progress_rect
197 r4=self.start_end_rect
198 res = [ None ] # no private data needed
199 re = compile('\xc2\x86.*?\xc2\x87')
200 list = re.findall(sname)
204 sname+=substr[2:len(substr)-2]
206 sname = service_name;
208 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-21, r1.height(), 0, RT_HALIGN_LEFT, sname))
209 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, 'epgclock-fs8.png'))))
211 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, sname))
212 if begTime is not None:
213 if nowTime < begTime:
214 begin = localtime(begTime)
215 end = localtime(begTime+duration)
216 # print "begin", begin
218 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])));
219 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
221 percent = (nowTime - begTime) * 100 / duration
222 res.append((eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent));
223 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
226 def queryEPG(self, list, buildFunc=None):
227 if self.epgcache is not None:
228 if buildFunc is not None:
229 return self.epgcache.lookupEvent(list, buildFunc)
231 return self.epgcache.lookupEvent(list)
234 def fillMultiEPG(self, services):
236 test = [ '0RIBDTCN' ]
237 for service in services:
238 tuple = ( service.ref.toString(), 0 )
240 self.list = self.queryEPG(test)
241 self.l.setList(self.list)
243 self.selectionChanged()
245 def updateMultiEPG(self, direction):
254 test.append((service, direction, begTime))
255 tmp = self.queryEPG(test)
258 changecount = self.list[cnt][0] + direction
261 self.list[cnt]=(changecount, x[0], x[1], x[2], x[3], x[4], x[5], x[6])
263 self.l.setList(self.list)
265 self.selectionChanged()
267 def fillSingleEPG(self, service):
270 self.l.setRoot(service.ref)
272 self.service = service
273 test = [ 'IBDT', (service.ref.toString(), 0, -1, -1) ]
274 self.l.setList(self.queryEPG(test))
276 self.selectionChanged()
278 def sort_func(self,x,y):
286 def fillSimilarList(self, refstr, event_id):
288 # search similar broadcastings
291 l = self.epgcache.search(('RIBN', 1024, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, event_id))
292 l.sort(self.sort_func)
294 self.selectionChanged()