1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
3 from config import KEY_LEFT, KEY_RIGHT, KEY_HOME, KEY_END, KEY_0, KEY_DELETE, KEY_BACKSPACE, KEY_OK, KEY_TOGGLEOW, KEY_ASCII, KEY_TIMEOUT, KEY_NUMBERS, ConfigElement
4 from Components.ActionMap import NumberActionMap
5 from enigma import eListbox, eListboxPythonConfigContent, eRCInput, eTimer
6 from Screens.MessageBox import MessageBox
8 class ConfigList(HTMLComponent, GUIComponent, object):
9 def __init__(self, list, session = None):
10 GUIComponent.__init__(self)
11 self.l = eListboxPythonConfigContent()
12 self.l.setSeperation(200)
15 self.onSelectionChanged = [ ]
17 self.session = session
20 rcinput = eRCInput.getInstance()
21 rcinput.setKeyboardMode(rcinput.kmAscii)
22 self.timer.callback.append(self.timeout)
25 rcinput = eRCInput.getInstance()
26 rcinput.setKeyboardMode(rcinput.kmNone)
27 self.timer.callback.remove(self.timeout)
30 selection = self.getCurrent()
32 self.invalidateCurrent()
34 def handleKey(self, key):
35 selection = self.getCurrent()
36 if selection and selection[1].enabled:
37 selection[1].handleKey(key)
38 self.invalidateCurrent()
39 if key in KEY_NUMBERS:
40 self.timer.start(1000, 1)
43 return self.l.getCurrentSelection()
45 def getCurrentIndex(self):
46 return self.l.getCurrentSelectionIndex()
48 def setCurrentIndex(self, index):
49 if self.instance is not None:
50 self.instance.moveSelectionTo(index)
52 def invalidateCurrent(self):
53 self.l.invalidateEntry(self.l.getCurrentSelectionIndex())
55 def invalidate(self, entry):
56 # when the entry to invalidate does not exist, just ignore the request.
57 # this eases up conditional setup screens a lot.
58 if entry in self.__list:
59 self.l.invalidateEntry(self.__list.index(entry))
63 def selectionChanged(self):
65 self.current[1].onDeselect(self.session)
66 self.current = self.getCurrent()
68 self.current[1].onSelect(self.session)
69 for x in self.onSelectionChanged:
72 def postWidgetCreate(self, instance):
73 instance.selectionChanged.get().append(self.selectionChanged)
74 instance.setContent(self.l)
76 def preWidgetRemove(self, instance):
78 self.current[1].onDeselect(self.session)
79 instance.selectionChanged.get().remove(self.selectionChanged)
80 instance.setContent(None)
85 self.l.setList(self.__list)
89 assert isinstance(x[1], ConfigElement), "entry in ConfigList " + str(x[1]) + " must be a ConfigElement"
94 list = property(getList, setList)
97 self.handleKey(KEY_TIMEOUT)
102 is_changed |= x[1].isChanged()
106 class ConfigListScreen:
107 def __init__(self, list, session = None, on_change = None):
108 self["config_actions"] = NumberActionMap(["SetupActions", "InputAsciiActions", "KeyboardInputActions"],
110 "gotAsciiCode": self.keyGotAscii,
112 "left": self.keyLeft,
113 "right": self.keyRight,
114 "home": self.keyHome,
116 "deleteForward": self.keyDelete,
117 "deleteBackward": self.keyBackspace,
118 "toggleOverwrite": self.keyToggleOW,
119 "1": self.keyNumberGlobal,
120 "2": self.keyNumberGlobal,
121 "3": self.keyNumberGlobal,
122 "4": self.keyNumberGlobal,
123 "5": self.keyNumberGlobal,
124 "6": self.keyNumberGlobal,
125 "7": self.keyNumberGlobal,
126 "8": self.keyNumberGlobal,
127 "9": self.keyNumberGlobal,
128 "0": self.keyNumberGlobal
129 }, -1) # to prevent left/right overriding the listbox
131 self["config"] = ConfigList(list, session = session)
132 if on_change is not None:
133 self.__changed = on_change
135 self.__changed = lambda: None
138 self["config"].handleKey(KEY_OK)
141 self["config"].handleKey(KEY_LEFT)
145 self["config"].handleKey(KEY_RIGHT)
149 self["config"].handleKey(KEY_HOME)
153 self["config"].handleKey(KEY_END)
157 self["config"].handleKey(KEY_DELETE)
160 def keyBackspace(self):
161 self["config"].handleKey(KEY_BACKSPACE)
164 def keyToggleOW(self):
165 self["config"].handleKey(KEY_TOGGLEOW)
168 def keyGotAscii(self):
169 self["config"].handleKey(KEY_ASCII)
172 def keyNumberGlobal(self, number):
173 self["config"].handleKey(KEY_0 + number)
177 for x in self["config"].list:
180 # keySave and keyCancel are just provided in case you need them.
181 # you have to call them by yourself.
186 def cancelConfirm(self, result):
190 for x in self["config"].list:
195 if self["config"].isChanged():
196 self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))