don't bluescreen on pressing up/down when cursor is on empty position in an input box
[enigma2.git] / lib / python / Components / Input.py
index d3b06612b42d417b7f4efe64ba3323244083769f..0bd13059e3ad69d75bcb7dbb4a0ce26afcab7309 100644 (file)
@@ -6,20 +6,34 @@ from enigma import eLabel
 
 from Tools.NumericalTextInput import NumericalTextInput
 
-class Input(HTMLComponent, GUIComponent, VariableText):
-       def __init__(self, text=""):
+class Input(VariableText, HTMLComponent, GUIComponent):
+       TEXT = 0
+       PIN = 1
+       NUMBER = 2      
+       
+       def __init__(self, text="", maxSize = False, type = TEXT):
                GUIComponent.__init__(self)
                VariableText.__init__(self)
                self.numericalTextInput = NumericalTextInput(self.right)
+               self.type = type
+               self.maxSize = maxSize
                self.currPos = 0
                self.text = text
                self.update()
 
        def update(self):
-               self.setText(self.text[0:self.currPos] + "_" + self.text[self.currPos] + "_" + self.text[self.currPos + 1:])
+               self.setMarkedPos(self.currPos)
+               text = self.text
+               if self.type == self.PIN:
+                       text = "*" * len(self.text)
+               self.setText(text)
+               #self.setText(self.text[0:self.currPos] + "_" + self.text[self.currPos] + "_" + self.text[self.currPos + 1:])
+
+       def getText(self):
+               return self.text
        
        def createWidget(self, parent):
-               return eLabel(parent)
+               return eLabel(parent, self.currPos)
        
        def getSize(self):
                s = self.instance.calculateSize()
@@ -28,19 +42,44 @@ class Input(HTMLComponent, GUIComponent, VariableText):
        def right(self):
                self.currPos += 1
                if self.currPos == len(self.text):
-                       self.text = self.text + " "
+                       if self.maxSize:
+                               self.currPos -= 1
+                       else:
+                               self.text = self.text + " "
+                       
                self.update()
                
        def left(self):
                self.currPos -= 1
                self.update()
                
-       def number(self, number):
-               self.text = self.text[0:self.currPos] + self.numericalTextInput.getKey(number) + self.text[self.currPos + 1:]
+       def up(self):
+               if self.text[self.currPos] == "9" or self.text[self.currPos] == " ":
+                       newNumber = "0"
+               else:
+                       newNumber = str(int(self.text[self.currPos]) + 1)
+               self.text = self.text[0:self.currPos] + newNumber + self.text[self.currPos + 1:]
                self.update()
+               
+       def down(self):
+               if self.text[self.currPos] == "0" or self.text[self.currPos] == " ":
+                       newNumber = "9"
+               else:
+                       newNumber = str(int(self.text[self.currPos]) - 1)
 
-       def show(self):
-               self.instance.show()
-
-       def hide(self):
-               self.instance.hide()
\ No newline at end of file
+               self.text = self.text[0:self.currPos] + newNumber + self.text[self.currPos + 1:]
+               self.update()
+               
+       def delete(self):
+               self.text = self.text[:self.currPos] + self.text[self.currPos + 1:]
+               self.update()
+               
+       def number(self, number):
+               if self.type == self.TEXT:
+                       newChar = self.numericalTextInput.getKey(number)
+               elif self.type == self.PIN or self.type == self.NUMBER:
+                       newChar = str(number)
+               self.text = self.text[0:self.currPos] + newChar + self.text[self.currPos + 1:]
+               if self.type == self.PIN or self.type == self.NUMBER:
+                       self.right()
+               self.update()