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