1 from Source import Source
2 from Components.Element import cached
4 class List(Source, object):
5 """The datasource of a listbox. Currently, the format depends on the used converter. So
6 if you put a simple string list in here, you need to use a StringList converter, if you are
7 using a "multi content list styled"-list, you need to use the StaticMultiList converter, and
10 This has been done so another converter could convert the list to a different format, for example
12 def __init__(self, list = [ ], enableWrapAround = False, item_height = 25, fonts = [ ]):
15 self.onSelectionChanged = [ ]
16 self.item_height = item_height
18 self.disable_callbacks = False
19 self.enableWrapAround = enableWrapAround
20 self.__style = "default" # style might be an optional string which can be used to define different visualisations in the skin
22 def setList(self, list):
24 self.changed((self.CHANGED_ALL,))
26 list = property(lambda self: self.__list, setList)
28 def entry_changed(self, index):
29 if not self.disable_callbacks:
30 self.downstream_elements.entry_changed(self, index)
33 return len(self.__list)
35 def selectionChanged(self, index):
36 if self.disable_callbacks:
39 for x in self.onSelectionChanged:
44 return self.master is not None and self.master.current
46 current = property(getCurrent)
48 def setIndex(self, index):
49 if self.master is not None:
50 self.master.index = index
51 self.selectionChanged(index)
55 if self.master is not None:
56 return self.master.index
60 setCurrentIndex = setIndex
62 index = property(getIndex, setIndex)
65 if self.getIndex() + 1 >= self.count():
66 if self.enableWrapAround:
70 self.setIndex(self.index)
72 def selectPrevious(self):
73 if self.getIndex() - 1 < 0:
74 if self.enableWrapAround:
75 self.index = self.count() - 1
78 self.setIndex(self.index)
84 def setStyle(self, style):
86 self.changed((self.CHANGED_SPECIFIC, "style"))
88 style = property(getStyle, setStyle)
90 def updateList(self, list):
91 """Changes the list without changing the selection or emitting changed Events"""
92 assert len(list) == len(self.__list)
93 old_index = self.index
94 self.disable_callbacks = True
96 self.index = old_index
97 self.disable_callbacks = False