more work on keyboard support
[vuplus_dvbapp] / 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                 if self.currPos > 0:
54                         self.currPos -= 1
55                         self.update()
56                 
57         def up(self):
58                 if self.text[self.currPos] == "9" or self.text[self.currPos] == " ":
59                         newNumber = "0"
60                 else:
61                         newNumber = str(int(self.text[self.currPos]) + 1)
62                 self.text = self.text[0:self.currPos] + newNumber + self.text[self.currPos + 1:]
63                 self.update()
64                 
65         def down(self):
66                 if self.text[self.currPos] == "0" or self.text[self.currPos] == " ":
67                         newNumber = "9"
68                 else:
69                         newNumber = str(int(self.text[self.currPos]) - 1)
70
71                 self.text = self.text[0:self.currPos] + newNumber + self.text[self.currPos + 1:]
72                 self.update()
73                 
74         def delete(self):
75                 self.text = self.text[:self.currPos] + self.text[self.currPos + 1:]
76                 self.update()
77
78         def handleAscii(self, code):
79                 newChar = chr(code)
80                 self.text = self.text[0:self.currPos] + newChar + self.text[self.currPos + 1:]
81                 self.right()
82                 self.update()
83
84         def number(self, number):
85                 if self.type == self.TEXT:
86                         newChar = self.numericalTextInput.getKey(number)
87                 elif self.type == self.PIN or self.type == self.NUMBER:
88                         newChar = str(number)
89                 self.text = self.text[0:self.currPos] + newChar + self.text[self.currPos + 1:]
90                 if self.type == self.PIN or self.type == self.NUMBER:
91                         self.right()
92                 self.update()