from Source import Source
-from Tools.Event import Event
from Components.Element import cached
class List(Source, object):
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
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()
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"