1 from enigma import eRCInput, getPrevAsciiCode
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 Tools.BoundFunction import boundFunction
10 class InputBox(Screen):
11 def __init__(self, session, title = "", windowTitle = _("Input"), **kwargs):
12 Screen.__init__(self, session)
14 self["text"] = Label(title)
15 self["input"] = Input(**kwargs)
16 self.onShown.append(boundFunction(self.setTitle, windowTitle))
18 self["actions"] = NumberActionMap(["WizardActions", "InputBoxActions", "InputAsciiActions", "KeyboardInputActions"],
20 "gotAsciiCode": self.gotAsciiCode,
24 "right": self.keyRight,
27 "deleteForward": self.keyDelete,
28 "deleteBackward": self.keyBackspace,
30 "toggleOverwrite": self.keyInsert,
31 "1": self.keyNumberGlobal,
32 "2": self.keyNumberGlobal,
33 "3": self.keyNumberGlobal,
34 "4": self.keyNumberGlobal,
35 "5": self.keyNumberGlobal,
36 "6": self.keyNumberGlobal,
37 "7": self.keyNumberGlobal,
38 "8": self.keyNumberGlobal,
39 "9": self.keyNumberGlobal,
40 "0": self.keyNumberGlobal
42 if self["input"].type == Input.TEXT:
43 rcinput = eRCInput.getInstance()
44 rcinput.setKeyboardMode(rcinput.kmAscii)
46 def gotAsciiCode(self):
47 self["input"].handleAscii(getPrevAsciiCode())
55 def keyNumberGlobal(self, number):
56 self["input"].number(number)
59 self["input"].delete()
62 rcinput = eRCInput.getInstance()
63 rcinput.setKeyboardMode(rcinput.kmNone)
64 self.close(self["input"].getText())
67 rcinput = eRCInput.getInstance()
68 rcinput.setKeyboardMode(rcinput.kmNone)
77 def keyBackspace(self):
78 self["input"].deleteBackward()
84 self["input"].toggleOverwrite()
86 class PinInput(InputBox):
87 def __init__(self, session, service = "", triesEntry = None, pinList = [], *args, **kwargs):
88 InputBox.__init__(self, session = session, text=" ", maxSize=True, type=Input.PIN, *args, **kwargs)
92 self.triesEntry = triesEntry
94 self.pinList = pinList
95 self["service"] = Label(service)
97 if self.getTries() == 0:
98 if (self.triesEntry.time.value + (self.waitTime * 60)) > time():
99 remaining = (self.triesEntry.time.value + (self.waitTime * 60)) - time()
100 remainingMinutes = int(remaining / 60)
101 remainingSeconds = int(remaining % 60)
102 self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.closePinCancel, MessageBox, _("You have to wait for") + " " + str(remainingMinutes) + " " + _("minutes and") + " " + str(remainingSeconds) + " " + _("seconds."), MessageBox.TYPE_ERROR))
106 self["tries"] = Label("")
107 self.onShown.append(self.showTries)
109 def gotAsciiCode(self):
110 if self["input"].currPos == len(self["input"]) - 1:
111 InputBox.gotAsciiCode(self)
114 InputBox.gotAsciiCode(self)
116 def keyNumberGlobal(self, number):
117 if self["input"].currPos == len(self["input"]) - 1:
118 InputBox.keyNumberGlobal(self, number)
121 InputBox.keyNumberGlobal(self, number)
123 def checkPin(self, pin):
124 if pin is not None and pin.find(" ") == -1 and int(pin) in self.pinList:
129 self.triesEntry.time.value = int(time())
130 self.triesEntry.time.save()
131 if self.checkPin(self["input"].getText()):
133 self.closePinCorrect()
137 if self.getTries() == 0:
142 def closePinWrong(self, *args):
143 rcinput = eRCInput.getInstance()
144 rcinput.setKeyboardMode(rcinput.kmNone)
148 def closePinCorrect(self, *args):
149 rcinput = eRCInput.getInstance()
150 rcinput.setKeyboardMode(rcinput.kmNone)
153 def closePinCancel(self, *args):
154 rcinput = eRCInput.getInstance()
155 rcinput.setKeyboardMode(rcinput.kmNone)
159 self.closePinCancel()
162 return self.triesEntry.tries.value
165 self.setTries(self.triesEntry.tries.value - 1)
168 def setTries(self, tries):
169 self.triesEntry.tries.value = tries
170 self.triesEntry.tries.save()
173 self["tries"].setText(_("Tries left:") + " " + str(self.getTries()))