1 from GUIComponent import GUIComponent
2 from Tools.FuzzyDate import FuzzyTime
3 from ServiceReference import ServiceReference
4 from Components.MultiContent import MultiContentEntryText
6 from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation, \
7 RT_HALIGN_LEFT, RT_HALIGN_RIGHT, eServiceReference, eServiceCenter
9 class MovieList(GUIComponent):
10 def __init__(self, root):
11 GUIComponent.__init__(self)
12 self.l = eListboxPythonMultiContent()
16 self.l.setFont(0, gFont("Regular", 22))
17 self.l.setFont(1, gFont("Regular", 18))
18 self.l.setFont(2, gFont("Regular", 16))
19 self.l.setBuildFunc(self.buildMovieListEntry)
20 self.l.setItemHeight(75)
25 def buildMovieListEntry(self, serviceref, info, begin, len):
26 if serviceref.flags & eServiceReference.mustDescent:
28 width = self.entry_width
30 if len <= 0: #recalc len when not already done
31 cur_idx = self.l.getCurrentSelectionIndex()
32 x = self.list[cur_idx]
33 len = x[1].getLength(x[0]) #recalc the movie length...
34 self.list[cur_idx] = (x[0], x[1], x[2], len) #update entry in list... so next time we don't need to recalc
37 len = "%d:%02d" % (len / 60, len % 60)
43 res.append(MultiContentEntryText(pos=(0, 0), size=(width-140, 30), font = 0, flags = RT_HALIGN_LEFT, text = info.getName(serviceref)))
44 service = ServiceReference(info.getInfoString(serviceref, iServiceInformation.sServiceref))
45 if service is not None:
46 res.append(MultiContentEntryText(pos=(width-140, 0), size=(140, 30), font = 2, flags = RT_HALIGN_RIGHT, text = service.getServiceName()))
48 description = info.getInfoString(serviceref, iServiceInformation.sDescription)
53 begin_string = t[0] + ", " + t[1]
55 res.append(MultiContentEntryText(pos=(0, 30), size=(width, 20), font=1, flags=RT_HALIGN_LEFT, text=description))
56 res.append(MultiContentEntryText(pos=(0, 50), size=(width-270, 20), font=1, flags=RT_HALIGN_LEFT, text=begin_string))
57 res.append(MultiContentEntryText(pos=(width, 50), size=(270, 20), font=1, flags=RT_HALIGN_RIGHT, text=len))
61 def moveToIndex(self, index):
62 self.instance.moveSelectionTo(index)
64 def getCurrentIndex(self):
65 return self.instance.getCurrentIndex()
67 def getCurrentEvent(self):
68 l = self.l.getCurrentSelection()
69 return l and l[0] and l[1] and l[1].getEvent(l[0])
72 l = self.l.getCurrentSelection()
77 def postWidgetCreate(self, instance):
78 instance.setContent(self.l)
79 self.entry_width = self.l.getItemSize().width()
81 def reload(self, root = None, filter_tags = None):
83 self.load(root, filter_tags)
85 self.load(self.root, filter_tags)
86 self.l.setList(self.list)
87 self.entry_width = self.l.getItemSize().width()
89 def removeService(self, service):
90 for l in self.list[:]:
93 self.l.setList(self.list)
94 self.entry_width = self.l.getItemSize().width()
99 def load(self, root, filter_tags):
100 # this lists our root service, then building a
106 self.serviceHandler = eServiceCenter.getInstance()
107 list = self.serviceHandler.list(root)
112 raise "listing of movies failed"
115 serviceref = list.getNext()
116 if not serviceref.valid():
118 if serviceref.flags & eServiceReference.mustDescent:
120 info = self.serviceHandler.info(serviceref)
123 begin = info.getInfo(serviceref, iServiceInformation.sTimeCreate)
125 # convert space-seperated list of tags into a set
126 this_tags = info.getInfoString(serviceref, iServiceInformation.sTags).split(' ')
127 if this_tags == ['']:
129 this_tags = set(this_tags)
131 # filter_tags is either None (which means no filter at all), or
132 # a set. In this case, all elements of filter_tags must be present,
133 # otherwise the entry will be dropped.
134 if filter_tags is not None and not this_tags.issuperset(filter_tags):
138 self.list.append((serviceref, info, begin, -1))
140 # sort: key is 'begin'
141 self.list.sort(key=lambda x: -x[2])
143 # finally, store a list of all tags which were found. these can be presented
144 # to the user to filter the list
147 def moveTo(self, serviceref):
151 if x[0] == serviceref:
154 self.instance.moveSelectionTo(found)
157 self.instance.moveSelection(self.instance.moveDown)