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
20 def setList(self, list):
22 self.changed((self.CHANGED_ALL,))
24 list = property(lambda self: self.__list, setList)
26 def entry_changed(self, index):
27 if not self.disable_callbacks:
28 self.downstream_elements.entry_changed(self, index)
31 return len(self.__list)
33 def selectionChanged(self, index):
34 if self.disable_callbacks:
37 for x in self.onSelectionChanged:
42 return self.master is not None and self.master.current
44 current = property(getCurrent)
46 def setIndex(self, index):
47 if self.master is not None:
48 self.master.index = index
52 if self.master is not None:
53 return self.master.index
57 setCurrentIndex = setIndex
59 index = property(getIndex, setIndex)
61 def updateList(self, list):
62 """Changes the list without changing the selection or emitting changed Events"""
63 assert len(list) == len(self.__list)
65 old_index = self.index
66 print "disable callback"
67 self.disable_callbacks = True
71 self.index = old_index
72 print "reenable callbacks"
73 self.disable_callbacks = False