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
22 self.__scrollbarMode = "showOnDemand"
26 def contentChanged(self):
27 self.content = self.source.content
29 def setContent(self, content):
30 self.__content = content
31 if self.instance is not None:
32 self.instance.setContent(self.__content)
34 content = property(lambda self: self.__content, setContent)
36 def postWidgetCreate(self, instance):
37 if self.__content is not None:
38 instance.setContent(self.__content)
39 instance.selectionChanged.get().append(self.selectionChanged)
40 self.wrap_around = self.wrap_around # trigger
41 self.selection_enabled = self.selection_enabled # trigger
42 self.scrollbarMode = self.scrollbarMode # trigger
44 def preWidgetRemove(self, instance):
45 instance.setContent(None)
46 instance.selectionChanged.get().remove(self.selectionChanged)
48 def setWrapAround(self, wrap_around):
49 self.__wrap_around = wrap_around
50 if self.instance is not None:
51 self.instance.setWrapAround(self.__wrap_around)
53 wrap_around = property(lambda self: self.__wrap_around, setWrapAround)
55 def selectionChanged(self):
56 self.source.selectionChanged(self.index)
59 if self.instance is None:
61 return self.instance.getCurrentIndex()
63 def moveToIndex(self, index):
64 if self.instance is None:
66 self.instance.moveSelectionTo(index)
68 index = property(getIndex, moveToIndex)
70 def move(self, direction):
71 if self.instance is not None:
72 self.instance.moveSelection(direction)
74 def setSelectionEnabled(self, enabled):
75 self.__selection_enabled = enabled
76 if self.instance is not None:
77 self.instance.setSelectionEnable(enabled)
79 selection_enabled = property(lambda self: self.__selection_enabled, setSelectionEnabled)
81 def setScrollbarMode(self, mode):
82 self.__scrollbarMode = mode
83 if self.instance is not None:
84 self.instance.setScrollbarMode(int(
90 scrollbarMode = property(lambda self: self.__scrollbarMode, setScrollbarMode)
92 def changed(self, what):
93 if hasattr(self.source, "selectionEnabled"):
94 self.selection_enabled = self.source.selectionEnabled
95 if hasattr(self.source, "scrollbarMode"):
96 self.scrollbarMode = self.source.scrollbarMode
97 if len(what) > 1 and isinstance(what[1], str) and what[1] == "style":
99 self.content = self.source.content
101 def entry_changed(self, index):
102 if self.instance is not None:
103 self.instance.entryChanged(index)