diff options
Diffstat (limited to 'lib/python')
| -rw-r--r-- | lib/python/Components/Converter/Makefile.am | 2 | ||||
| -rw-r--r-- | lib/python/Components/Converter/MovieInfo.py | 42 | ||||
| -rw-r--r-- | lib/python/Components/MovieList.py | 156 | ||||
| -rw-r--r-- | lib/python/Screens/MovieSelection.py | 203 |
4 files changed, 327 insertions, 76 deletions
diff --git a/lib/python/Components/Converter/Makefile.am b/lib/python/Components/Converter/Makefile.am index 81dfdd4d..657010db 100644 --- a/lib/python/Components/Converter/Makefile.am +++ b/lib/python/Components/Converter/Makefile.am @@ -4,4 +4,4 @@ install_PYTHON = \ __init__.py ClockToText.py Converter.py EventName.py StaticText.py EventTime.py \ Poll.py RemainingToText.py StringList.py ServiceName.py FrontendInfo.py ServiceInfo.py \ ConditionalShowHide.py ServicePosition.py ValueRange.py RdsInfo.py Streaming.py \ - StaticMultiList.py ServiceTime.py + StaticMultiList.py ServiceTime.py MovieInfo.py diff --git a/lib/python/Components/Converter/MovieInfo.py b/lib/python/Components/Converter/MovieInfo.py new file mode 100644 index 00000000..068d24d3 --- /dev/null +++ b/lib/python/Components/Converter/MovieInfo.py @@ -0,0 +1,42 @@ +from Components.Converter.Converter import Converter +from Components.Element import cached +from enigma import iServiceInformation +from ServiceReference import ServiceReference + +class MovieInfo(Converter, object): + MOVIE_SHORT_DESCRIPTION = 0 # meta description when available.. when not .eit short description + MOVIE_META_DESCRIPTION = 1 # just meta description when available + MOVIE_REC_SERVICE_NAME = 2 # name of recording service + + def __init__(self, type): + if type == "ShortDescription": + self.type = self.MOVIE_SHORT_DESCRIPTION + elif type == "MetaDescription": + self.type = self.MOVIE_META_DESCRIPTION + elif type == "RecordServiceName": + self.type = self.MOVIE_REC_SERVICE_NAME + else: + raise str("'%s' is not <ShortDescription|MetaDescription|RecordServiceName> for MovieInfo converter" % type) + Converter.__init__(self, type) + + @cached + def getText(self): + service = self.source.service + info = self.source.info + if info and service: + if self.type == self.MOVIE_SHORT_DESCRIPTION: + event = self.source.event + if event: + descr = info.getInfoString(service, iServiceInformation.sDescription) + if descr == "": + return event.getShortDescription() + else: + return descr + elif self.type == self.MOVIE_META_DESCRIPTION: + return info.getInfoString(service, iServiceInformation.sDescription) + elif self.type == self.MOVIE_REC_SERVICE_NAME: + rec_ref_str = info.getInfoString(service, iServiceInformation.sServiceref) + return ServiceReference(rec_ref_str).getServiceName() + return "" + + text = property(getText) diff --git a/lib/python/Components/MovieList.py b/lib/python/Components/MovieList.py index 588582da..8e4fc043 100644 --- a/lib/python/Components/MovieList.py +++ b/lib/python/Components/MovieList.py @@ -7,17 +7,69 @@ from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformat RT_HALIGN_LEFT, RT_HALIGN_RIGHT, eServiceReference, eServiceCenter class MovieList(GUIComponent): - def __init__(self, root): + SORT_ALPHANUMERIC = 1 + SORT_RECORDED = 2 + + LISTTYPE_ORIGINAL = 0 + LISTTYPE_COMPACT_DESCRIPTION = 1 + LISTTYPE_COMPACT = 2 + LISTTYPE_MINIMAL = 3 + + HIDE_DESCRIPTION = 0 + SHOW_DESCRIPTION = 1 + + def __init__(self, root, list_type, sort_type, descr_state): GUIComponent.__init__(self) + self.list_type = list_type + self.descr_state = descr_state + self.sort_type = sort_type + 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.redrawList() self.l.setBuildFunc(self.buildMovieListEntry) - self.l.setItemHeight(75) + + self.onSelectionChanged = [ ] + + def connectSelChanged(self, fnc): + if not fnc in self.onSelectionChanged: + self.onSelectionChanged.append(fnc) + + def disconnectSelChanged(self, fnc): + if fnc in self.onSelectionChanged: + self.onSelectionChanged.remove(fnc) + + def selectionChanged(self): + for x in self.onSelectionChanged: + x() + + def setListType(self, type): + self.list_type = type + + def setDescriptionState(self, val): + self.descr_state = val + + def setSortType(self, type): + self.sort_type = type + + def redrawList(self): + if self.list_type == MovieList.LISTTYPE_ORIGINAL: + self.l.setFont(0, gFont("Regular", 22)) + self.l.setFont(1, gFont("Regular", 18)) + self.l.setFont(2, gFont("Regular", 16)) + self.l.setItemHeight(75) + elif self.list_type == MovieList.LISTTYPE_COMPACT_DESCRIPTION or self.list_type == MovieList.LISTTYPE_COMPACT: + self.l.setFont(0, gFont("Regular", 20)) + self.l.setFont(1, gFont("Regular", 14)) + self.l.setItemHeight(37) + else: + self.l.setFont(0, gFont("Regular", 20)) + self.l.setFont(1, gFont("Regular", 16)) + self.l.setItemHeight(25) # # | name of movie | @@ -25,37 +77,60 @@ class MovieList(GUIComponent): def buildMovieListEntry(self, serviceref, info, begin, len): if serviceref.flags & eServiceReference.mustDescent: return None - width = self.entry_width + + width = self.l.getItemSize().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) else: len = "?:??" - + res = [ None ] - - res.append(MultiContentEntryText(pos=(0, 0), size=(width-140, 30), font = 0, flags = RT_HALIGN_LEFT, text = info.getName(serviceref))) + + txt = info.getName(serviceref) service = ServiceReference(info.getInfoString(serviceref, iServiceInformation.sServiceref)) - if service is not None: - 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) - + begin_string = "" if begin > 0: t = FuzzyTime(begin) begin_string = t[0] + ", " + t[1] - - 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)) - + + if self.list_type == MovieList.LISTTYPE_ORIGINAL: + res.append(MultiContentEntryText(pos=(0, 0), size=(width-182, 30), font = 0, flags = RT_HALIGN_LEFT, text=txt)) + if service is not None: + res.append(MultiContentEntryText(pos=(width-180, 0), size=(180, 30), font = 2, flags = RT_HALIGN_RIGHT, text = service.getServiceName())) + 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-200, 50), size=(200, 20), font=1, flags=RT_HALIGN_RIGHT, text=len)) + elif self.list_type == MovieList.LISTTYPE_COMPACT_DESCRIPTION: + res.append(MultiContentEntryText(pos=(0, 0), size=(width-120, 20), font = 0, flags = RT_HALIGN_LEFT, text = txt)) + if service is not None: + res.append(MultiContentEntryText(pos=(width-212, 20), size=(154, 17), font = 1, flags = RT_HALIGN_RIGHT, text = service.getServiceName())) + res.append(MultiContentEntryText(pos=(0, 20), size=(width-212, 17), font=1, flags=RT_HALIGN_LEFT, text=description)) + res.append(MultiContentEntryText(pos=(width-120, 6), size=(120, 20), font=1, flags=RT_HALIGN_RIGHT, text=begin_string)) + res.append(MultiContentEntryText(pos=(width-58, 20), size=(58, 20), font=1, flags=RT_HALIGN_RIGHT, text=len)) + elif self.list_type == MovieList.LISTTYPE_COMPACT: + res.append(MultiContentEntryText(pos=(0, 0), size=(width-77, 20), font = 0, flags = RT_HALIGN_LEFT, text = txt)) + if service is not None: + res.append(MultiContentEntryText(pos=(width-200, 20), size=(200, 17), font = 1, flags = RT_HALIGN_RIGHT, text = service.getServiceName())) + res.append(MultiContentEntryText(pos=(0, 20), size=(width-200, 17), font=1, flags=RT_HALIGN_LEFT, text=begin_string)) + res.append(MultiContentEntryText(pos=(width-75, 0), size=(75, 20), font=0, flags=RT_HALIGN_RIGHT, text=len)) + else: + assert(self.list_type == MovieList.LISTTYPE_MINIMAL) + if self.descr_state == MovieList.SHOW_DESCRIPTION: + res.append(MultiContentEntryText(pos=(0, 0), size=(width-146, 20), font = 0, flags = RT_HALIGN_LEFT, text = txt)) + res.append(MultiContentEntryText(pos=(width-145, 4), size=(145, 20), font=1, flags=RT_HALIGN_RIGHT, text=begin_string)) + else: + res.append(MultiContentEntryText(pos=(0, 0), size=(width-77, 20), font = 0, flags = RT_HALIGN_LEFT, text = txt)) + res.append(MultiContentEntryText(pos=(width-75, 0), size=(75, 20), font=0, flags=RT_HALIGN_RIGHT, text=len)) + return res def moveToIndex(self, index): @@ -73,10 +148,10 @@ class MovieList(GUIComponent): return l and l[0] GUI_WIDGET = eListbox - + def postWidgetCreate(self, instance): instance.setContent(self.l) - self.entry_width = self.l.getItemSize().width() + instance.selectionChanged.get().append(self.selectionChanged) def reload(self, root = None, filter_tags = None): if root is not None: @@ -84,14 +159,12 @@ class MovieList(GUIComponent): else: 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) @@ -101,57 +174,66 @@ class MovieList(GUIComponent): # nice list self.list = [ ] - self.root = root - self.serviceHandler = eServiceCenter.getInstance() - list = self.serviceHandler.list(root) + self.root = root + list = self.serviceHandler.list(root) + if list is None: + print "listing of movies failed" + list = [ ] + return tags = set() - if list is None: - raise "listing of movies failed" - while 1: serviceref = list.getNext() if not serviceref.valid(): break if serviceref.flags & eServiceReference.mustDescent: continue + info = self.serviceHandler.info(serviceref) 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]) + if self.sort_type == MovieList.SORT_ALPHANUMERIC: + self.list.sort(key=self.buildAlphaNumericSortKey) + else: + # 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 buildAlphaNumericSortKey(self, x): + ref = x[0] + info = self.serviceHandler.info(ref) + name = info and info.getName(ref) + return name and name.lower() or "" + def moveTo(self, serviceref): - found = 0 count = 0 for x in self.list: if x[0] == serviceref: - found = count + self.instance.moveSelectionTo(count) + break count += 1 - self.instance.moveSelectionTo(found) def moveDown(self): self.instance.moveSelection(self.instance.moveDown) diff --git a/lib/python/Screens/MovieSelection.py b/lib/python/Screens/MovieSelection.py index d345bddb..ad9a2aff 100644 --- a/lib/python/Screens/MovieSelection.py +++ b/lib/python/Screens/MovieSelection.py @@ -1,33 +1,92 @@ from Screen import Screen from Components.Button import Button -from Components.ActionMap import ActionMap +from Components.ActionMap import HelpableActionMap, ActionMap +from Components.MenuList import MenuList from Components.MovieList import MovieList from Components.DiskInfo import DiskInfo +from Components.Pixmap import Pixmap from Components.Label import Label from Components.PluginComponent import plugins +from Components.config import config, ConfigSubsection, ConfigInteger, configfile +from Components.Sources.ServiceEvent import ServiceEvent + from Plugins.Plugin import PluginDescriptor from Screens.MessageBox import MessageBox -from Screens.FixedMenu import FixedMenu from Screens.ChoiceBox import ChoiceBox +from Screens.HelpMenu import HelpableScreen from Tools.Directories import * from Tools.BoundFunction import boundFunction -from enigma import eServiceReference, eServiceCenter, eTimer +from enigma import eServiceReference, eServiceCenter, eTimer, eSize + +config.movielist = ConfigSubsection() +config.movielist.moviesort = ConfigInteger(default=MovieList.SORT_RECORDED) +config.movielist.listtype = ConfigInteger(default=MovieList.LISTTYPE_COMPACT_DESCRIPTION) +config.movielist.description = ConfigInteger(default=MovieList.HIDE_DESCRIPTION) -class ChannelContextMenu(FixedMenu): +class MovieContextMenu(Screen): def __init__(self, session, csel, service): + Screen.__init__(self, session) self.csel = csel self.service = service - menu = [(_("back"), self.close), (_("delete..."), self.delete)] + self["actions"] = ActionMap(["OkCancelActions"], + { + "ok": self.okbuttonClick, + "cancel": self.cancelClick + }) + menu = [(_("delete..."), self.delete)] + for p in plugins.getPlugins(PluginDescriptor.WHERE_MOVIELIST): menu.append((p.description, boundFunction(self.execPlugin, p))) + + if config.movielist.moviesort.value == MovieList.SORT_ALPHANUMERIC: + menu.append((_("sort by date"), boundFunction(self.sortBy, MovieList.SORT_RECORDED))) + else: + menu.append((_("alphabetic sort"), boundFunction(self.sortBy, MovieList.SORT_ALPHANUMERIC))) + + menu.append((_("list style default"), boundFunction(self.listType, MovieList.LISTTYPE_ORIGINAL))) + menu.append((_("list style compact with description"), boundFunction(self.listType, MovieList.LISTTYPE_COMPACT_DESCRIPTION))) + menu.append((_("list style compact"), boundFunction(self.listType, MovieList.LISTTYPE_COMPACT))) + menu.append((_("list style single line"), boundFunction(self.listType, MovieList.LISTTYPE_MINIMAL))) + + if config.movielist.description.value == MovieList.SHOW_DESCRIPTION: + menu.append((_("hide extended description"), boundFunction(self.showDescription, MovieList.HIDE_DESCRIPTION))) + else: + menu.append((_("show extended description"), boundFunction(self.showDescription, MovieList.SHOW_DESCRIPTION))) + self["menu"] = MenuList(menu) + + def okbuttonClick(self): + self["menu"].getCurrent()[1]() + + def cancelClick(self): + self.close(False) + + def sortBy(self, newType): + self.csel.saveflag = True + config.movielist.moviesort.value = newType + self.csel.selectedmovie = self.csel.getCurrent() + self.csel.setSortType(newType) + self.csel.reloadList() + self.csel.moveTo() + self.close() + + def listType(self, newType): + self.csel.saveflag = True + config.movielist.listtype.value = newType + self.csel.setListType(newType) + self.csel.list.redrawList() + self.close() - FixedMenu.__init__(self, session, _("Movie Menu"), menu) - self.skinName = "Menu" + def showDescription(self, newType): + self.csel.saveflag = True + config.movielist.description.value = newType + self.csel.setDescriptionState(newType) + self.csel.updateDescription() + self.close() def execPlugin(self, plugin): plugin(session=self.session, service=self.service) @@ -42,7 +101,6 @@ class ChannelContextMenu(FixedMenu): # simulate first if not offline.deleteFromDisk(1): result = True - if result == True: self.session.openWithCallback(self.deleteConfirmed, MessageBox, _("Do you really want to delete %s?") % (name)) else: @@ -51,7 +109,7 @@ class ChannelContextMenu(FixedMenu): def deleteConfirmed(self, confirmed): if not confirmed: return self.close() - + serviceHandler = eServiceCenter.getInstance() offline = serviceHandler.offlineOperations(self.service) result = False @@ -65,52 +123,98 @@ class ChannelContextMenu(FixedMenu): else: list = self.csel["list"].removeService(self.service) self.close() - -class MovieSelection(Screen): + +class SelectionEventInfo: + def __init__(self): + self["Service"] = ServiceEvent() + self.list.connectSelChanged(self.__selectionChanged) + self.timer = eTimer() + self.timer.timeout.get().append(self.updateEventInfo) + self.onShown.append(self.__selectionChanged) + + def __selectionChanged(self): + if self.execing and config.movielist.description.value == MovieList.SHOW_DESCRIPTION: + self.timer.start(100, True) + + def updateEventInfo(self): + serviceref = self.getCurrent() + self["Service"].newService(serviceref) + +class MovieSelection(Screen, HelpableScreen, SelectionEventInfo): def __init__(self, session, selectedmovie = None): Screen.__init__(self, session) - + HelpableScreen.__init__(self) + + self.saveflag = False + self.tags = [ ] self.selected_tags = None - + self.current_ref = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + resolveFilename(SCOPE_HDD)) - + self.movemode = False self.bouquet_mark_edit = False - + self.delayTimer = eTimer() self.delayTimer.timeout.get().append(self.updateHDDData) - + self["waitingtext"] = Label(_("Please wait... Loading list...")) - - self["list"] = MovieList(None) + + # create optional description border and hide immediately + self["DescriptionBorder"] = Pixmap() + self["DescriptionBorder"].hide() + + self["list"] = MovieList(None, + config.movielist.listtype.value, + config.movielist.moviesort.value, + config.movielist.description.value) + self.list = self["list"] self.selectedmovie = selectedmovie - + + # Need list for init + SelectionEventInfo.__init__(self) + self["key_red"] = Button(_("All...")) self["key_green"] = Button("") self["key_yellow"] = Button("") self["key_blue"] = Button("") - - #self["okbutton"] = Button("ok", [self.channelSelected]) - self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False) - - self["actions"] = ActionMap(["OkCancelActions", "MovieSelectionActions", "ColorActions"], + + #self["freeDiskSpace"] = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False) + self["freeDiskSpace"] = self.diskinfo = DiskInfo(resolveFilename(SCOPE_HDD), DiskInfo.FREE, update=False) + + self["MovieSelectionActions"] = HelpableActionMap(self, "MovieSelectionActions", { - "cancel": self.abort, - "ok": self.movieSelected, - "showEventInfo": self.showEventInformation, - "contextMenu": self.doContext, - - "red": self.showAll, - "green": self.showTagsFirst, - "yellow": self.showTagsSecond, - "blue": self.showTagsMenu, + "contextMenu": (self.doContext, _("menu")), + "showEventInfo": (self.showEventInformation, _("show event details")), }) - self["actions"].csel = self + + self["ColorActions"] = HelpableActionMap(self, "ColorActions", + { + "red": (self.showAll, _("show all")), + "green": (self.showTagsFirst, _("show first tag")), + "yellow": (self.showTagsSecond, _("show second tag")), + "blue": (self.showTagsMenu, _("show tag menu")), + }) + + self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions", + { + "cancel": (self.abort, _("exit movielist")), + "ok": (self.movieSelected, _("select movie")), + }) + self.onShown.append(self.go) self.inited = False + def updateDescription(self): + if config.movielist.description.value == MovieList.SHOW_DESCRIPTION: + self["DescriptionBorder"].show() + self["list"].instance.resize(eSize(self.listWidth, self.listHeight-self["DescriptionBorder"].instance.size().height())) + else: + self["Service"].newService(None) + self["DescriptionBorder"].hide() + self["list"].instance.resize(eSize(self.listWidth, self.listHeight)) + def showEventInformation(self): from Screens.EventView import EventViewSimple from ServiceReference import ServiceReference @@ -124,15 +228,19 @@ class MovieSelection(Screen): # this is of course not the right way to do this. self.delayTimer.start(10, 1) self.inited=True + # as this workaround is here anyways we can wait until the skin is initialized + # and afterwards read out the information we need to draw the dynamic style + listsize = self["list"].instance.size() + self.listWidth = listsize.width() + self.listHeight = listsize.height() + self.updateDescription() def updateHDDData(self): self.reloadList() if self.selectedmovie is not None: self.moveTo() - self["waitingtext"].instance.hide() - + self["waitingtext"].visible = False self["freeDiskSpace"].update() - self.updateTags() def moveTo(self): @@ -144,16 +252,26 @@ class MovieSelection(Screen): def movieSelected(self): current = self.getCurrent() if current is not None: + self.saveconfig() self.close(current) def doContext(self): current = self.getCurrent() if current is not None: - self.session.open(ChannelContextMenu, self, current) + self.session.open(MovieContextMenu, self, current) def abort(self): + self.saveconfig() self.close(None) + def saveconfig(self): + if self.saveflag == True: + config.movielist.moviesort.save() + config.movielist.listtype.save() + config.movielist.description.save() + configfile.save() + self.saveflag = False + def getTagDescription(self, tag): # TODO: access the tag database return tag @@ -184,6 +302,15 @@ class MovieSelection(Screen): else: self["key_blue"].text = "" + def setListType(self, type): + self["list"].setListType(type) + + def setDescriptionState(self, val): + self["list"].setDescriptionState(val) + + def setSortType(self, type): + self["list"].setSortType(type) + def reloadList(self): self["list"].reload(self.current_ref, self.selected_tags) title = _("Recorded files...") |
