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
27 def __init__(self, x, y, width, height):
31 self.__height = height
45 class EPGList(HTMLComponent, GUIComponent):
46 def __init__(self, type=EPG_TYPE_SINGLE, selChangedCB=None, timer = None):
48 self.onSelChanged = [ ]
49 if selChangedCB is not None:
50 self.onSelChanged.append(selChangedCB)
51 GUIComponent.__init__(self)
53 if type == EPG_TYPE_SINGLE and SINGLE_CPP > 0:
54 self.l = eListboxEPGContent()
56 self.l = eListboxPythonMultiContent()
57 self.epgcache = eEPGCache.getInstance()
59 def getEventFromId(self, service, eventid):
61 if self.epgcache is not None and eventid is not None:
62 event = self.epgcache.lookupEventId(service.ref, eventid)
65 def getCurrentChangeCount(self):
66 if self.type == EPG_TYPE_SINGLE:
68 return self.l.getCurrentSelection()[0][0]
71 if self.type == EPG_TYPE_SINGLE:
73 evt = self.l.getCurrent()
75 eventid = self.l.getCurrentSelection()[0]
76 evt = self.getEventFromId(self.service, eventid)
78 tmp = self.l.getCurrentSelection()[0]
80 service = ServiceReference(tmp[2])
81 event = self.getEventFromId(service, eventid)
82 evt = ( 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:
106 def GUIcreate(self, parent):
107 self.instance = eListbox(parent)
108 self.instance.setWrapAround(True)
109 self.instance.selectionChanged.get().append(self.selectionChanged)
110 self.instance.setContent(self.l)
112 self.instance.setItemHeight(25)
117 def recalcEntrySize(self):
119 esize = self.l.getItemSize()
120 self.l.setFont(0, gFont("Regular", 22))
121 self.l.setFont(1, gFont("Regular", 16))
122 width = esize.width()
123 height = esize.height()
124 if self.type == EPG_TYPE_SINGLE:
126 self.datetime_rect = Rect(0,0, w, height)
127 self.descr_rect = Rect(w, 0, width/20*15, height)
131 self.service_rect = Rect(xpos, 0, w-10, height)
134 self.start_end_rect = Rect(xpos, 0, w-10, height)
135 self.progress_rect = Rect(xpos, 4, w-10, height-8)
138 self.descr_rect = Rect(xpos, 0, width, height)
140 def buildSingleEntry(self, eventId, beginTime, duration, EventName, rec=False):
141 r1=self.datetime_rect
144 t = localtime(beginTime)
145 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])))
147 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r2.left(), r2.top(), 21, 21, loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, 'epgclock-fs8.png'))))
148 res.append((eListboxPythonMultiContent.TYPE_TEXT, r2.left() + 25, r2.top(), r2.width(), r2.height(), 0, RT_HALIGN_LEFT, EventName))
150 res.append((eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r2.height(), 0, RT_HALIGN_LEFT, EventName))
153 def buildMultiEntry(self, changecount, service, eventId, begTime, duration, EventName, nowTime, service_name):
156 r2=self.progress_rect
158 r4=self.start_end_rect
159 res = [ (changecount, eventId, service, begTime, duration) ]
160 re = compile('\xc2\x86.*?\xc2\x87')
161 list = re.findall(sname)
165 sname+=substr[2:len(substr)-2]
167 sname = service_name;
168 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, sname))
169 if begTime is not None:
170 if nowTime < begTime:
171 begin = localtime(begTime)
172 end = localtime(begTime+duration)
173 # print "begin", begin
175 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])));
176 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
178 percent = (nowTime - begTime) * 100 / duration
179 res.append((eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent));
180 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
183 def queryEPG(self, list, buildFunc=None):
184 if self.epgcache is not None:
185 if buildFunc is not None:
186 return self.epgcache.lookupEvent(list, buildFunc)
188 return self.epgcache.lookupEvent(list)
191 def fillMultiEPG(self, services):
194 for service in services:
195 tuple = ( service.ref.toString(), 0 )
197 # self.list = self.queryEPG(test, self.buildMultiEntry)
198 tmp = self.queryEPG(test)
201 self.list.append(self.buildMultiEntry(0, x[0], x[1], x[2], x[3], x[4], x[5], x[6]))
202 self.l.setList(self.list)
204 self.selectionChanged()
206 def updateMultiEPG(self, direction):
216 test.append((service, direction, begTime))
217 # self.list = self.queryEPG(test, self.buildMultiEntry)
218 tmp = self.queryEPG(test)
221 changecount = self.list[cnt][0][0] + direction
224 self.list[cnt]=self.buildMultiEntry(changecount, x[0], x[1], x[2], x[3], x[4], x[5], x[6])
226 self.l.setList(self.list)
228 self.selectionChanged()
230 def fillSingleEPG(self, service):
233 self.l.setRoot(service.ref)
235 self.service = service
236 test = [ 'IBDT', (service.ref.toString(), 0, -1, -1) ]
237 # self.list = self.queryEPG(test, self.buildSingleEntry)
238 tmp = self.queryEPG(test)
241 self.list.append(self.buildSingleEntry(x[0], x[1], x[2], x[3], (self.timer.isInTimer(eventid=x[0], begin=x[1], duration=x[2], service=service) > 0)))
242 # self.list.append(self.buildSingleEntry(refstr, x[0], x[1], x[2], x[3]))
243 self.l.setList(self.list)
245 self.selectionChanged()