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
26 def __init__(self, x, y, width, height):
30 self.__height = height
44 class EPGList(HTMLComponent, GUIComponent):
45 def __init__(self, type=EPG_TYPE_SINGLE, selChangedCB=None, timer = None):
46 self.days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
48 self.onSelChanged = [ ]
49 if selChangedCB is not None:
50 self.onSelChanged.append(selChangedCB)
51 GUIComponent.__init__(self)
53 self.l = eListboxPythonMultiContent()
54 if type == EPG_TYPE_SINGLE:
55 self.l.setBuildFunc(self.buildSingleEntry)
56 elif type == EPG_TYPE_MULTI:
57 self.l.setBuildFunc(self.buildMultiEntry)
59 assert(type == EPG_TYPE_SIMILAR)
60 self.l.setBuildFunc(self.buildSimilarEntry)
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_MULTI:
71 return self.l.getCurrentSelection()[0]
76 if self.type == EPG_TYPE_MULTI:
78 tmp = self.l.getCurrentSelection()
82 service = ServiceReference(tmp[idx])
83 event = self.getEventFromId(service, eventid)
84 return ( event, service )
87 self.instance.moveSelection(self.instance.moveUp)
90 self.instance.moveSelection(self.instance.moveDown)
92 def connectSelectionChanged(func):
93 if not self.onSelChanged.count(func):
94 self.onSelChanged.append(func)
96 def disconnectSelectionChanged(func):
97 self.onSelChanged.remove(func)
99 def selectionChanged(self):
100 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 recalcEntrySize(self):
116 esize = self.l.getItemSize()
117 self.l.setFont(0, gFont("Regular", 22))
118 self.l.setFont(1, gFont("Regular", 16))
119 width = esize.width()
120 height = esize.height()
121 if self.type == EPG_TYPE_SINGLE:
122 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
123 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
124 self.descr_rect = Rect(width/20*7, 0, width/20*13, height)
125 elif self.type == EPG_TYPE_MULTI:
128 self.service_rect = Rect(xpos, 0, w-10, height)
131 self.start_end_rect = Rect(xpos, 0, w-10, height)
132 self.progress_rect = Rect(xpos, 4, w-10, height-8)
135 self.descr_rect = Rect(xpos, 0, width, height)
136 else: # EPG_TYPE_SIMILAR
137 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
138 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
139 self.service_rect = Rect(width/20*7, 0, width/20*13, height)
141 def buildSingleEntry(self, service, eventId, beginTime, duration, EventName):
142 rec=(self.timer.isInTimer(eventId, beginTime, duration, service) > ((duration/10)*8))
144 r2=self.datetime_rect
146 res = [ None ] # no private data needed
147 t = localtime(beginTime)
148 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]))
149 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])))
151 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, 'epgclock-fs8.png'))))
152 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
154 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
157 def buildSimilarEntry(self, service, eventId, beginTime, service_name, duration):
158 rec=(self.timer.isInTimer(eventId, beginTime, duration, service) > ((duration/10)*8))
160 r2=self.datetime_rect
162 res = [ None ] # no private data needed
163 t = localtime(beginTime)
164 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]))
165 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])))
167 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, 'epgclock-fs8.png'))))
168 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
170 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
173 def buildMultiEntry(self, changecount, service, eventId, begTime, duration, EventName, nowTime, service_name):
174 rec=begTime and (self.timer.isInTimer(eventId, begTime, duration, service) > ((duration/10)*8))
177 r2=self.progress_rect
179 r4=self.start_end_rect
180 res = [ None ] # no private data needed
181 re = compile('\xc2\x86.*?\xc2\x87')
182 list = re.findall(sname)
186 sname+=substr[2:len(substr)-2]
188 sname = service_name;
190 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-21, r1.height(), 0, RT_HALIGN_LEFT, sname))
191 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, 'epgclock-fs8.png'))))
193 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, sname))
194 if begTime is not None:
195 if nowTime < begTime:
196 begin = localtime(begTime)
197 end = localtime(begTime+duration)
198 # print "begin", begin
200 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])));
201 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
203 percent = (nowTime - begTime) * 100 / duration
204 res.append((eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent));
205 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
208 def queryEPG(self, list, buildFunc=None):
209 if self.epgcache is not None:
210 if buildFunc is not None:
211 return self.epgcache.lookupEvent(list, buildFunc)
213 return self.epgcache.lookupEvent(list)
216 def fillMultiEPG(self, services, stime=-1):
218 test = [ '0RIBDTCN' ]
219 for service in services:
220 tuple = (service.ref.toString(), 0, stime)
222 self.list = self.queryEPG(test)
223 self.l.setList(self.list)
225 self.selectionChanged()
227 def updateMultiEPG(self, direction):
236 test.append((service, direction, begTime))
237 tmp = self.queryEPG(test)
240 changecount = self.list[cnt][0] + direction
243 self.list[cnt]=(changecount, x[0], x[1], x[2], x[3], x[4], x[5], x[6])
245 self.l.setList(self.list)
247 self.selectionChanged()
249 def fillSingleEPG(self, service):
251 test = [ 'RIBDT', (service.ref.toString(), 0, -1, -1) ]
252 self.l.setList(self.queryEPG(test))
254 self.selectionChanged()
256 def sort_func(self,x,y):
264 def fillSimilarList(self, refstr, event_id):
266 # search similar broadcastings
269 l = self.epgcache.search(('RIBND', 1024, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, event_id))
271 l.sort(self.sort_func)
273 self.selectionChanged()