add orBottomToTop, orRightToLeft, orLeftToRight(orHorizontal), orTopToBottom(OrVertic...
[enigma2.git] / lib / python / Components / Sources / List.py
index 6d083f05f41f209754a877383aec00ddc00cf251..26c68ab5a874f30ef6e29ab6eadb9e2d9b80bf9b 100644 (file)
@@ -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,8 @@ to generate HTML."""
                self.item_height = item_height
                self.fonts = fonts
                self.disable_callbacks = False
+               self.enableWrapAround = enableWrapAround
+               self.__style = "default" # style might be an optional string which can be used to define different visualisations in the skin
 
        def setList(self, list):
                self.__list = list
@@ -27,11 +28,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,29 +48,50 @@ 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
+               self.setIndex(self.index)
+
+       def selectPrevious(self):
+               if self.getIndex() - 1 < 0:
+                       if self.enableWrapAround:
+                               self.index = self.count() - 1
+               else:
+                       self.index -= 1
+               self.setIndex(self.index)
+
+       @cached
+       def getStyle(self):
+               return self.__style
+
+       def setStyle(self, style):
+               self.__style = style
+               self.changed((self.CHANGED_SPECIFIC, "style"))
+
+       style = property(getStyle, setStyle)
 
        def updateList(self, list):
                """Changes the list without changing the selection or emitting changed Events"""
                assert len(list) == len(self.__list)
-               print "get old index"
                old_index = self.index
-               print "disable callback"
                self.disable_callbacks = True
-               print "set list"
                self.list = list
-               print "set index"
                self.index = old_index
-               print "reenable callbacks"
                self.disable_callbacks = False
-               print "done"