ef8206af22c562ed33d109722b7ecbde2dca84a1
[enigma2.git] / lib / python / Components / Renderer / Listbox.py
1 from Renderer import Renderer
2 from enigma import eListbox
3
4 # the listbox renderer is the listbox, but no listbox content.
5 # the content will be provided by the source (or converter).
6
7 # the source should emit the 'changed' signal whenever
8 # it has a new listbox content.
9
10 # the source needs to have the 'content' property for the
11 # used listbox content
12
13 # it should expose exactly the non-content related functions
14 # of the eListbox class. more or less.
15
16 class Listbox(Renderer, object):
17         def __init__(self):
18                 Renderer.__init__(self)
19                 self.__content = None
20                 self.__wrap_around = False
21                 self.__selection_enabled = True
22
23         GUI_WIDGET = eListbox
24
25         def contentChanged(self):
26                 self.content = self.source.content
27
28         def setContent(self, content):
29                 self.__content = content
30                 if self.instance is not None:
31                         self.instance.setContent(self.__content)
32
33         content = property(lambda self: self.__content, setContent)
34
35         def postWidgetCreate(self, instance):
36                 if self.__content is not None:
37                         instance.setContent(self.__content)
38                 instance.selectionChanged.get().append(self.selectionChanged)
39                 self.wrap_around = self.wrap_around # trigger
40                 self.selection_enabled = self.selection_enabled # trigger
41
42         def setWrapAround(self, wrap_around):
43                 self.__wrap_around = wrap_around
44                 if self.instance is not None:
45                         self.instance.setWrapAround(self.__wrap_around)
46
47         wrap_around = property(lambda self: self.__wrap_around, setWrapAround)
48
49         def selectionChanged(self):
50                 self.source.selectionChanged(self.index)
51
52         def getIndex(self):
53                 if self.instance is None:
54                         return None
55                 return self.instance.getCurrentIndex()
56
57         def moveToIndex(self, index):
58                 if self.instance is None:
59                         return
60                 self.instance.moveSelectionTo(index)
61
62         index = property(getIndex, moveToIndex)
63
64         def move(self, direction):
65                 if self.instance is not None:
66                         self.instance.moveSelection(direction)
67
68         def setSelectionEnabled(self, enabled):
69                 self.__selection_enabled = enabled
70                 if self.instance is not None:
71                         self.instance.setSelectionEnable(enabled)
72
73         selection_enabled = property(lambda self: self.__selection_enabled, setSelectionEnabled)
74
75         def changed(self, what):
76                 self.content = self.source.content