add parental control (still somehow buggy and some minor features missing... don...
[vuplus_dvbapp] / lib / python / Screens / InputBox.py
index 558cbc0..e73215c 100644 (file)
@@ -5,15 +5,17 @@ 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
 
 class InputBox(Screen):
-       def __init__(self, session, title = "", **kwargs):
+       def __init__(self, session, title = "", windowTitle = _("Input"), **kwargs):
                Screen.__init__(self, session)
 
                self["text"] = Label(title)
                self["input"] = Input(**kwargs)
+               self.onShown.append(boundFunction(self.setTitle, windowTitle))
 
                self["actions"] = NumberActionMap(["WizardActions", "InputBoxActions", "InputAsciiActions", "KeyboardInputActions"], 
                {
@@ -85,3 +87,50 @@ class InputBox(Screen):
 
        def keyInsert(self):
                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)
+               
+               self.showTries = True
+               if tries == 1:
+                       self.showTries = False
+
+               self.pinList = pinList
+               self["service"] = Label(service)
+               
+               self["tries"] = Label("")
+               self.onShown.append(boundFunction(self.setTries, tries))
+                               
+       def keyNumberGlobal(self, number):
+               if self["input"].currPos == len(self["input"]) - 1:
+                       InputBox.keyNumberGlobal(self, number)
+                       self.go()
+               else:
+                       InputBox.keyNumberGlobal(self, number)
+               
+       def checkPin(self, pin):
+               if pin is not None and int(pin) in self.pinList:
+                       return True
+               return False
+               
+       def go(self):
+               if self.checkPin(self["input"].getText()):
+                       self.close((True, self.tries))
+               else:
+                       self.keyHome()
+                       self.setTries(self.tries - 1)
+                       if self.tries == 0:
+                               self.close((False, self.tries))
+                       else:
+                               pass
+                       
+       def cancel(self):
+               rcinput = eRCInput.getInstance()
+               rcinput.setKeyboardMode(rcinput.kmNone)
+               self.close((None, self.tries))
+       
+       def setTries(self, tries):
+               self.tries = tries
+               if self.showTries:
+                       self["tries"].setText(_("Tries left:") + " " + str(tries))
\ No newline at end of file