1 from Source import Source
2 from Tools.Event import Event
3 from Components.Element import cached
5 class List(Source, object):
6 """The datasource of a listbox. Currently, the format depends on the used converter. So
7 if you put a simple string list in here, you need to use a StringList converter, if you are
8 using a "multi content list styled"-list, you need to use the StaticMultiList converter, and
11 This has been done so another converter could convert the list to a different format, for example
13 def __init__(self, list = [ ], enableWrapAround = False, item_height = 25, fonts = [ ]):
16 self.onSelectionChanged = [ ]
17 self.item_height = item_height
19 self.disable_callbacks = False
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)
31 def selectionChanged(self, index):
32 if self.disable_callbacks:
35 for x in self.onSelectionChanged:
40 return self.master is not None and self.master.current
42 current = property(getCurrent)
44 def setIndex(self, index):
45 if self.master is not None:
46 self.master.index = index
50 if self.master is not None:
51 return self.master.index
55 setCurrentIndex = setIndex
57 index = property(getIndex, setIndex)
59 def updateList(self, list):
60 """Changes the list without changing the selection or emitting changed Events"""
61 assert len(list) == len(self.__list)
63 old_index = self.index
64 print "disable callback"
65 self.disable_callbacks = True
69 self.index = old_index
70 print "reenable callbacks"
71 self.disable_callbacks = False