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"), useableChars = None, **kwargs):
12 Screen.__init__(self, session)
14 self["text"] = Label(title)
15 self["input"] = Input(**kwargs)
16 self.onShown.append(boundFunction(self.setTitle, windowTitle))
17 if useableChars is not None:
18 self["input"].setUseableChars(useableChars)
20 self["actions"] = NumberActionMap(["WizardActions", "InputBoxActions", "InputAsciiActions", "KeyboardInputActions"],
22 "gotAsciiCode": self.gotAsciiCode,
26 "right": self.keyRight,
29 "deleteForward": self.keyDelete,
30 "deleteBackward": self.keyBackspace,
32 "toggleOverwrite": self.keyInsert,
33 "1": self.keyNumberGlobal,
34 "2": self.keyNumberGlobal,
35 "3": self.keyNumberGlobal,
36 "4": self.keyNumberGlobal,
37 "5": self.keyNumberGlobal,
38 "6": self.keyNumberGlobal,
39 "7": self.keyNumberGlobal,
40 "8": self.keyNumberGlobal,
41 "9": self.keyNumberGlobal,
42 "0": self.keyNumberGlobal
44 if self["input"].type == Input.TEXT:
45 rcinput = eRCInput.getInstance()
46 rcinput.setKeyboardMode(rcinput.kmAscii)
48 def gotAsciiCode(self):
49 self["input"].handleAscii(getPrevAsciiCode())
57 def keyNumberGlobal(self, number):
58 self["input"].number(number)
61 self["input"].delete()
64 rcinput = eRCInput.getInstance()
65 rcinput.setKeyboardMode(rcinput.kmNone)
66 self.close(self["input"].getText())
69 rcinput = eRCInput.getInstance()
70 rcinput.setKeyboardMode(rcinput.kmNone)
79 def keyBackspace(self):
80 self["input"].deleteBackward()
86 self["input"].toggleOverwrite()
88 class PinInput(InputBox):
89 def __init__(self, session, service = "", triesEntry = None, pinList = [], *args, **kwargs):
90 InputBox.__init__(self, session = session, text=" ", maxSize=True, type=Input.PIN, *args, **kwargs)
94 self.triesEntry = triesEntry
96 self.pinList = pinList
97 self["service"] = Label(service)
99 if self.getTries() == 0:
100 if (self.triesEntry.time.value + (self.waitTime * 60)) > time():
101 remaining = (self.triesEntry.time.value + (self.waitTime * 60)) - time()
102 remainingMinutes = int(remaining / 60)
103 remainingSeconds = int(remaining % 60)
104 self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.closePinCancel, MessageBox, _("You have to wait %s!") % (str(remainingMinutes) + " " + _("minutes") + ", " + str(remainingSeconds) + " " + _("seconds")), MessageBox.TYPE_ERROR))
108 self["tries"] = Label("")
109 self.onShown.append(self.showTries)
111 def gotAsciiCode(self):
112 if self["input"].currPos == len(self["input"]) - 1:
113 InputBox.gotAsciiCode(self)
116 InputBox.gotAsciiCode(self)
118 def keyNumberGlobal(self, number):
119 if self["input"].currPos == len(self["input"]) - 1:
120 InputBox.keyNumberGlobal(self, number)
123 InputBox.keyNumberGlobal(self, number)
125 def checkPin(self, pin):
126 if pin is not None and pin.find(" ") == -1 and int(pin) in self.pinList:
131 self.triesEntry.time.value = int(time())
132 self.triesEntry.time.save()
133 if self.checkPin(self["input"].getText()):
135 self.closePinCorrect()
139 if self.getTries() == 0:
144 def closePinWrong(self, *args):
145 rcinput = eRCInput.getInstance()
146 rcinput.setKeyboardMode(rcinput.kmNone)
150 def closePinCorrect(self, *args):
151 rcinput = eRCInput.getInstance()
152 rcinput.setKeyboardMode(rcinput.kmNone)
155 def closePinCancel(self, *args):
156 rcinput = eRCInput.getInstance()
157 rcinput.setKeyboardMode(rcinput.kmNone)
161 self.closePinCancel()
164 return self.triesEntry.tries.value
167 self.setTries(self.triesEntry.tries.value - 1)
170 def setTries(self, tries):
171 self.triesEntry.tries.value = tries
172 self.triesEntry.tries.save()
175 self["tries"].setText(_("Tries left:") + " " + str(self.getTries()))