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
21 def setList(self, list):
23 self.changed((self.CHANGED_ALL,))
25 list = property(lambda self: self.__list, setList)
27 def entry_changed(self, index):
28 if not self.disable_callbacks:
29 self.downstream_elements.entry_changed(self, index)
32 return len(self.__list)
34 def selectionChanged(self, index):
35 if self.disable_callbacks:
38 for x in self.onSelectionChanged:
43 return self.master is not None and self.master.current
45 current = property(getCurrent)
47 def setIndex(self, index):
48 if self.master is not None:
49 self.master.index = index
53 if self.master is not None:
54 return self.master.index
58 setCurrentIndex = setIndex
60 index = property(getIndex, setIndex)
63 if self.getIndex() + 1 >= self.count():
64 if self.enableWrapAround:
69 def selectPrevious(self):
70 if self.getIndex() - 1 < 0:
71 if self.enableWrapAround:
72 self.index = self.count() - 1
76 def updateList(self, list):
77 """Changes the list without changing the selection or emitting changed Events"""
78 assert len(list) == len(self.__list)
80 old_index = self.index
81 print "disable callback"
82 self.disable_callbacks = True
86 self.index = old_index
87 print "reenable callbacks"
88 self.disable_callbacks = False