2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Components.ActionMap import NumberActionMap
5 from Components.Label import Label
6 from Components.Input import Input
7 from Components.GUIComponent import *
8 from Tools.BoundFunction import boundFunction
12 class InputBox(Screen):
13 def __init__(self, session, title = "", windowTitle = _("Input"), **kwargs):
14 Screen.__init__(self, session)
16 self["text"] = Label(title)
17 self["input"] = Input(**kwargs)
18 self.onShown.append(boundFunction(self.setTitle, windowTitle))
20 self["actions"] = NumberActionMap(["WizardActions", "InputBoxActions", "InputAsciiActions", "KeyboardInputActions"],
22 "gotAsciiCode": self.gotAsciiCode,
26 "right": self.keyRight,
27 "delete": self.keyDelete,
28 "moveLeft": self.keyLeft,
29 "moveRight": self.keyRight,
30 "moveHome": self.keyHome,
31 "moveEnd": self.keyEnd,
32 "deleteForward": self.keyDelete,
33 "deleteBackward": self.keyBackspace,
35 "toggleOverwrite": self.keyInsert,
37 "1": self.keyNumberGlobal,
38 "2": self.keyNumberGlobal,
39 "3": self.keyNumberGlobal,
40 "4": self.keyNumberGlobal,
41 "5": self.keyNumberGlobal,
42 "6": self.keyNumberGlobal,
43 "7": self.keyNumberGlobal,
44 "8": self.keyNumberGlobal,
45 "9": self.keyNumberGlobal,
46 "0": self.keyNumberGlobal
48 rcinput = eRCInput.getInstance()
49 rcinput.setKeyboardMode(rcinput.kmAscii)
51 def gotAsciiCode(self):
52 self["input"].handleAscii(getPrevAsciiCode())
60 def keyNumberGlobal(self, number):
61 self["input"].number(number)
64 self["input"].delete()
67 rcinput = eRCInput.getInstance()
68 rcinput.setKeyboardMode(rcinput.kmNone)
69 self.close(self["input"].getText())
72 rcinput = eRCInput.getInstance()
73 rcinput.setKeyboardMode(rcinput.kmNone)
82 def keyBackspace(self):
83 self["input"].deleteBackward()
89 self["input"].toggleOverwrite()
91 class PinInput(InputBox):
92 def __init__(self, session, service = "", tries = 1, pinList = [], *args, **kwargs):
93 InputBox.__init__(self, session = session, text="9876", maxSize=True, type=Input.PIN, *args, **kwargs)
97 self.showTries = False
99 self.pinList = pinList
100 self["service"] = Label(service)
102 self["tries"] = Label("")
103 self.onShown.append(boundFunction(self.setTries, tries))
105 def keyNumberGlobal(self, number):
106 if self["input"].currPos == len(self["input"]) - 1:
107 InputBox.keyNumberGlobal(self, number)
110 InputBox.keyNumberGlobal(self, number)
112 def checkPin(self, pin):
113 if pin is not None and int(pin) in self.pinList:
118 if self.checkPin(self["input"].getText()):
119 self.close((True, self.tries))
122 self.setTries(self.tries - 1)
124 self.close((False, self.tries))
129 rcinput = eRCInput.getInstance()
130 rcinput.setKeyboardMode(rcinput.kmNone)
131 self.close((None, self.tries))
133 def setTries(self, tries):
136 self["tries"].setText(_("Tries left:") + " " + str(tries))