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,
25 "delete": self.keyDelete,
26 "moveLeft": self.keyLeft,
27 "moveRight": self.keyRight,
28 "moveHome": self.keyHome,
29 "moveEnd": self.keyEnd,
30 "deleteForward": self.keyDelete,
31 "deleteBackward": self.keyBackspace,
33 "toggleOverwrite": self.keyInsert,
35 "1": self.keyNumberGlobal,
36 "2": self.keyNumberGlobal,
37 "3": self.keyNumberGlobal,
38 "4": self.keyNumberGlobal,
39 "5": self.keyNumberGlobal,
40 "6": self.keyNumberGlobal,
41 "7": self.keyNumberGlobal,
42 "8": self.keyNumberGlobal,
43 "9": self.keyNumberGlobal,
44 "0": self.keyNumberGlobal
46 rcinput = eRCInput.getInstance()
47 rcinput.setKeyboardMode(rcinput.kmAscii)
49 def gotAsciiCode(self):
50 self["input"].handleAscii(getPrevAsciiCode())
58 def keyNumberGlobal(self, number):
59 self["input"].number(number)
62 self["input"].delete()
65 rcinput = eRCInput.getInstance()
66 rcinput.setKeyboardMode(rcinput.kmNone)
67 self.close(self["input"].getText())
70 rcinput = eRCInput.getInstance()
71 rcinput.setKeyboardMode(rcinput.kmNone)
80 def keyBackspace(self):
81 self["input"].deleteBackward()
87 self["input"].toggleOverwrite()
89 class PinInput(InputBox):
90 def __init__(self, session, service = "", triesEntry = None, pinList = [], *args, **kwargs):
91 InputBox.__init__(self, session = session, text="9876", maxSize=True, type=Input.PIN, *args, **kwargs)
95 self.triesEntry = triesEntry
97 self.pinList = pinList
98 self["service"] = Label(service)
100 if self.getTries() == 0:
101 if (self.triesEntry.time.value + (self.waitTime * 60)) > time():
102 remaining = (self.triesEntry.time.value + (self.waitTime * 60)) - time()
103 remainingMinutes = int(remaining / 60)
104 remainingSeconds = int(remaining % 60)
105 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))
109 self["tries"] = Label("")
110 self.onShown.append(self.showTries)
112 def keyNumberGlobal(self, number):
113 if self["input"].currPos == len(self["input"]) - 1:
114 InputBox.keyNumberGlobal(self, number)
117 InputBox.keyNumberGlobal(self, number)
119 def checkPin(self, pin):
120 if pin is not None and int(pin) in self.pinList:
125 self.triesEntry.time.value = int(time())
126 self.triesEntry.time.save()
127 if self.checkPin(self["input"].getText()):
129 self.closePinCorrect()
133 if self.getTries() == 0:
138 def closePinWrong(self, *args):
142 def closePinCorrect(self, *args):
145 def closePinCancel(self, *args):
149 rcinput = eRCInput.getInstance()
150 rcinput.setKeyboardMode(rcinput.kmNone)
151 self.closePinCancel()
154 return self.triesEntry.tries.value
157 self.setTries(self.triesEntry.tries.value - 1)
160 def setTries(self, tries):
161 self.triesEntry.tries.value = tries
162 self.triesEntry.tries.save()
165 self["tries"].setText(_("Tries left:") + " " + str(self.getTries()))