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, 'skin_default/icons/epgclock.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 preWidgetRemove(self, instance):
109 instance.selectionChanged.get().remove(self.selectionChanged)
110 instance.setContent(None)
112 def recalcEntrySize(self):
113 esize = self.l.getItemSize()
114 self.l.setFont(0, gFont("Regular", 22))
115 self.l.setFont(1, gFont("Regular", 16))
116 width = esize.width()
117 height = esize.height()
118 if self.type == EPG_TYPE_SINGLE:
119 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
120 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
121 self.descr_rect = Rect(width/20*7, 0, width/20*13, height)
122 elif self.type == EPG_TYPE_MULTI:
125 self.service_rect = Rect(xpos, 0, w-10, height)
128 self.start_end_rect = Rect(xpos, 0, w-10, height)
129 self.progress_rect = Rect(xpos, 4, w-10, height-8)
132 self.descr_rect = Rect(xpos, 0, width, height)
133 else: # EPG_TYPE_SIMILAR
134 self.weekday_rect = Rect(0, 0, width/20*2-10, height)
135 self.datetime_rect = Rect(width/20*2, 0, width/20*5-15, height)
136 self.service_rect = Rect(width/20*7, 0, width/20*13, height)
138 def buildSingleEntry(self, service, eventId, beginTime, duration, EventName):
139 rec=beginTime and (self.timer.isInTimer(eventId, beginTime, duration, service) > ((duration/10)*8))
141 r2=self.datetime_rect
143 res = [ None ] # no private data needed
144 t = localtime(beginTime)
145 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]))
146 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])))
148 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, self.clock_pixmap))
149 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
151 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
154 def buildSimilarEntry(self, service, eventId, beginTime, service_name, duration):
155 rec=beginTime and (self.timer.isInTimer(eventId, beginTime, duration, service) > ((duration/10)*8))
157 r2=self.datetime_rect
159 res = [ None ] # no private data needed
160 t = localtime(beginTime)
161 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_RIGHT, self.days[t[6]]))
162 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])))
164 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r3.left(), r3.top(), 21, 21, self.clock_pixmap))
165 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left() + 25, r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
167 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, service_name))
170 def buildMultiEntry(self, changecount, service, eventId, begTime, duration, EventName, nowTime, service_name):
171 rec=begTime and (self.timer.isInTimer(eventId, begTime, duration, service) > ((duration/10)*8))
173 r2=self.progress_rect
175 r4=self.start_end_rect
176 res = [ None ] # no private data needed
178 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width()-21, r1.height(), 0, RT_HALIGN_LEFT, service_name))
179 res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, r1.left()+r1.width()-16, r1.top(), 21, 21, self.clock_pixmap))
181 res.append((eListboxPythonMultiContent.TYPE_TEXT, r1.left(), r1.top(), r1.width(), r1.height(), 0, RT_HALIGN_LEFT, service_name))
182 if begTime is not None:
183 if nowTime < begTime:
184 begin = localtime(begTime)
185 end = localtime(begTime+duration)
186 # print "begin", begin
188 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])));
189 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
191 percent = (nowTime - begTime) * 100 / duration
192 res.append((eListboxPythonMultiContent.TYPE_PROGRESS, r2.left(), r2.top(), r2.width(), r2.height(), percent));
193 res.append((eListboxPythonMultiContent.TYPE_TEXT, r3.left(), r3.top(), r3.width(), r3.height(), 0, RT_HALIGN_LEFT, EventName))
196 def queryEPG(self, list, buildFunc=None):
197 if self.epgcache is not None:
198 if buildFunc is not None:
199 return self.epgcache.lookupEvent(list, buildFunc)
201 return self.epgcache.lookupEvent(list)
204 def fillMultiEPG(self, services, stime=-1):
206 test = [ (service.ref.toString(), 0, stime) for service in services ]
207 test.insert(0, 'X0RIBDTCn')
208 self.list = self.queryEPG(test)
209 self.l.setList(self.list)
211 self.selectionChanged()
213 def updateMultiEPG(self, direction):
215 test = [ x[3] and (x[1], direction, x[3]) or (x[1], direction, 0) for x in self.list ]
216 test.insert(0, 'XRIBDTCn')
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):
231 test = [ 'RIBDT', (service.ref.toString(), 0, -1, -1) ]
232 self.list = self.queryEPG(test)
233 self.l.setList(self.list)
235 self.selectionChanged()
237 def sortSingleEPG(self, type):
240 event_id = self.getSelectedEventId()
241 self.list.sort(key=lambda x: (x[4] and x[4].lower(), x[2]))
242 self.l.setList(self.list)
243 self.moveToEventId(event_id)
246 event_id = self.getSelectedEventId()
247 self.list.sort(key=lambda x: x[2])
248 self.l.setList(self.list)
249 self.moveToEventId(event_id)
251 def getSelectedEventId(self):
252 x = self.l.getCurrentSelection()
255 def moveToEventId(self, eventId):
259 self.instance.moveSelectionTo(index)
263 def fillSimilarList(self, refstr, event_id):
265 # search similar broadcastings
268 l = self.epgcache.search(('RIBND', 1024, eEPGCache.SIMILAR_BROADCASTINGS_SEARCH, refstr, event_id))
270 l.sort(key=lambda x: x[2])
272 self.selectionChanged()