fix bracket bug (thanks to Nix_niX)
[enigma2.git] / lib / python / Screens / InputBox.py
index e73215c..43b8a8b 100644 (file)
@@ -1,13 +1,11 @@
-from enigma import *
+from enigma import eRCInput, getPrevAsciiCode
 from Screens.Screen import Screen
 from Screens.MessageBox import MessageBox
 from Components.ActionMap import NumberActionMap
 from Components.Label import Label
 from Components.Input import Input
-from Components.GUIComponent import *
 from Tools.BoundFunction import boundFunction
-
-import os
+from time import time
 
 class InputBox(Screen):
        def __init__(self, session, title = "", windowTitle = _("Input"), **kwargs):
@@ -24,16 +22,12 @@ class InputBox(Screen):
                        "back": self.cancel,
                        "left": self.keyLeft,
                        "right": self.keyRight,
-                       "delete": self.keyDelete,
-                       "moveLeft": self.keyLeft,
-                       "moveRight": self.keyRight,
-                       "moveHome": self.keyHome,
-                       "moveEnd": self.keyEnd,
+                       "home": self.keyHome,
+                       "end": self.keyEnd,
                        "deleteForward": self.keyDelete,
                        "deleteBackward": self.keyBackspace,
                        "tab": self.keyTab,
                        "toggleOverwrite": self.keyInsert,
-                       "accept": self.go,
                        "1": self.keyNumberGlobal,
                        "2": self.keyNumberGlobal,
                        "3": self.keyNumberGlobal,
@@ -45,8 +39,9 @@ class InputBox(Screen):
                        "9": self.keyNumberGlobal,
                        "0": self.keyNumberGlobal
                }, -1)
-               rcinput = eRCInput.getInstance()
-               rcinput.setKeyboardMode(rcinput.kmAscii)
+               if self["input"].type == Input.TEXT:
+                       rcinput = eRCInput.getInstance()
+                       rcinput.setKeyboardMode(rcinput.kmAscii)
 
        def gotAsciiCode(self):
                self["input"].handleAscii(getPrevAsciiCode())
@@ -89,19 +84,35 @@ class InputBox(Screen):
                self["input"].toggleOverwrite()
 
 class PinInput(InputBox):
-       def __init__(self, session, service = "", tries = 1, pinList = [], *args, **kwargs):
-               InputBox.__init__(self, session = session, text="9876", maxSize=True, type=Input.PIN, *args, **kwargs)
+       def __init__(self, session, service = "", triesEntry = None, pinList = [], *args, **kwargs):
+               InputBox.__init__(self, session = session, text="    ", maxSize=True, type=Input.PIN, *args, **kwargs)
+               
+               self.waitTime = 15
+               
+               self.triesEntry = triesEntry
                
-               self.showTries = True
-               if tries == 1:
-                       self.showTries = False
-
                self.pinList = pinList
                self["service"] = Label(service)
                
+               if self.getTries() == 0:
+                       if (self.triesEntry.time.value + (self.waitTime * 60)) > time():
+                               remaining = (self.triesEntry.time.value + (self.waitTime * 60)) - time()
+                               remainingMinutes = int(remaining / 60)
+                               remainingSeconds = int(remaining % 60)
+                               self.onFirstExecBegin.append(boundFunction(self.session.openWithCallback, self.closePinCancel, MessageBox, _("You have to wait %s!") % (str(remainingMinutes) + " " + _("minutes") + ", " + str(remainingSeconds) + " " + _("seconds")), MessageBox.TYPE_ERROR))
+                       else:
+                               self.setTries(3)
+
                self["tries"] = Label("")
-               self.onShown.append(boundFunction(self.setTries, tries))
-                               
+               self.onShown.append(self.showTries)
+
+       def gotAsciiCode(self):
+               if self["input"].currPos == len(self["input"]) - 1:
+                       InputBox.gotAsciiCode(self)
+                       self.go()
+               else:
+                       InputBox.gotAsciiCode(self)
+
        def keyNumberGlobal(self, number):
                if self["input"].currPos == len(self["input"]) - 1:
                        InputBox.keyNumberGlobal(self, number)
@@ -110,27 +121,53 @@ class PinInput(InputBox):
                        InputBox.keyNumberGlobal(self, number)
                
        def checkPin(self, pin):
-               if pin is not None and int(pin) in self.pinList:
+               if pin is not None and pin.find(" ") == -1 and int(pin) in self.pinList:
                        return True
                return False
                
        def go(self):
+               self.triesEntry.time.value = int(time())
+               self.triesEntry.time.save()
                if self.checkPin(self["input"].getText()):
-                       self.close((True, self.tries))
+                       self.setTries(3)
+                       self.closePinCorrect()
                else:
                        self.keyHome()
-                       self.setTries(self.tries - 1)
-                       if self.tries == 0:
-                               self.close((False, self.tries))
+                       self.decTries()
+                       if self.getTries() == 0:
+                               self.closePinWrong()
                        else:
                                pass
-                       
-       def cancel(self):
+       
+       def closePinWrong(self, *args):
                rcinput = eRCInput.getInstance()
                rcinput.setKeyboardMode(rcinput.kmNone)
-               self.close((None, self.tries))
-       
+               print "args:", args
+               self.close(False)
+               
+       def closePinCorrect(self, *args):
+               rcinput = eRCInput.getInstance()
+               rcinput.setKeyboardMode(rcinput.kmNone)
+               self.close(True)
+               
+       def closePinCancel(self, *args):
+               rcinput = eRCInput.getInstance()
+               rcinput.setKeyboardMode(rcinput.kmNone)
+               self.close(None)
+                       
+       def cancel(self):
+               self.closePinCancel()
+               
+       def getTries(self):
+               return self.triesEntry.tries.value
+
+       def decTries(self):
+               self.setTries(self.triesEntry.tries.value - 1)
+               self.showTries()
+               
        def setTries(self, tries):
-               self.tries = tries
-               if self.showTries:
-                       self["tries"].setText(_("Tries left:") + " " + str(tries))
\ No newline at end of file
+               self.triesEntry.tries.value = tries
+               self.triesEntry.tries.save()
+                               
+       def showTries(self):
+               self["tries"].setText(_("Tries left:") + " " + str(self.getTries()))