[RecordTimer] fix repeat timer issue.
[vuplus_dvbapp] / lib / python / Screens / InputBox.py
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
8 from time import time
9
10 class InputBox(Screen):
11         def __init__(self, session, title = "", windowTitle = _("Input"), useableChars = None, **kwargs):
12                 Screen.__init__(self, session)
13
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)
19
20                 self["actions"] = NumberActionMap(["WizardActions", "InputBoxActions", "InputAsciiActions", "KeyboardInputActions"], 
21                 {
22                         "gotAsciiCode": self.gotAsciiCode,
23                         "ok": self.go,
24                         "back": self.cancel,
25                         "left": self.keyLeft,
26                         "right": self.keyRight,
27                         "home": self.keyHome,
28                         "end": self.keyEnd,
29                         "deleteForward": self.keyDelete,
30                         "deleteBackward": self.keyBackspace,
31                         "tab": self.keyTab,
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
43                 }, -1)
44
45                 if self["input"].type == Input.TEXT:
46                         self.onExecBegin.append(self.setKeyboardModeAscii)
47                 else:
48                         self.onExecBegin.append(self.setKeyboardModeNone)
49
50         def gotAsciiCode(self):
51                 self["input"].handleAscii(getPrevAsciiCode())
52
53         def keyLeft(self):
54                 self["input"].left()
55
56         def keyRight(self):
57                 self["input"].right()
58
59         def keyNumberGlobal(self, number):
60                 self["input"].number(number)
61
62         def keyDelete(self):
63                 self["input"].delete()
64
65         def go(self):
66                 self.close(self["input"].getText())
67
68         def cancel(self):
69                 self.close(None)
70
71         def keyHome(self):
72                 self["input"].home()
73
74         def keyEnd(self):
75                 self["input"].end()
76
77         def keyBackspace(self):
78                 self["input"].deleteBackward()
79
80         def keyTab(self):
81                 self["input"].tab()
82
83         def keyInsert(self):
84                 self["input"].toggleOverwrite()
85
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)
89                 
90                 self.waitTime = 15
91                 
92                 self.triesEntry = triesEntry
93                 
94                 self.pinList = pinList
95                 self["service"] = Label(service)
96                 
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 %s!") % (str(remainingMinutes) + " " + _("minutes") + ", " + str(remainingSeconds) + " " + _("seconds")), MessageBox.TYPE_ERROR))
103                         else:
104                                 self.setTries(3)
105
106                 self["tries"] = Label("")
107                 self.onShown.append(self.showTries)
108
109         def gotAsciiCode(self):
110                 if self["input"].currPos == len(self["input"]) - 1:
111                         InputBox.gotAsciiCode(self)
112                         self.go()
113                 else:
114                         InputBox.gotAsciiCode(self)
115
116         def keyNumberGlobal(self, number):
117                 if self["input"].currPos == len(self["input"]) - 1:
118                         InputBox.keyNumberGlobal(self, number)
119                         self.go()
120                 else:
121                         InputBox.keyNumberGlobal(self, number)
122                 
123         def checkPin(self, pin):
124                 if pin is not None and pin.find(" ") == -1 and int(pin) in self.pinList:
125                         return True
126                 return False
127                 
128         def go(self):
129                 self.triesEntry.time.value = int(time())
130                 self.triesEntry.time.save()
131                 if self.checkPin(self["input"].getText()):
132                         self.setTries(3)
133                         self.closePinCorrect()
134                 else:
135                         self.keyHome()
136                         self.decTries()
137                         if self.getTries() == 0:
138                                 self.closePinWrong()
139                         else:
140                                 pass
141         
142         def closePinWrong(self, *args):
143                 print "args:", args
144                 self.close(False)
145                 
146         def closePinCorrect(self, *args):
147                 self.close(True)
148                 
149         def closePinCancel(self, *args):
150                 self.close(None)
151                         
152         def cancel(self):
153                 self.closePinCancel()
154                 
155         def getTries(self):
156                 return self.triesEntry.tries.value
157
158         def decTries(self):
159                 self.setTries(self.triesEntry.tries.value - 1)
160                 self.showTries()
161                 
162         def setTries(self, tries):
163                 self.triesEntry.tries.value = tries
164                 self.triesEntry.tries.save()
165                                 
166         def showTries(self):
167                 self["tries"].setText(_("Tries left:") + " " + str(self.getTries()))