seperate summary screen for movie playeer
[enigma2.git] / lib / python / Screens / InputBox.py
index 558cbc01bac7dd2b3b67c2e4c6797443783de85d..6cdb42ee8da47f47e5fba6eaec372a94a8dd1ac0 100644 (file)
@@ -1,19 +1,19 @@
-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 *
-
-import os
+from Tools.BoundFunction import boundFunction
+from time import time
 
 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 +85,81 @@ class InputBox(Screen):
 
        def keyInsert(self):
                self["input"].toggleOverwrite()
+
+class PinInput(InputBox):
+       def __init__(self, session, service = "", triesEntry = None, pinList = [], *args, **kwargs):
+               InputBox.__init__(self, session = session, text="9876", maxSize=True, type=Input.PIN, *args, **kwargs)
+               
+               self.waitTime = 15
+               
+               self.triesEntry = triesEntry
+               
+               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 for") + " " + str(remainingMinutes) + " " + _("minutes and") + " " + str(remainingSeconds) + " " + _("seconds."), MessageBox.TYPE_ERROR))
+                       else:
+                               self.setTries(3)
+
+               self["tries"] = Label("")
+               self.onShown.append(self.showTries)
+
+       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):
+               self.triesEntry.time.value = int(time())
+               self.triesEntry.time.save()
+               if self.checkPin(self["input"].getText()):
+                       self.setTries(3)
+                       self.closePinCorrect()
+               else:
+                       self.keyHome()
+                       self.decTries()
+                       if self.getTries() == 0:
+                               self.closePinWrong()
+                       else:
+                               pass
+       
+       def closePinWrong(self, *args):
+               print "args:", args
+               self.close(False)
+               
+       def closePinCorrect(self, *args):
+               self.close(True)
+               
+       def closePinCancel(self, *args):
+               self.close(None)
+                       
+       def cancel(self):
+               rcinput = eRCInput.getInstance()
+               rcinput.setKeyboardMode(rcinput.kmNone)
+               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.triesEntry.tries.value = tries
+               self.triesEntry.tries.save()
+                               
+       def showTries(self):
+               self["tries"].setText(_("Tries left:") + " " + str(self.getTries()))