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 if type == EPG_TYPE_SINGLE:
58 self.l.setBuildFunc(self.buildSingleEntry)
60 self.l.setBuildFunc(self.buildMultiEntry)
61 self.epgcache = eEPGCache.getInstance()
63 def getEventFromId(self, service, eventid):
65 if self.epgcache is not None and eventid is not None:
66 event = self.epgcache.lookupEventId(service.ref, eventid)
69 def getCurrentChangeCount(self):
70 if self.type == EPG_TYPE_SINGLE:
72 return self.l.getCurrentSelection()[0]
75 if self.type == EPG_TYPE_SINGLE:
77 evt = self.l.getCurrent()
79 eventid = self.l.getCurrentSelection()[0]
80 evt = self.getEventFromId(self.service, eventid)
82 tmp = self.l.getCurrentSelection()
84 service = ServiceReference(tmp[1])
85 event = self.getEventFromId(service, eventid)
86 evt = ( event, service )
90 self.instance.moveSelection(self.instance.moveUp)
93 self.instance.moveSelection(self.instance.moveDown)
95 def connectSelectionChanged(func):
96 if not self.onSelChanged.count(func):
97 self.onSelChanged.append(func)
99 def disconnectSelectionChanged(func):
100 self.onSelChanged.remove(func)
102 def selectionChanged(self):
103 for x in self.onSelChanged:
110 def GUIcreate(self, parent):
111 self.instance = eListbox(parent)
112 self.instance.setWrapAround(True)
113 self.instance.selectionChanged.get().append(self.selectionChanged)
114 self.instance.setContent(self.l)
116 self.instance.setItemHeight(25)
121 def recalcEntrySize(self):
123 esize = self.l.getItemSize()
124 self.l.setFont(0, gFont("Regular", 22))
125 self.l.setFont(1, gFont("Regular", 16))
126 width = esize.width()
127 height = esize.height()
128 if self.type == EPG_TYPE_SINGLE:
130 self.datetime_rect = Rect(0,0, w, height)
131 self.descr_rect = Rect(w, 0, width/20*15, height)
135 self.service_rect = Rect(xpos, 0, w-10, height)
138 self.start_end_rect = Rect(xpos, 0, w-10, height)
139 self.progress_rect = Rect(xpos, 4, w-10, height-8)
142 self.descr_rect = Rect(xpos, 0, width, height)
144 def buildSingleEntry(self, eventId, beginTime, duration, EventName):
145 rec=(self.timer.isInTimer(eventid=eventId, begin=beginTime, duration=duration, service=self.service) > ((duration/10)*8))
146 r1=self.datetime_rect
148 res = [ None ] # no private data needed
149 t = localtime(beginTime)
150 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])))
152 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r2.left(), r2.top(), 21, 21, loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, 'epgclock-fs8.png'))))
153 res.append((eListboxPythonMultiContent.TYPE_TEXT, r2.left() + 25, r2.top(), r2.width(), r2.height(), 0, RT_HALIGN_LEFT, EventName))
155 res.append((eListboxPythonMultiContent.TYPE_TEXT, r2.left(), r2.top(), r2.width(), r2.height(), 0, RT_HALIGN_LEFT, EventName))
158 def buildMultiEntry(self, changecount, service, eventId, begTime, duration, EventName, nowTime, service_name):
161 r2=self.progress_rect
163 r4=self.start_end_rect
164 res = [ None ] # no private data needed
165 re = compile('\xc2\x86.*?\xc2\x87')
166 list = re.findall(sname)
170 sname+=substr[2:len(substr)-2]
172 sname = service_name;
173 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, sname))
174 if begTime is not None:
175 if nowTime < begTime:
176 begin = localtime(begTime)
177 end = localtime(begTime+duration)
178 # print "begin", begin
180 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])));
181 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
183 percent = (nowTime - begTime) * 100 / duration
184 res.append((eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent));
185 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
188 def queryEPG(self, list, buildFunc=None):
189 if self.epgcache is not None:
190 if buildFunc is not None:
191 return self.epgcache.lookupEvent(list, buildFunc)
193 return self.epgcache.lookupEvent(list)
196 def fillMultiEPG(self, services):
198 test = [ '0RIBDTCN' ]
199 for service in services:
200 tuple = ( service.ref.toString(), 0 )
202 self.list = self.queryEPG(test)
203 self.l.setList(self.list)
205 self.selectionChanged()
207 def updateMultiEPG(self, direction):
216 test.append((service, direction, begTime))
217 tmp = self.queryEPG(test)
220 changecount = self.list[cnt][0] + direction
223 self.list[cnt]=(changecount, x[0], x[1], x[2], x[3], x[4], x[5], x[6])
225 self.l.setList(self.list)
227 self.selectionChanged()
229 def fillSingleEPG(self, service):
232 self.l.setRoot(service.ref)
234 self.service = service
235 test = [ 'IBDT', (service.ref.toString(), 0, -1, -1) ]
236 self.l.setList(self.queryEPG(test))
238 self.selectionChanged()