add support for umlauts
[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, isUTF8, convertUTF8DVB, convertDVBUTF8
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.table = 0
18                 self.numericalTextInput = NumericalTextInput(self.right)
19                 self.type = type
20                 self.maxSize = maxSize
21                 self.currPos = 0
22                 self.Text = text
23                 self.overwrite = 0
24                 self.update()
25
26         def update(self):
27                 self.setMarkedPos(self.currPos)
28                 if self.type == self.PIN:
29                         self.message = "*" * len(self.Text)
30                 else:
31                         self.message = convertDVBUTF8(self.Text, self.table)
32                 if self.instance:
33                         self.instance.setText(self.message)
34
35         def setText(self, text):
36                 if not len(text):
37                         self.currPos = 0
38                         self.Text = ""
39                 elif isUTF8(text):
40                         self.Text = convertUTF8DVB(text, self.table)
41                 else:
42                         self.Text = text
43                 self.update()
44
45         def getText(self):
46                 return convertDVBUTF8(self.Text, self.table)
47
48         def createWidget(self, parent):
49                 return eLabel(parent, self.currPos)
50
51         def getSize(self):
52                 s = self.instance.calculateSize()
53                 return (s.width(), s.height())
54         
55         def right(self):
56                 self.currPos += 1
57                 if self.currPos == len(self.Text):
58                         if self.maxSize:
59                                 self.currPos -= 1
60                         else:
61                                 self.Text = self.Text + " "
62                 self.update()
63
64         def left(self):
65                 if self.currPos > 0:
66                         self.currPos -= 1
67                         self.update()
68
69         def up(self):
70                 if self.Text[self.currPos] == "9" or self.Text[self.currPos] == " ":
71                         newNumber = "0"
72                 else:
73                         newNumber = str(int(self.Text[self.currPos]) + 1)
74                 self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
75                 self.update()
76
77         def down(self):
78                 if self.Text[self.currPos] == "0" or self.Text[self.currPos] == " ":
79                         newNumber = "9"
80                 else:
81                         newNumber = str(int(self.Text[self.currPos]) - 1)
82                 self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
83                 self.update()
84                 
85         def home(self):
86                 self.currPos = 0
87                 self.update()
88         
89         def end(self):
90                 self.currPos = len(self.Text) - 1
91                 self.update()
92
93         def tab(self):
94                 if self.currPos == len(self.Text) - 1:
95                         self.Text=self.Text+ " "
96                         self.end()
97                 else:
98                         self.Text = self.Text[0:self.currPos] + " " + self.Text[self.currPos:]
99                 self.update()
100
101         def delete(self):
102                 self.Text = self.Text[:self.currPos] + self.Text[self.currPos + 1:]
103                 self.update()
104
105         def toggleOverwrite(self):
106                 if self.overwrite==1:
107                         self.overwrite=0
108                 else:
109                         self.overwrite=1
110                 self.update()
111
112         def deleteBackward(self):
113                 self.Text = self.Text[:self.currPos - 1] + self.Text[self.currPos:]
114                 self.left()
115                 self.update()
116
117         def handleAscii(self, code):
118                 newChar = chr(code)
119                 if self.overwrite==1:
120                         self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos + 1:]
121                 else:
122                         self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos:]
123                 self.right()
124
125         def number(self, number):
126                 if self.type == self.TEXT:
127                         newChar = self.numericalTextInput.getKey(number)
128                 elif self.type == self.PIN or self.type == self.NUMBER:
129                         newChar = str(number)
130                 self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos + 1:]
131                 if self.type == self.PIN or self.type == self.NUMBER:
132                         self.right()
133                 self.update()