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(index)
32 def modifyEntry(self, index, data):
33 self.__list[index] = data
34 self.entry_changed(index)
37 return len(self.__list)
39 def selectionChanged(self, index):
40 if self.disable_callbacks:
43 # update all non-master targets
44 for x in self.downstream_elements:
45 if x is not self.master:
48 for x in self.onSelectionChanged:
53 return self.master is not None and self.master.current
55 current = property(getCurrent)
57 def setIndex(self, index):
58 if self.master is not None:
59 self.master.index = index
60 self.selectionChanged(index)
64 if self.master is not None:
65 return self.master.index
69 setCurrentIndex = setIndex
71 index = property(getIndex, setIndex)
74 if self.getIndex() + 1 >= self.count():
75 if self.enableWrapAround:
79 self.setIndex(self.index)
81 def selectPrevious(self):
82 if self.getIndex() - 1 < 0:
83 if self.enableWrapAround:
84 self.index = self.count() - 1
87 self.setIndex(self.index)
93 def setStyle(self, style):
94 if self.__style != style:
96 self.changed((self.CHANGED_SPECIFIC, "style"))
98 style = property(getStyle, setStyle)
100 def updateList(self, list):
101 """Changes the list without changing the selection or emitting changed Events"""
102 assert len(list) == len(self.__list)
103 old_index = self.index
104 self.disable_callbacks = True
106 self.index = old_index
107 self.disable_callbacks = False