X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/a65edb264cc943a2a15b6886d9fa3190a92373c0..3285eb3ebcd0ba134ac6b80337f8519d5a0da5b0:/lib/python/Components/MovieList.py?ds=sidebyside diff --git a/lib/python/Components/MovieList.py b/lib/python/Components/MovieList.py index 1a61d20f..588582da 100644 --- a/lib/python/Components/MovieList.py +++ b/lib/python/Components/MovieList.py @@ -1,25 +1,23 @@ -from HTMLComponent import * -from GUIComponent import * +from GUIComponent import GUIComponent from Tools.FuzzyDate import FuzzyTime from ServiceReference import ServiceReference -from Components.MultiContent import MultiContentEntryText, RT_HALIGN_LEFT, RT_HALIGN_RIGHT +from Components.MultiContent import MultiContentEntryText -from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation +from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation, \ + RT_HALIGN_LEFT, RT_HALIGN_RIGHT, eServiceReference, eServiceCenter -from enigma import eServiceReference, eServiceCenter, \ - eServiceCenterPtr, iListableServicePtr, \ - iStaticServiceInformationPtr - -class MovieList(HTMLComponent, GUIComponent): +class MovieList(GUIComponent): def __init__(self, root): GUIComponent.__init__(self) self.l = eListboxPythonMultiContent() + self.tags = set() if root is not None: self.reload(root) self.l.setFont(0, gFont("Regular", 22)) self.l.setFont(1, gFont("Regular", 18)) self.l.setFont(2, gFont("Regular", 16)) self.l.setBuildFunc(self.buildMovieListEntry) + self.l.setItemHeight(75) # # | name of movie | @@ -27,6 +25,13 @@ class MovieList(HTMLComponent, GUIComponent): def buildMovieListEntry(self, serviceref, info, begin, len): if serviceref.flags & eServiceReference.mustDescent: return None + width = self.entry_width + + if len <= 0: #recalc len when not already done + cur_idx = self.l.getCurrentSelectionIndex() + x = self.list[cur_idx] + len = x[1].getLength(x[0]) #recalc the movie length... + self.list[cur_idx] = (x[0], x[1], x[2], len) #update entry in list... so next time we don't need to recalc if len > 0: len = "%d:%02d" % (len / 60, len % 60) @@ -35,10 +40,10 @@ class MovieList(HTMLComponent, GUIComponent): res = [ None ] - res.append(MultiContentEntryText(pos=(0, 0), size=(420, 30), font = 0, flags = RT_HALIGN_LEFT, text = info.getName(serviceref))) + res.append(MultiContentEntryText(pos=(0, 0), size=(width-140, 30), font = 0, flags = RT_HALIGN_LEFT, text = info.getName(serviceref))) service = ServiceReference(info.getInfoString(serviceref, iServiceInformation.sServiceref)) if service is not None: - res.append(MultiContentEntryText(pos=(420, 0), size=(140, 30), font = 2, flags = RT_HALIGN_RIGHT, text = service.getServiceName())) + res.append(MultiContentEntryText(pos=(width-140, 0), size=(140, 30), font = 2, flags = RT_HALIGN_RIGHT, text = service.getServiceName())) description = info.getInfoString(serviceref, iServiceInformation.sDescription) @@ -47,9 +52,9 @@ class MovieList(HTMLComponent, GUIComponent): t = FuzzyTime(begin) begin_string = t[0] + ", " + t[1] - res.append(MultiContentEntryText(pos=(0, 30), size=(560, 20), font=1, flags=RT_HALIGN_LEFT, text=description)) - res.append(MultiContentEntryText(pos=(0, 50), size=(270, 20), font=1, flags=RT_HALIGN_LEFT, text=begin_string)) - res.append(MultiContentEntryText(pos=(290, 50), size=(270, 20), font=1, flags=RT_HALIGN_RIGHT, text=len)) + res.append(MultiContentEntryText(pos=(0, 30), size=(width, 20), font=1, flags=RT_HALIGN_LEFT, text=description)) + res.append(MultiContentEntryText(pos=(0, 50), size=(width-270, 20), font=1, flags=RT_HALIGN_LEFT, text=begin_string)) + res.append(MultiContentEntryText(pos=(width-270, 50), size=(270, 20), font=1, flags=RT_HALIGN_RIGHT, text=len)) return res @@ -71,31 +76,27 @@ class MovieList(HTMLComponent, GUIComponent): def postWidgetCreate(self, instance): instance.setContent(self.l) - instance.setItemHeight(75) - - def reload(self, root = None): + self.entry_width = self.l.getItemSize().width() + + def reload(self, root = None, filter_tags = None): if root is not None: - self.load(root) + self.load(root, filter_tags) else: - self.load(self.root) + self.load(self.root, filter_tags) self.l.setList(self.list) + self.entry_width = self.l.getItemSize().width() def removeService(self, service): for l in self.list[:]: if l[0] == service: self.list.remove(l) self.l.setList(self.list) + self.entry_width = self.l.getItemSize().width() def __len__(self): return len(self.list) - def updateLengthOfIndex(self, index): - if len(self.list) > index: - x = self.list[index] - self.list[index] = (x[0], x[1], x[2], x[1].getLength(x[0])) - self.l.invalidateEntry(index) - - def load(self, root): + def load(self, root, filter_tags): # this lists our root service, then building a # nice list @@ -105,6 +106,8 @@ class MovieList(HTMLComponent, GUIComponent): self.serviceHandler = eServiceCenter.getInstance() list = self.serviceHandler.list(root) + tags = set() + if list is None: raise "listing of movies failed" @@ -118,9 +121,28 @@ class MovieList(HTMLComponent, GUIComponent): if info is None: continue begin = info.getInfo(serviceref, iServiceInformation.sTimeCreate) + + # convert space-seperated list of tags into a set + this_tags = info.getInfoString(serviceref, iServiceInformation.sTags).split(' ') + if this_tags == ['']: + this_tags = [] + this_tags = set(this_tags) + + # filter_tags is either None (which means no filter at all), or + # a set. In this case, all elements of filter_tags must be present, + # otherwise the entry will be dropped. + if filter_tags is not None and not this_tags.issuperset(filter_tags): + continue + + tags |= this_tags self.list.append((serviceref, info, begin, -1)) + # sort: key is 'begin' self.list.sort(key=lambda x: -x[2]) + + # finally, store a list of all tags which were found. these can be presented + # to the user to filter the list + self.tags = tags def moveTo(self, serviceref): found = 0