1 from Renderer import Renderer
2 from enigma import eListbox
4 # the listbox renderer is the listbox, but no listbox content.
5 # the content will be provided by the source (or converter).
7 # the source should emit the 'changed' signal whenever
8 # it has a new listbox content.
10 # the source needs to have the 'content' property for the
11 # used listbox content
13 # it should expose exactly the non-content related functions
14 # of the eListbox class. more or less.
16 class Listbox(Renderer, object):
18 Renderer.__init__(self)
20 self.__wrap_around = False
21 self.__selection_enabled = True
25 def contentChanged(self):
26 self.content = self.source.content
28 def setContent(self, content):
29 self.__content = content
30 if self.instance is not None:
31 self.instance.setContent(self.__content)
33 content = property(lambda self: self.__content, setContent)
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
42 def preWidgetRemove(self, instance):
43 instance.setContent(None)
44 instance.selectionChanged.get().remove(self.selectionChanged)
46 def setWrapAround(self, wrap_around):
47 self.__wrap_around = wrap_around
48 if self.instance is not None:
49 self.instance.setWrapAround(self.__wrap_around)
51 wrap_around = property(lambda self: self.__wrap_around, setWrapAround)
53 def selectionChanged(self):
54 self.source.selectionChanged(self.index)
57 if self.instance is None:
59 return self.instance.getCurrentIndex()
61 def moveToIndex(self, index):
62 if self.instance is None:
64 self.instance.moveSelectionTo(index)
66 index = property(getIndex, moveToIndex)
68 def move(self, direction):
69 if self.instance is not None:
70 self.instance.moveSelection(direction)
72 def setSelectionEnabled(self, enabled):
73 self.__selection_enabled = enabled
74 if self.instance is not None:
75 self.instance.setSelectionEnable(enabled)
77 selection_enabled = property(lambda self: self.__selection_enabled, setSelectionEnabled)
79 def changed(self, what):
80 self.content = self.source.content