fix typo
[enigma2.git] / lib / python / Components / Input.py
1 from HTMLComponent import *
2 from GUIComponent import *
3 from VariableText import *
4
5 from enigma import eLabel
6
7 from Tools.NumericalTextInput import NumericalTextInput
8
9 class Input(VariableText, HTMLComponent, GUIComponent):
10         TEXT = 0
11         PIN = 1
12         NUMBER = 2      
13         
14         def __init__(self, text="", maxSize = False, type = TEXT):
15                 GUIComponent.__init__(self)
16                 VariableText.__init__(self)
17                 self.numericalTextInput = NumericalTextInput(self.right)
18                 self.type = type
19                 self.maxSize = maxSize
20                 self.currPos = 0
21                 self.text = text
22                 self.update()
23
24         def update(self):
25                 self.setMarkedPos(self.currPos)
26                 text = self.text
27                 if self.type == self.PIN:
28                         text = "*" * len(self.text)
29                 self.setText(text)
30                 #self.setText(self.text[0:self.currPos] + "_" + self.text[self.currPos] + "_" + self.text[self.currPos + 1:])
31
32         def getText(self):
33                 return self.text
34         
35         def createWidget(self, parent):
36                 return eLabel(parent, self.currPos)
37         
38         def getSize(self):
39                 s = self.instance.calculateSize()
40                 return (s.width(), s.height())
41         
42         def right(self):
43                 self.currPos += 1
44                 if self.currPos == len(self.text):
45                         if self.maxSize:
46                                 self.currPos -= 1
47                         else:
48                                 self.text = self.text + " "
49                         
50                 self.update()
51                 
52         def left(self):
53                 self.currPos -= 1
54                 self.update()
55                 
56         def up(self):
57                 if self.text[self.currPos] == "9" or self.text[self.currPos] == " ":
58                         newNumber = "0"
59                 else:
60                         newNumber = str(int(self.text[self.currPos]) + 1)
61                 self.text = self.text[0:self.currPos] + newNumber + self.text[self.currPos + 1:]
62                 self.update()
63                 
64         def down(self):
65                 if self.text[self.currPos] == "0" or self.text[self.currPos] == " ":
66                         newNumber = "9"
67                 else:
68                         newNumber = str(int(self.text[self.currPos]) - 1)
69
70                 self.text = self.text[0:self.currPos] + newNumber + self.text[self.currPos + 1:]
71                 self.update()
72                 
73         def delete(self):
74                 self.text = self.text[:self.currPos] + self.text[self.currPos + 1:]
75                 self.update()
76                 
77         def number(self, number):
78                 if self.type == self.TEXT:
79                         newChar = self.numericalTextInput.getKey(number)
80                 elif self.type == self.PIN or self.type == self.NUMBER:
81                         newChar = str(number)
82                 self.text = self.text[0:self.currPos] + newChar + self.text[self.currPos + 1:]
83                 if self.type == self.PIN or self.type == self.NUMBER:
84                         self.right()
85                 self.update()