experimental: add possibility to add user skins in /etc/enigma2/skin_user.xml
[enigma2.git] / lib / python / Components / Sources / List.py
1 from Source import Source
2 from Components.Element import cached
3
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
8 setup the "fonts". 
9
10 This has been done so another converter could convert the list to a different format, for example
11 to generate HTML."""
12         def __init__(self, list = [ ], enableWrapAround = False, item_height = 25, fonts = [ ]):
13                 Source.__init__(self)
14                 self.__list = list
15                 self.onSelectionChanged = [ ]
16                 self.item_height = item_height
17                 self.fonts = fonts
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
21
22         def setList(self, list):
23                 self.__list = list
24                 self.changed((self.CHANGED_ALL,))
25
26         list = property(lambda self: self.__list, setList)
27
28         def entry_changed(self, index):
29                 if not self.disable_callbacks:
30                         self.downstream_elements.entry_changed(self, index)
31
32         def modifyEntry(self, index, data):
33                 self.__list[index] = data
34                 self.entry_changed(index)
35
36         def count(self):
37                 return len(self.__list)
38
39         def selectionChanged(self, index):
40                 if self.disable_callbacks:
41                         return
42
43                 for x in self.onSelectionChanged:
44                         x()
45
46         @cached
47         def getCurrent(self):
48                 return self.master is not None and self.master.current
49
50         current = property(getCurrent)
51
52         def setIndex(self, index):
53                 if self.master is not None:
54                         self.master.index = index
55                         self.selectionChanged(index)
56
57         @cached
58         def getIndex(self):
59                 if self.master is not None:
60                         return self.master.index
61                 else:
62                         return None
63
64         setCurrentIndex = setIndex
65
66         index = property(getIndex, setIndex)
67         
68         def selectNext(self):
69                 if self.getIndex() + 1 >= self.count():
70                         if self.enableWrapAround:
71                                 self.index = 0
72                 else:
73                         self.index += 1
74                 self.setIndex(self.index)
75
76         def selectPrevious(self):
77                 if self.getIndex() - 1 < 0:
78                         if self.enableWrapAround:
79                                 self.index = self.count() - 1
80                 else:
81                         self.index -= 1
82                 self.setIndex(self.index)
83
84         @cached
85         def getStyle(self):
86                 return self.__style
87
88         def setStyle(self, style):
89                 self.__style = style
90                 self.changed((self.CHANGED_SPECIFIC, "style"))
91
92         style = property(getStyle, setStyle)
93
94         def updateList(self, list):
95                 """Changes the list without changing the selection or emitting changed Events"""
96                 assert len(list) == len(self.__list)
97                 old_index = self.index
98                 self.disable_callbacks = True
99                 self.list = list
100                 self.index = old_index
101                 self.disable_callbacks = False