class PopupInputDialog(InputBox): def __init__(self, session): InputBox.__init__(self, session) self.numti = NumericalTextInput() self.configText = ConfigText("", False) self.configText.help_window = self.session.instantiateDialog( PopupInputHelpDialog, self.numti) self.setTitle(_("Search:")) self.isShown = False # self.shown not working in oe2.2 def keyNumberGlobal(self, number): self.configText.handleKey(KEY_0 + number) self["input"].number(number) def show(self): self.isShown = True self["input"].setText("") self.configText.setValue("") self.configText.help_window.show() return Screen.show(self) def hide(self): self.isShown = False self.configText.help_window.hide() return Screen.hide(self) def _showHelpWindow(self): # prevent showing help window in oe2.2 pass
def handleKey(self, key, callback=None): if callback: ConfigText.handleKey(self, key, callback) else: ConfigText.handleKey(self, key) if key in [KEY_DELETE, KEY_BACKSPACE, KEY_ASCII, KEY_TIMEOUT]: self.getSuggestions()
def handleKey(self, key): if key in KEY_NUMBERS or key == KEY_ASCII: if key == KEY_ASCII: owr = False ascii = getPrevAsciiCode() if not 48 <= ascii <= 57 or not 65 <= ascii <= 70 or not 97 <= ascii <= 102: return newChar = unichr(ascii) else: owr = self.lastKey == getKeyNumber(key) newChar = self.getKey(getKeyNumber(key)) if self.allmarked: self.text = '0' * self.size self.allmarked = False self.marked_pos = 0 self.insertChar(newChar, self.marked_pos, True) else: ConfigText.handleKey(self, key) self.conform()
def handleKey(self, key): if key in KEY_NUMBERS or key == KEY_ASCII: if key == KEY_ASCII: owr = False ascii = getPrevAsciiCode() if not (48 <= ascii <= 57) or not(65 <= ascii <= 70) or not(97 <= ascii <= 102): return newChar = unichr(ascii) else: owr = self.lastKey == getKeyNumber(key) newChar = self.getKey(getKeyNumber(key)) if self.allmarked: self.text = "0" * self.size self.allmarked = False self.marked_pos = 0 self.insertChar(newChar, self.marked_pos, True) else: ConfigText.handleKey(self, key) self.conform()
class PopupInputDialog(InputBox): def __init__(self, session): InputBox.__init__(self, session) self.numti = NumericalTextInput() self.configText = ConfigText("", False) self.configText.help_window = self.session.instantiateDialog(PopupInputHelpDialog, self.numti) self.setTitle(_("Search:")) def keyNumberGlobal(self, number): self.configText.handleKey(KEY_0 + number) self["input"].number(number) def show(self): self["input"].setText("") self.configText.setValue("") self.configText.help_window.show() return Screen.show(self) def hide(self): self.configText.help_window.hide() return Screen.hide(self)
def handleKey(self, key): if not self.suggestionsListActivated: ConfigText.handleKey(self, key) if key in [KEY_DELETE, KEY_BACKSPACE, KEY_ASCII, KEY_TIMEOUT]: self.getSuggestions()
class AdvancedKeyBoard(VirtualKeyBoard, NumericalTextInput, SkinResolutionHelper): KEYBOARD = 0x01 NUM_KEYB = 0x02 BOTH = KEYBOARD | NUM_KEYB def __init__(self, session, title="", text=""): VirtualKeyBoard.__init__(self, session, title, text) NumericalTextInput.__init__(self, nextFunc=self.nextFunc) SkinResolutionHelper.__init__(self) self.configText = None if config.AdvancedMovieSelection.keyboard.value == "virtual": use = self.KEYBOARD elif config.AdvancedMovieSelection.keyboard.value == "numerical": use = self.NUM_KEYB else: use = self.BOTH if not use & self.KEYBOARD: # hide the keyboard self["list"].hide() # overwrite VirtualKeyBoard actions # make sure not overwrite any action of base class self["actions"] = ActionMap( [ "OkCancelActions", "WizardActions", "ColorActions", "KeyboardInputActions", "InputBoxActions", "InputAsciiActions", ], { "ok": self.__ok, "cancel": self.__cancel, "left": self.dummy, "right": self.dummy, "up": self.dummy, "down": self.dummy, "red": self.__cancel, "green": self.__ok, "yellow": self.dummy, "deleteBackward": self.dummy, "back": self.dummy, }, -2, ) if use & self.NUM_KEYB: self.timer = eTimer() self.timer.callback.append(self.timeout) self.configText = ConfigText("", False) if text: self.configText.text = text self.configText.marked_pos = len(text) self["config_actions"] = NumberActionMap( ["SetupActions", "InputAsciiActions", "KeyboardInputActions"], { "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 if use & self.KEYBOARD: self.selectedKey = self.getKeyIndex(u"OK") self.onLayoutFinish.append(self.__onLayoutFinish) self.onClose.append(self.__onClose) def __onLayoutFinish(self): self.setTitle(_("Advanced Movie Selection - Input help")) if self.configText: self.configText.help_window = self.session.instantiateDialog(AdvancedTextInputHelpDialog, self) self.configText.help_window.show() def __onClose(self): if self.configText and self.configText.help_window: self.session.deleteDialog(self.configText.help_window) self.configText.help_window = None def getKeyIndex(self, key): index = 0 for x in self.keys_list: for k in x: if k == key: return index index += 1 return index def buildVirtualKeyBoard(self, selectedKey=0): VirtualKeyBoard.buildVirtualKeyBoard(self, selectedKey=self.selectedKey) def dummy(self): pass def __ok(self): self.close(self["text"].getText()) def __cancel(self): self.close(None) def timeout(self): self.handleKey(KEY_TIMEOUT) self["text"].setMarkedPos(-1) def handleKey(self, key): if self.configText: self.configText.handleKey(key) if key in KEY_NUMBERS: self.timer.start(1000, 1) def keyNumberGlobal(self, number): self.handleKey(KEY_0 + number) self.getKey(number) self.text = self.configText.getText() self["text"].setText(self.configText.getText()) self["text"].setMarkedPos(self.configText.marked_pos) def okClicked(self): VirtualKeyBoard.okClicked(self) self["text"].setMarkedPos(-1) if self.configText: self.configText.text = self.text self.configText.marked_pos = len(self.text) def nextFunc(self): self["text"].setMarkedPos(-1)
class AdvancedKeyBoard(VirtualKeyBoard, NumericalTextInput): KEYBOARD = 0x01 NUM_KEYB = 0x02 BOTH = KEYBOARD | NUM_KEYB def __init__(self, session, title="", text=""): VirtualKeyBoard.__init__(self, session, title, text) NumericalTextInput.__init__(self, nextFunc=self.nextFunc) self.configText = None if config.AdvancedMovieSelection.keyboard.value == "virtual": use = self.KEYBOARD elif config.AdvancedMovieSelection.keyboard.value == "numerical": use = self.NUM_KEYB else: use = self.BOTH if not use & self.KEYBOARD: # hide the keyboard self["list"].hide() # overwrite VirtualKeyBoard actions # make sure not overwrite any action of base class self["actions"] = ActionMap(["OkCancelActions", "WizardActions", "ColorActions", "KeyboardInputActions", "InputBoxActions", "InputAsciiActions"], { "ok": self.__ok, "cancel": self.__cancel, "left": self.keyLeft, "right": self.keyRight, "up": self.keyHome, "down": self.keyEnd, "red": self.__cancel, "green": self.__ok, "yellow": self.dummy, "deleteForward": self.keyDelete, "deleteBackward": self.keyBackspace, "back": self.dummy }, -2) if use & self.NUM_KEYB: self.timer = xTimer() self.timer.addCallback(self.timeout) self.configText = ConfigText("", False) if text: self.configText.text = text self.configText.marked_pos = len(text) self["config_actions"] = NumberActionMap(["SetupActions", "InputAsciiActions", "KeyboardInputActions"], { "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 if use & self.KEYBOARD: self.selectedKey = self.getKeyIndex(u"OK") self.onLayoutFinish.append(self.__onLayoutFinish) self.onClose.append(self.__onClose) def __onLayoutFinish(self): self.setTitle(_("Advanced Movie Selection - Input help")) if self.configText: self.configText.help_window = self.session.instantiateDialog(AdvancedTextInputHelpDialog, self) self.configText.help_window.show() def __onClose(self): if self.configText and self.configText.help_window: self.session.deleteDialog(self.configText.help_window) self.configText.help_window = None def getKeyIndex(self, key): index = 0 for x in self.keys_list: for k in x: if k == key: return index index += 1 return index def buildVirtualKeyBoard(self, selectedKey=0): VirtualKeyBoard.buildVirtualKeyBoard(self, selectedKey=self.selectedKey) def dummy(self): pass def __ok(self): self.close(self["text"].getText()) def __cancel(self): self.close(None) def timeout(self): self.handleKey(KEY_TIMEOUT) self["text"].setMarkedPos(-1) def handleKey(self, key): if self.configText: self.configText.handleKey(key) if key in KEY_NUMBERS: self.timer.start(1000, 1) def __keyNumberGlobal(self, number): self.handleKey(number) #self.getKey(number) self.text = str(self.configText.getText()) self["text"].setText(self.text) self["text"].setMarkedPos(self.configText.marked_pos) def keyNumberGlobal(self, number): self.__keyNumberGlobal(KEY_0 + number) def okClicked(self): VirtualKeyBoard.okClicked(self) self["text"].setMarkedPos(-1) if self.configText: self.configText.text = self.text self.configText.marked_pos = len(self.text) def nextFunc(self): self["text"].setMarkedPos(-1) def keyLeft(self): self.__keyNumberGlobal(KEY_LEFT) def keyRight(self): self.__keyNumberGlobal(KEY_RIGHT) def keyHome(self): self.__keyNumberGlobal(KEY_HOME) def keyEnd(self): self.__keyNumberGlobal(KEY_END) def keyDelete(self): self.__keyNumberGlobal(KEY_DELETE) def keyBackspace(self): self.__keyNumberGlobal(KEY_BACKSPACE)
def handleKey(self, key): ConfigText.handleKey(self, key) if key in [KEY_DELETE, KEY_BACKSPACE, KEY_ASCII, KEY_TIMEOUT]: self.getSuggestions()