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()
53 def getEventFromId(self, service, eventid):
55 if self.epgcache is not None and eventid is not None:
56 event = self.epgcache.lookupEventId(service.ref, eventid)
59 def getCurrentChangeCount(self):
60 if self.type == EPG_TYPE_MULTI:
61 return self.l.getCurrentSelection()[0]
66 if self.type == EPG_TYPE_MULTI:
68 tmp = self.l.getCurrentSelection()
72 service = ServiceReference(tmp[idx])
73 event = self.getEventFromId(service, eventid)
74 return ( event, service )
77 self.instance.moveSelection(self.instance.moveUp)
80 self.instance.moveSelection(self.instance.moveDown)
82 def connectSelectionChanged(func):
83 if not self.onSelChanged.count(func):
84 self.onSelChanged.append(func)
86 def disconnectSelectionChanged(func):
87 self.onSelChanged.remove(func)
89 def selectionChanged(self):
90 for x in self.onSelChanged:
95 print "FIXME in EPGList.selectionChanged"
100 def postWidgetCreate(self, instance):
101 instance.setWrapAround(True)
102 instance.selectionChanged.get().append(self.selectionChanged)
103 instance.setContent(self.l)
105 def recalcEntrySize(self):
106 esize = self.l.getItemSize()
107 self.l.setFont(0, gFont("Regular", 22))
108 self.l.setFont(1, gFont("Regular", 16))
109 width = esize.width()
110 height = esize.height()
111 if self.type == EPG_TYPE_SINGLE:
112 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
113 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
114 self.descr_rect = Rect(width/20*7, 0, width/20*13, height)
115 elif self.type == EPG_TYPE_MULTI:
118 self.service_rect = Rect(xpos, 0, w-10, height)
121 self.start_end_rect = Rect(xpos, 0, w-10, height)
122 self.progress_rect = Rect(xpos, 4, w-10, height-8)
125 self.descr_rect = Rect(xpos, 0, width, height)
126 else: # EPG_TYPE_SIMILAR
127 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
128 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
129 self.service_rect = Rect(width/20*7, 0, width/20*13, height)
131 def buildSingleEntry(self, service, eventId, beginTime, duration, EventName):
132 rec=(self.timer.isInTimer(eventId, beginTime, duration, service) > ((duration/10)*8))
134 r2=self.datetime_rect
136 res = [ None ] # no private data needed
137 t = localtime(beginTime)
138 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]))
139 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])))
141 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, 'epgclock-fs8.png'))))
142 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
144 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
147 def buildSimilarEntry(self, service, eventId, beginTime, service_name, duration):
148 rec=(self.timer.isInTimer(eventId, beginTime, duration, service) > ((duration/10)*8))
150 r2=self.datetime_rect
152 res = [ None ] # no private data needed
153 t = localtime(beginTime)
154 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]))
155 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])))
157 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, 'epgclock-fs8.png'))))
158 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
160 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
163 def buildMultiEntry(self, changecount, service, eventId, begTime, duration, EventName, nowTime, service_name):
164 rec=begTime and (self.timer.isInTimer(eventId, begTime, duration, service) > ((duration/10)*8))
166 r2=self.progress_rect
168 r4=self.start_end_rect
169 res = [ None ] # no private data needed
171 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-21, r1.height(), 0, RT_HALIGN_LEFT, service_name))
172 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, loadPNG(resolveFilename(SCOPE_SKIN_IMAGE, 'epgclock-fs8.png'))))
174 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, service_name))
175 if begTime is not None:
176 if nowTime < begTime:
177 begin = localtime(begTime)
178 end = localtime(begTime+duration)
179 # print "begin", begin
181 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])));
182 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
184 percent = (nowTime - begTime) * 100 / duration
185 res.append((eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent));
186 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
189 def queryEPG(self, list, buildFunc=None):
190 if self.epgcache is not None:
191 if buildFunc is not None:
192 return self.epgcache.lookupEvent(list, buildFunc)
194 return self.epgcache.lookupEvent(list)
197 def fillMultiEPG(self, services, stime=-1):
199 test = [ (service.ref.toString(), 0, stime) for service in services ]
200 test.insert(0, '0RIBDTCn')
201 self.list = self.queryEPG(test)
202 self.l.setList(self.list)
204 self.selectionChanged()
206 def updateMultiEPG(self, direction):
208 test = [ x[3] and (x[1], direction, x[3]) or (x[1], direction, 0) for x in self.list ]
209 test.insert(0, 'RIBDTCn')
210 tmp = self.queryEPG(test)
213 changecount = self.list[cnt][0] + direction
216 self.list[cnt]=(changecount, x[0], x[1], x[2], x[3], x[4], x[5], x[6])
218 self.l.setList(self.list)
220 self.selectionChanged()
222 def fillSingleEPG(self, service):
224 test = [ 'RIBDT', (service.ref.toString(), 0, -1, -1) ]
225 self.l.setList(self.queryEPG(test))
227 self.selectionChanged()
229 def sort_func(self,x,y):
237 def fillSimilarList(self, refstr, event_id):
239 # search similar broadcastings
242 l = self.epgcache.search(('RIBND', 1024, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, event_id))
244 l.sort(self.sort_func)
246 self.selectionChanged()