1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
4 from enigma import eEPGCache, eListbox, eListboxPythonMultiContent, gFont, \
5 RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_HALIGN_CENTER, RT_VALIGN_CENTER
7 from Tools.LoadPixmap import LoadPixmap
9 from time import localtime, time
10 from ServiceReference import ServiceReference
11 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
18 def __init__(self, x, y, width, height):
22 self.__height = height
36 class EPGList(HTMLComponent, GUIComponent):
37 def __init__(self, type=EPG_TYPE_SINGLE, selChangedCB=None, timer = None):
38 self.days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
40 self.onSelChanged = [ ]
41 if selChangedCB is not None:
42 self.onSelChanged.append(selChangedCB)
43 GUIComponent.__init__(self)
45 self.l = eListboxPythonMultiContent()
46 if type == EPG_TYPE_SINGLE:
47 self.l.setBuildFunc(self.buildSingleEntry)
48 elif type == EPG_TYPE_MULTI:
49 self.l.setBuildFunc(self.buildMultiEntry)
51 assert(type == EPG_TYPE_SIMILAR)
52 self.l.setBuildFunc(self.buildSimilarEntry)
53 self.epgcache = eEPGCache.getInstance()
54 self.clock_pixmap = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, 'epgclock-fs8.png'))
56 def getEventFromId(self, service, eventid):
58 if self.epgcache is not None and eventid is not None:
59 event = self.epgcache.lookupEventId(service.ref, eventid)
62 def getCurrentChangeCount(self):
63 if self.type == EPG_TYPE_MULTI:
64 return self.l.getCurrentSelection()[0]
69 if self.type == EPG_TYPE_MULTI:
71 tmp = self.l.getCurrentSelection()
75 service = ServiceReference(tmp[idx])
76 event = self.getEventFromId(service, eventid)
77 return ( event, service )
80 self.instance.moveSelection(self.instance.moveUp)
83 self.instance.moveSelection(self.instance.moveDown)
85 def connectSelectionChanged(func):
86 if not self.onSelChanged.count(func):
87 self.onSelChanged.append(func)
89 def disconnectSelectionChanged(func):
90 self.onSelChanged.remove(func)
92 def selectionChanged(self):
93 for x in self.onSelChanged:
98 print "FIXME in EPGList.selectionChanged"
101 GUI_WIDGET = eListbox
103 def postWidgetCreate(self, instance):
104 instance.setWrapAround(True)
105 instance.selectionChanged.get().append(self.selectionChanged)
106 instance.setContent(self.l)
108 def recalcEntrySize(self):
109 esize = self.l.getItemSize()
110 self.l.setFont(0, gFont("Regular", 22))
111 self.l.setFont(1, gFont("Regular", 16))
112 width = esize.width()
113 height = esize.height()
114 if self.type == EPG_TYPE_SINGLE:
115 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
116 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
117 self.descr_rect = Rect(width/20*7, 0, width/20*13, height)
118 elif self.type == EPG_TYPE_MULTI:
121 self.service_rect = Rect(xpos, 0, w-10, height)
124 self.start_end_rect = Rect(xpos, 0, w-10, height)
125 self.progress_rect = Rect(xpos, 4, w-10, height-8)
128 self.descr_rect = Rect(xpos, 0, width, height)
129 else: # EPG_TYPE_SIMILAR
130 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
131 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
132 self.service_rect = Rect(width/20*7, 0, width/20*13, height)
134 def buildSingleEntry(self, service, eventId, beginTime, duration, EventName):
135 rec=(self.timer.isInTimer(eventId, beginTime, duration, service) > ((duration/10)*8))
137 r2=self.datetime_rect
139 res = [ None ] # no private data needed
140 t = localtime(beginTime)
141 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]))
142 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])))
144 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, self.clock_pixmap))
145 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
147 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
150 def buildSimilarEntry(self, service, eventId, beginTime, service_name, duration):
151 rec=(self.timer.isInTimer(eventId, beginTime, duration, service) > ((duration/10)*8))
153 r2=self.datetime_rect
155 res = [ None ] # no private data needed
156 t = localtime(beginTime)
157 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]))
158 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])))
160 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, self.clock_pixmap))
161 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
163 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
166 def buildMultiEntry(self, changecount, service, eventId, begTime, duration, EventName, nowTime, service_name):
167 rec=begTime and (self.timer.isInTimer(eventId, begTime, duration, service) > ((duration/10)*8))
169 r2=self.progress_rect
171 r4=self.start_end_rect
172 res = [ None ] # no private data needed
174 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-21, r1.height(), 0, RT_HALIGN_LEFT, service_name))
175 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, self.clock_pixmap))
177 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, service_name))
178 if begTime is not None:
179 if nowTime < begTime:
180 begin = localtime(begTime)
181 end = localtime(begTime+duration)
182 # print "begin", begin
184 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])));
185 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
187 percent = (nowTime - begTime) * 100 / duration
188 res.append((eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent));
189 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
192 def queryEPG(self, list, buildFunc=None):
193 if self.epgcache is not None:
194 if buildFunc is not None:
195 return self.epgcache.lookupEvent(list, buildFunc)
197 return self.epgcache.lookupEvent(list)
200 def fillMultiEPG(self, services, stime=-1):
202 test = [ (service.ref.toString(), 0, stime) for service in services ]
203 test.insert(0, '0RIBDTCn')
204 self.list = self.queryEPG(test)
205 self.l.setList(self.list)
207 self.selectionChanged()
209 def updateMultiEPG(self, direction):
211 test = [ x[3] and (x[1], direction, x[3]) or (x[1], direction, 0) for x in self.list ]
212 test.insert(0, 'RIBDTCn')
213 tmp = self.queryEPG(test)
216 changecount = self.list[cnt][0] + direction
219 self.list[cnt]=(changecount, x[0], x[1], x[2], x[3], x[4], x[5], x[6])
221 self.l.setList(self.list)
223 self.selectionChanged()
225 def fillSingleEPG(self, service):
227 test = [ 'RIBDT', (service.ref.toString(), 0, -1, -1) ]
228 self.list = self.queryEPG(test)
229 self.l.setList(self.list)
231 self.selectionChanged()
233 def sortSingleEPG(self, type):
236 event_id = self.getSelectedEventId()
237 self.list.sort(key=lambda x: (x[4] and x[4].lower(), x[2]))
238 self.l.setList(self.list)
239 self.moveToEventId(event_id)
242 event_id = self.getSelectedEventId()
243 self.list.sort(key=lambda x: x[2])
244 self.l.setList(self.list)
245 self.moveToEventId(event_id)
247 def getSelectedEventId(self):
248 x = self.l.getCurrentSelection()
251 def moveToEventId(self, eventId):
255 self.instance.moveSelectionTo(index)
259 def fillSimilarList(self, refstr, event_id):
261 # search similar broadcastings
264 l = self.epgcache.search(('RIBND', 1024, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, event_id))
266 l.sort(key=lambda x: x[2])
268 self.selectionChanged()