1 from GUIComponent import GUIComponent
2 from Tools.FuzzyDate import FuzzyTime
3 from ServiceReference import ServiceReference
4 from Components.MultiContent import MultiContentEntryText
5 from Components.config import config
7 from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation, \
8 RT_HALIGN_LEFT, RT_HALIGN_RIGHT, eServiceReference, eServiceCenter
10 class MovieList(GUIComponent):
15 LISTTYPE_COMPACT_DESCRIPTION = 2
22 def __init__(self, root, list_type=None, sort_type=None, descr_state=None):
23 GUIComponent.__init__(self)
24 self.list_type = list_type or self.LISTTYPE_ORIGINAL
25 self.descr_state = descr_state or self.HIDE_DESCRIPTION
26 self.sort_type = sort_type or self.SORT_RECORDED
28 self.l = eListboxPythonMultiContent()
35 self.l.setBuildFunc(self.buildMovieListEntry)
37 self.onSelectionChanged = [ ]
39 def connectSelChanged(self, fnc):
40 if not fnc in self.onSelectionChanged:
41 self.onSelectionChanged.append(fnc)
43 def disconnectSelChanged(self, fnc):
44 if fnc in self.onSelectionChanged:
45 self.onSelectionChanged.remove(fnc)
47 def selectionChanged(self):
48 for x in self.onSelectionChanged:
51 def setListType(self, type):
54 def setDescriptionState(self, val):
55 self.descr_state = val
57 def setSortType(self, type):
61 if self.list_type == MovieList.LISTTYPE_ORIGINAL:
62 self.l.setFont(0, gFont("Regular", 22))
63 self.l.setFont(1, gFont("Regular", 18))
64 self.l.setFont(2, gFont("Regular", 16))
65 self.l.setItemHeight(75)
66 elif self.list_type == MovieList.LISTTYPE_COMPACT_DESCRIPTION or self.list_type == MovieList.LISTTYPE_COMPACT:
67 self.l.setFont(0, gFont("Regular", 20))
68 self.l.setFont(1, gFont("Regular", 14))
69 self.l.setItemHeight(37)
71 self.l.setFont(0, gFont("Regular", 20))
72 self.l.setFont(1, gFont("Regular", 16))
73 self.l.setItemHeight(25)
78 def buildMovieListEntry(self, serviceref, info, begin, len):
79 if serviceref.flags & eServiceReference.mustDescent:
82 width = self.l.getItemSize().width()
84 if len <= 0: #recalc len when not already done
85 cur_idx = self.l.getCurrentSelectionIndex()
86 x = self.list[cur_idx]
87 if config.usage.load_length_of_movies_in_moviellist.value:
88 len = x[1].getLength(x[0]) #recalc the movie length...
90 len = 0 #dont recalc movielist to speedup loading the list
91 self.list[cur_idx] = (x[0], x[1], x[2], len) #update entry in list... so next time we don't need to recalc
94 len = "%d:%02d" % (len / 60, len % 60)
96 if config.usage.load_length_of_movies_in_moviellist.value:
103 txt = info.getName(serviceref)
104 service = ServiceReference(info.getInfoString(serviceref, iServiceInformation.sServiceref))
105 description = info.getInfoString(serviceref, iServiceInformation.sDescription)
106 tags = info.getInfoString(serviceref, iServiceInformation.sTags)
111 begin_string = t[0] + ", " + t[1]
113 if self.list_type == MovieList.LISTTYPE_ORIGINAL:
114 res.append(MultiContentEntryText(pos=(0, 0), size=(width-182, 30), font = 0, flags = RT_HALIGN_LEFT, text=txt))
116 res.append(MultiContentEntryText(pos=(width-180, 0), size=(180, 30), font = 2, flags = RT_HALIGN_RIGHT, text = tags))
117 if service is not None:
118 res.append(MultiContentEntryText(pos=(200, 50), size=(200, 20), font = 1, flags = RT_HALIGN_LEFT, text = service.getServiceName()))
120 if service is not None:
121 res.append(MultiContentEntryText(pos=(width-180, 0), size=(180, 30), font = 2, flags = RT_HALIGN_RIGHT, text = service.getServiceName()))
122 res.append(MultiContentEntryText(pos=(0, 30), size=(width, 20), font=1, flags=RT_HALIGN_LEFT, text=description))
123 res.append(MultiContentEntryText(pos=(0, 50), size=(200, 20), font=1, flags=RT_HALIGN_LEFT, text=begin_string))
124 res.append(MultiContentEntryText(pos=(width-200, 50), size=(198, 20), font=1, flags=RT_HALIGN_RIGHT, text=len))
125 elif self.list_type == MovieList.LISTTYPE_COMPACT_DESCRIPTION:
126 res.append(MultiContentEntryText(pos=(0, 0), size=(width-120, 20), font = 0, flags = RT_HALIGN_LEFT, text = txt))
127 res.append(MultiContentEntryText(pos=(0, 20), size=(width-212, 17), font=1, flags=RT_HALIGN_LEFT, text=description))
128 res.append(MultiContentEntryText(pos=(width-120, 6), size=(120, 20), font=1, flags=RT_HALIGN_RIGHT, text=begin_string))
129 if service is not None:
130 res.append(MultiContentEntryText(pos=(width-212, 20), size=(154, 17), font = 1, flags = RT_HALIGN_RIGHT, text = service.getServiceName()))
131 res.append(MultiContentEntryText(pos=(width-58, 20), size=(58, 20), font=1, flags=RT_HALIGN_RIGHT, text=len))
132 elif self.list_type == MovieList.LISTTYPE_COMPACT:
133 res.append(MultiContentEntryText(pos=(0, 0), size=(width-77, 20), font = 0, flags = RT_HALIGN_LEFT, text = txt))
135 res.append(MultiContentEntryText(pos=(width-200, 20), size=(200, 17), font = 1, flags = RT_HALIGN_RIGHT, text = tags))
136 if service is not None:
137 res.append(MultiContentEntryText(pos=(200, 20), size=(200, 17), font = 1, flags = RT_HALIGN_LEFT, text = service.getServiceName()))
139 if service is not None:
140 res.append(MultiContentEntryText(pos=(width-200, 20), size=(200, 17), font = 1, flags = RT_HALIGN_RIGHT, text = service.getServiceName()))
141 res.append(MultiContentEntryText(pos=(0, 20), size=(200, 17), font=1, flags=RT_HALIGN_LEFT, text=begin_string))
142 res.append(MultiContentEntryText(pos=(width-75, 0), size=(75, 20), font=0, flags=RT_HALIGN_RIGHT, text=len))
144 assert(self.list_type == MovieList.LISTTYPE_MINIMAL)
145 if self.descr_state == MovieList.SHOW_DESCRIPTION:
146 res.append(MultiContentEntryText(pos=(0, 0), size=(width-146, 20), font = 0, flags = RT_HALIGN_LEFT, text = txt))
147 res.append(MultiContentEntryText(pos=(width-145, 4), size=(145, 20), font=1, flags=RT_HALIGN_RIGHT, text=begin_string))
149 res.append(MultiContentEntryText(pos=(0, 0), size=(width-77, 20), font = 0, flags = RT_HALIGN_LEFT, text = txt))
150 res.append(MultiContentEntryText(pos=(width-75, 0), size=(75, 20), font=0, flags=RT_HALIGN_RIGHT, text=len))
154 def moveToIndex(self, index):
155 self.instance.moveSelectionTo(index)
157 def getCurrentIndex(self):
158 return self.instance.getCurrentIndex()
160 def getCurrentEvent(self):
161 l = self.l.getCurrentSelection()
162 return l and l[0] and l[1] and l[1].getEvent(l[0])
164 def getCurrent(self):
165 l = self.l.getCurrentSelection()
168 GUI_WIDGET = eListbox
170 def postWidgetCreate(self, instance):
171 instance.setContent(self.l)
172 instance.selectionChanged.get().append(self.selectionChanged)
174 def preWidgetRemove(self, instance):
175 instance.setContent(None)
176 instance.selectionChanged.get().remove(self.selectionChanged)
178 def reload(self, root = None, filter_tags = None):
180 self.load(root, filter_tags)
182 self.load(self.root, filter_tags)
183 self.l.setList(self.list)
185 def removeService(self, service):
186 for l in self.list[:]:
189 self.l.setList(self.list)
192 return len(self.list)
194 def load(self, root, filter_tags):
195 # this lists our root service, then building a
199 self.serviceHandler = eServiceCenter.getInstance()
202 list = self.serviceHandler.list(root)
204 print "listing of movies failed"
210 serviceref = list.getNext()
211 if not serviceref.valid():
213 if serviceref.flags & eServiceReference.mustDescent:
216 info = self.serviceHandler.info(serviceref)
219 begin = info.getInfo(serviceref, iServiceInformation.sTimeCreate)
221 # convert space-seperated list of tags into a set
222 this_tags = info.getInfoString(serviceref, iServiceInformation.sTags).split(' ')
223 if this_tags == ['']:
225 this_tags = set(this_tags)
228 # filter_tags is either None (which means no filter at all), or
229 # a set. In this case, all elements of filter_tags must be present,
230 # otherwise the entry will be dropped.
231 if filter_tags is not None and not this_tags.issuperset(filter_tags):
234 self.list.append((serviceref, info, begin, -1))
236 if self.sort_type == MovieList.SORT_ALPHANUMERIC:
237 self.list.sort(key=self.buildAlphaNumericSortKey)
239 # sort: key is 'begin'
240 self.list.sort(key=lambda x: -x[2])
242 # finally, store a list of all tags which were found. these can be presented
243 # to the user to filter the list
246 def buildAlphaNumericSortKey(self, x):
248 info = self.serviceHandler.info(ref)
249 name = info and info.getName(ref)
250 return (name and name.lower() or "", -x[2])
252 def moveTo(self, serviceref):
255 if x[0] == serviceref:
256 self.instance.moveSelectionTo(count)
262 self.instance.moveSelection(self.instance.moveDown)