X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/d5e22a275d2ecdf3205bfefa927be6e125ac27b8..ddb050fe8357a01b1fc52070ee9f87450c407c1c:/lib/python/Components/MovieList.py diff --git a/lib/python/Components/MovieList.py b/lib/python/Components/MovieList.py index 4144353e..1a61d20f 100644 --- a/lib/python/Components/MovieList.py +++ b/lib/python/Components/MovieList.py @@ -1,89 +1,135 @@ from HTMLComponent import * from GUIComponent import * +from Tools.FuzzyDate import FuzzyTime +from ServiceReference import ServiceReference +from Components.MultiContent import MultiContentEntryText, RT_HALIGN_LEFT, RT_HALIGN_RIGHT -from enigma import eListboxPythonMultiContent, eListbox, gFont +from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation from enigma import eServiceReference, eServiceCenter, \ eServiceCenterPtr, iListableServicePtr, \ iStaticServiceInformationPtr +class MovieList(HTMLComponent, GUIComponent): + def __init__(self, root): + GUIComponent.__init__(self) + self.l = eListboxPythonMultiContent() + 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) + # + # | name of movie | + # + def buildMovieListEntry(self, serviceref, info, begin, len): + if serviceref.flags & eServiceReference.mustDescent: + return None -RT_HALIGN_LEFT = 0 -RT_HALIGN_RIGHT = 1 -RT_HALIGN_CENTER = 2 -RT_HALIGN_BLOCK = 4 + if len > 0: + len = "%d:%02d" % (len / 60, len % 60) + else: + len = "?:??" -RT_VALIGN_TOP = 0 -RT_VALIGN_CENTER = 8 -RT_VALIGN_BOTTOM = 16 + res = [ None ] -RT_WRAP = 32 + res.append(MultiContentEntryText(pos=(0, 0), size=(420, 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())) + description = info.getInfoString(serviceref, iServiceInformation.sDescription) -# -# | name of movie | -# -def MovieListEntry(serviceref, serviceHandler): - res = [ serviceref ] + begin_string = "" + if begin > 0: + t = FuzzyTime(begin) + begin_string = t[0] + ", " + t[1] - info = iStaticServiceInformationPtr() + 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)) - if serviceHandler.info(serviceref, info): - # ignore service which refuse to info - del info - return - - res.append((0, 0, 400, 30, 0, RT_HALIGN_LEFT, info.getName(serviceref))) - res.append((0, 30, 200, 20, 1, RT_HALIGN_LEFT, "Toller Film")) - res.append((0, 50, 200, 20, 1, RT_HALIGN_LEFT, "Aufgenommen: irgendwann")) - res.append((200, 50, 200, 20, 1, RT_HALIGN_RIGHT, "1232MB")) - - return res + return res + + def moveToIndex(self, index): + self.instance.moveSelectionTo(index) + + def getCurrentIndex(self): + return self.instance.getCurrentIndex() + + def getCurrentEvent(self): + l = self.l.getCurrentSelection() + return l and l[0] and l[1] and l[1].getEvent(l[0]) -class MovieList(HTMLComponent, GUIComponent): - def __init__(self, root): - GUIComponent.__init__(self) - self.l = eListboxPythonMultiContent() - self.load(root) - self.l.setList(self.list) - self.l.setFont(0, gFont("Arial", 30)) - self.l.setFont(1, gFont("Arial", 18)) - def getCurrent(self): - return self.l.getCurrentSelection() + l = self.l.getCurrentSelection() + return l and l[0] + + GUI_WIDGET = eListbox - def GUIcreate(self, parent): - self.instance = eListbox(parent) - self.instance.setContent(self.l) - self.instance.setItemHeight(75) + def postWidgetCreate(self, instance): + instance.setContent(self.l) + instance.setItemHeight(75) - def GUIdelete(self): - self.instance.setContent(None) - self.instance = None + def reload(self, root = None): + if root is not None: + self.load(root) + else: + self.load(self.root) + self.l.setList(self.list) + + def removeService(self, service): + for l in self.list[:]: + if l[0] == service: + self.list.remove(l) + self.l.setList(self.list) + + 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): # this lists our root service, then building a # nice list self.list = [ ] + self.root = root - serviceHandler = eServiceCenterPtr() - eServiceCenter.getInstance(serviceHandler) - list = iListableServicePtr() + self.serviceHandler = eServiceCenter.getInstance() + list = self.serviceHandler.list(root) - if serviceHandler.list(root, list): + if list is None: raise "listing of movies failed" - movieList = [ ] while 1: - s = eServiceReference() - if list.getNext(s): - del s - del list + serviceref = list.getNext() + if not serviceref.valid(): break - movieList.append(s) + if serviceref.flags & eServiceReference.mustDescent: + continue + info = self.serviceHandler.info(serviceref) + if info is None: + continue + begin = info.getInfo(serviceref, iServiceInformation.sTimeCreate) + self.list.append((serviceref, info, begin, -1)) - # now process them... - for ref in movieList: - self.list.append(MovieListEntry(ref, serviceHandler)) + self.list.sort(key=lambda x: -x[2]) + + def moveTo(self, serviceref): + found = 0 + count = 0 + for x in self.list: + if x[0] == serviceref: + found = count + count += 1 + self.instance.moveSelectionTo(found) + + def moveDown(self): + self.instance.moveSelection(self.instance.moveDown)