Merge remote branch 'origin/bug_429_remove_hardcoded_paths' into bug_429_remove_hardc...
[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                 self.__scrollbarMode = "showOnDemand"
23
24         GUI_WIDGET = eListbox
25
26         def contentChanged(self):
27                 self.content = self.source.content
28
29         def setContent(self, content):
30                 self.__content = content
31                 if self.instance is not None:
32                         self.instance.setContent(self.__content)
33
34         content = property(lambda self: self.__content, setContent)
35
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
43
44         def preWidgetRemove(self, instance):
45                 instance.setContent(None)
46                 instance.selectionChanged.get().remove(self.selectionChanged)
47
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)
52
53         wrap_around = property(lambda self: self.__wrap_around, setWrapAround)
54
55         def selectionChanged(self):
56                 self.source.selectionChanged(self.index)
57
58         def getIndex(self):
59                 if self.instance is None:
60                         return 0
61                 return self.instance.getCurrentIndex()
62
63         def moveToIndex(self, index):
64                 if self.instance is None:
65                         return
66                 self.instance.moveSelectionTo(index)
67
68         index = property(getIndex, moveToIndex)
69
70         def move(self, direction):
71                 if self.instance is not None:
72                         self.instance.moveSelection(direction)
73
74         def setSelectionEnabled(self, enabled):
75                 self.__selection_enabled = enabled
76                 if self.instance is not None:
77                         self.instance.setSelectionEnable(enabled)
78
79         selection_enabled = property(lambda self: self.__selection_enabled, setSelectionEnabled)
80
81         def setScrollbarMode(self, mode):
82                 self.__scrollbarMode = mode
83                 if self.instance is not None:
84                         self.instance.setScrollbarMode(int(
85                                 { "showOnDemand": 0,
86                                   "showAlways": 1,
87                                   "showNever": 2,
88                                 }[mode]))
89
90         scrollbarMode = property(lambda self: self.__scrollbarMode, setScrollbarMode)
91         
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":
98                         return
99                 self.content = self.source.content
100
101         def entry_changed(self, index):
102                 if self.instance is not None:
103                         self.instance.entryChanged(index)