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:
29 if len <= 0: #recalc len when not already done
30 cur_idx = self.l.getCurrentSelectionIndex()
31 x = self.list[cur_idx]
32 len = x[1].getLength(x[0]) #recalc the movie length...
33 self.list[cur_idx] = (x[0], x[1], x[2], len) #update entry in list... so next time we don't need to recalc
36 len = "%d:%02d" % (len / 60, len % 60)
42 res.append(MultiContentEntryText(pos=(0, 0), size=(420, 30), font = 0, flags = RT_HALIGN_LEFT, text = info.getName(serviceref)))
43 service = ServiceReference(info.getInfoString(serviceref, iServiceInformation.sServiceref))
44 if service is not None:
45 res.append(MultiContentEntryText(pos=(420, 0), size=(140, 30), font = 2, flags = RT_HALIGN_RIGHT, text = service.getServiceName()))
47 description = info.getInfoString(serviceref, iServiceInformation.sDescription)
52 begin_string = t[0] + ", " + t[1]
54 res.append(MultiContentEntryText(pos=(0, 30), size=(560, 20), font=1, flags=RT_HALIGN_LEFT, text=description))
55 res.append(MultiContentEntryText(pos=(0, 50), size=(270, 20), font=1, flags=RT_HALIGN_LEFT, text=begin_string))
56 res.append(MultiContentEntryText(pos=(290, 50), size=(270, 20), font=1, flags=RT_HALIGN_RIGHT, text=len))
60 def moveToIndex(self, index):
61 self.instance.moveSelectionTo(index)
63 def getCurrentIndex(self):
64 return self.instance.getCurrentIndex()
66 def getCurrentEvent(self):
67 l = self.l.getCurrentSelection()
68 return l and l[0] and l[1] and l[1].getEvent(l[0])
71 l = self.l.getCurrentSelection()
76 def postWidgetCreate(self, instance):
77 instance.setContent(self.l)
79 def reload(self, root = None, filter_tags = None):
81 self.load(root, filter_tags)
83 self.load(self.root, filter_tags)
84 self.l.setList(self.list)
86 def removeService(self, service):
87 for l in self.list[:]:
90 self.l.setList(self.list)
95 def load(self, root, filter_tags):
96 # this lists our root service, then building a
102 self.serviceHandler = eServiceCenter.getInstance()
103 list = self.serviceHandler.list(root)
108 raise "listing of movies failed"
111 serviceref = list.getNext()
112 if not serviceref.valid():
114 if serviceref.flags & eServiceReference.mustDescent:
116 info = self.serviceHandler.info(serviceref)
119 begin = info.getInfo(serviceref, iServiceInformation.sTimeCreate)
121 # convert space-seperated list of tags into a set
122 this_tags = info.getInfoString(serviceref, iServiceInformation.sTags).split(' ')
123 if this_tags == ['']:
125 this_tags = set(this_tags)
127 # filter_tags is either None (which means no filter at all), or
128 # a set. In this case, all elements of filter_tags must be present,
129 # otherwise the entry will be dropped.
130 if filter_tags is not None and not this_tags.issuperset(filter_tags):
134 self.list.append((serviceref, info, begin, -1))
136 # sort: key is 'begin'
137 self.list.sort(key=lambda x: -x[2])
139 # finally, store a list of all tags which were found. these can be presented
140 # to the user to filter the list
143 def moveTo(self, serviceref):
147 if x[0] == serviceref:
150 self.instance.moveSelectionTo(found)
153 self.instance.moveSelection(self.instance.moveDown)