X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/aa3e781f31a04223416f0a34b25ab95fc0bef429..dd6c331e2a83af4e911fecc70c47b74256ea3419:/lib/python/Components/ConfigList.py diff --git a/lib/python/Components/ConfigList.py b/lib/python/Components/ConfigList.py old mode 100644 new mode 100755 index a2bdcb0b..60785802 --- a/lib/python/Components/ConfigList.py +++ b/lib/python/Components/ConfigList.py @@ -1,32 +1,233 @@ -from HTMLComponent import * -from GUIComponent import * -from config import * +from HTMLComponent import HTMLComponent +from GUIComponent import GUIComponent +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, ConfigText, ConfigPassword +from Components.ActionMap import NumberActionMap, ActionMap +from enigma import eListbox, eListboxPythonConfigContent, eRCInput, eTimer +from Screens.MessageBox import MessageBox -from enigma import eListbox, eListboxPythonConfigContent - -class ConfigList(HTMLComponent, GUIComponent): - def __init__(self, list): +class ConfigList(HTMLComponent, GUIComponent, object): + def __init__(self, list, session = None): GUIComponent.__init__(self) self.l = eListboxPythonConfigContent() - self.l.setList(list) - self.l.setSeperation(100) - + self.l.setSeperation(200) + self.timer = eTimer() + self.list = list + self.onSelectionChanged = [ ] + self.current = None + self.session = session + + def execBegin(self): + rcinput = eRCInput.getInstance() + rcinput.setKeyboardMode(rcinput.kmAscii) + self.timer.callback.append(self.timeout) + + def execEnd(self): + rcinput = eRCInput.getInstance() + rcinput.setKeyboardMode(rcinput.kmNone) + self.timer.callback.remove(self.timeout) + def toggle(self): selection = self.getCurrent() selection[1].toggle() self.invalidateCurrent() - + + def handleKey(self, key): + selection = self.getCurrent() + if selection and selection[1].enabled: + selection[1].handleKey(key) + self.invalidateCurrent() + if key in KEY_NUMBERS: + self.timer.start(1000, 1) + def getCurrent(self): return self.l.getCurrentSelection() + def getCurrentIndex(self): + return self.l.getCurrentSelectionIndex() + + def setCurrentIndex(self, index): + if self.instance is not None: + self.instance.moveSelectionTo(index) + def invalidateCurrent(self): self.l.invalidateEntry(self.l.getCurrentSelectionIndex()) + + def invalidate(self, entry): + # when the entry to invalidate does not exist, just ignore the request. + # this eases up conditional setup screens a lot. + if entry in self.__list: + self.l.invalidateEntry(self.__list.index(entry)) + + GUI_WIDGET = eListbox + + def selectionChanged(self): + if self.current: + self.current[1].onDeselect(self.session) + self.current = self.getCurrent() + if self.current: + self.current[1].onSelect(self.session) + + for x in self.onSelectionChanged: + x() + + def postWidgetCreate(self, instance): + instance.selectionChanged.get().append(self.selectionChanged) + instance.setContent(self.l) - def GUIcreate(self, parent, skindata): - self.instance = eListbox(parent) - self.instance.setContent(self.l) + def preWidgetRemove(self, instance): + if self.current: + self.current[1].onDeselect(self.session) + instance.selectionChanged.get().remove(self.selectionChanged) + instance.setContent(None) - def GUIdelete(self): - self.instance.setContent(None) - self.instance = None + def setList(self, l): + self.timer.stop() + self.__list = l + self.l.setList(self.__list) + + if l is not None: + for x in l: + assert isinstance(x[1], ConfigElement), "entry in ConfigList " + str(x[1]) + " must be a ConfigElement" + + def getList(self): + return self.__list + + list = property(getList, setList) + + def timeout(self): + self.handleKey(KEY_TIMEOUT) + + def isChanged(self): + is_changed = False + for x in self.list: + is_changed |= x[1].isChanged() + + return is_changed + +class ConfigListScreen: + def __init__(self, list, session = None, on_change = None): + self["config_actions"] = NumberActionMap(["SetupActions", "InputAsciiActions", "KeyboardInputActions"], + { + "gotAsciiCode": self.keyGotAscii, + "ok": self.keyOK, + "left": self.keyLeft, + "right": self.keyRight, + "home": self.keyHome, + "end": self.keyEnd, + "deleteForward": self.keyDelete, + "deleteBackward": self.keyBackspace, + "toggleOverwrite": self.keyToggleOW, + "1": self.keyNumberGlobal, + "2": self.keyNumberGlobal, + "3": self.keyNumberGlobal, + "4": self.keyNumberGlobal, + "5": self.keyNumberGlobal, + "6": self.keyNumberGlobal, + "7": self.keyNumberGlobal, + "8": self.keyNumberGlobal, + "9": self.keyNumberGlobal, + "0": self.keyNumberGlobal + }, -1) # to prevent left/right overriding the listbox + + self["VirtualKB"] = ActionMap(["VirtualKeyboardActions"], + { + "showVirtualKeyboard": self.KeyText, + }, -2) + self["VirtualKB"].setEnabled(False) + + self["config"] = ConfigList(list, session = session) + + if on_change is not None: + self.__changed = on_change + else: + self.__changed = lambda: None + + if not self.handleInputHelpers in self["config"].onSelectionChanged: + self["config"].onSelectionChanged.append(self.handleInputHelpers) + + def handleInputHelpers(self): + if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword): + if self.has_key("VKeyIcon"): + self["VirtualKB"].setEnabled(True) + self["VKeyIcon"].boolean = True + if self.has_key("HelpWindow"): + if self["config"].getCurrent()[1].help_window.instance is not None: + helpwindowpos = self["HelpWindow"].getPosition() + from enigma import ePoint + self["config"].getCurrent()[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1])) + else: + if self.has_key("VKeyIcon"): + self["VirtualKB"].setEnabled(False) + self["VKeyIcon"].boolean = False + + def KeyText(self): + from Screens.VirtualKeyBoard import VirtualKeyBoard + self.session.openWithCallback(self.VirtualKeyBoardCallback, VirtualKeyBoard, title = self["config"].getCurrent()[0], text = self["config"].getCurrent()[1].getValue()) + + def VirtualKeyBoardCallback(self, callback = None): + if callback is not None and len(callback): + self["config"].getCurrent()[1].setValue(callback) + self["config"].invalidate(self["config"].getCurrent()) + + def keyOK(self): + self["config"].handleKey(KEY_OK) + + def keyLeft(self): + self["config"].handleKey(KEY_LEFT) + self.__changed() + + def keyRight(self): + self["config"].handleKey(KEY_RIGHT) + self.__changed() + + def keyHome(self): + self["config"].handleKey(KEY_HOME) + self.__changed() + + def keyEnd(self): + self["config"].handleKey(KEY_END) + self.__changed() + + def keyDelete(self): + self["config"].handleKey(KEY_DELETE) + self.__changed() + + def keyBackspace(self): + self["config"].handleKey(KEY_BACKSPACE) + self.__changed() + + def keyToggleOW(self): + self["config"].handleKey(KEY_TOGGLEOW) + self.__changed() + + def keyGotAscii(self): + self["config"].handleKey(KEY_ASCII) + self.__changed() + + def keyNumberGlobal(self, number): + self["config"].handleKey(KEY_0 + number) + self.__changed() + + def saveAll(self): + for x in self["config"].list: + x[1].save() + + # keySave and keyCancel are just provided in case you need them. + # you have to call them by yourself. + def keySave(self): + self.saveAll() + self.close() + + def cancelConfirm(self, result): + if not result: + return + + for x in self["config"].list: + x[1].cancel() + self.close() + def keyCancel(self): + if self["config"].isChanged(): + self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?")) + else: + self.close()