X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/a62e5192b59710f70a8610dbff84982ad6a98e46..1c6adfdbe104773d7a98377de6951da02ae1aac0:/lib/python/Components/Sources/List.py diff --git a/lib/python/Components/Sources/List.py b/lib/python/Components/Sources/List.py index 6d083f05..89e1e71c 100644 --- a/lib/python/Components/Sources/List.py +++ b/lib/python/Components/Sources/List.py @@ -1,5 +1,4 @@ from Source import Source -from Tools.Event import Event from Components.Element import cached class List(Source, object): @@ -17,6 +16,7 @@ to generate HTML.""" self.item_height = item_height self.fonts = fonts self.disable_callbacks = False + self.enableWrapAround = enableWrapAround def setList(self, list): self.__list = list @@ -27,11 +27,14 @@ to generate HTML.""" def entry_changed(self, index): if not self.disable_callbacks: self.downstream_elements.entry_changed(self, index) + + def count(self): + return len(self.__list) def selectionChanged(self, index): if self.disable_callbacks: return - + for x in self.onSelectionChanged: x() @@ -44,17 +47,32 @@ to generate HTML.""" def setIndex(self, index): if self.master is not None: self.master.index = index + self.selectionChanged(index) @cached def getIndex(self): if self.master is not None: return self.master.index else: - return -1 + return None setCurrentIndex = setIndex index = property(getIndex, setIndex) + + def selectNext(self): + if self.getIndex() + 1 >= self.count(): + if self.enableWrapAround: + self.index = 0 + else: + self.index += 1 + + def selectPrevious(self): + if self.getIndex() - 1 < 0: + if self.enableWrapAround: + self.index = self.count() - 1 + else: + self.index -= 1 def updateList(self, list): """Changes the list without changing the selection or emitting changed Events"""