whitespace fixup
[vuplus_dvbapp] / lib / python / Components / Sources / List.py
1 from Source import Source
2 from Tools.Event import Event
3 from Components.Element import cached
4
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
9 setup the "fonts". 
10
11 This has been done so another converter could convert the list to a different format, for example
12 to generate HTML."""
13         def __init__(self, list = [ ], enableWrapAround = False, item_height = 25, fonts = [ ]):
14                 Source.__init__(self)
15                 self.__list = list
16                 self.onSelectionChanged = [ ]
17                 self.item_height = item_height
18                 self.fonts = fonts
19                 self.disable_callbacks = False
20
21         def setList(self, list):
22                 self.__list = list
23                 self.changed((self.CHANGED_ALL,))
24
25         list = property(lambda self: self.__list, setList)
26
27         def entry_changed(self, index):
28                 if not self.disable_callbacks:
29                         self.downstream_elements.entry_changed(self, index)
30
31         def selectionChanged(self, index):
32                 if self.disable_callbacks:
33                         return
34
35                 for x in self.onSelectionChanged:
36                         x()
37
38         @cached
39         def getCurrent(self):
40                 return self.master is not None and self.master.current
41
42         current = property(getCurrent)
43
44         def setIndex(self, index):
45                 if self.master is not None:
46                         self.master.index = index
47
48         @cached
49         def getIndex(self):
50                 if self.master is not None:
51                         return self.master.index
52                 else:
53                         return -1
54
55         setCurrentIndex = setIndex
56
57         index = property(getIndex, setIndex)
58
59         def updateList(self, list):
60                 """Changes the list without changing the selection or emitting changed Events"""
61                 assert len(list) == len(self.__list)
62                 print "get old index"
63                 old_index = self.index
64                 print "disable callback"
65                 self.disable_callbacks = True
66                 print "set list"
67                 self.list = list
68                 print "set index"
69                 self.index = old_index
70                 print "reenable callbacks"
71                 self.disable_callbacks = False
72                 print "done"