set /etc/localtime link when change the timezone too
[enigma2.git] / lib / python / Components / Input.py
1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
3 from VariableText import VariableText
4
5 from enigma import eLabel
6
7 from Tools.NumericalTextInput import NumericalTextInput
8
9 class Input(VariableText, HTMLComponent, GUIComponent, NumericalTextInput):
10         TEXT = 0
11         PIN = 1
12         NUMBER = 2
13
14         def __init__(self, text="", maxSize = False, type = TEXT):
15                 NumericalTextInput.__init__(self, self.right)
16                 GUIComponent.__init__(self)
17                 VariableText.__init__(self)
18                 self.type = type
19                 self.maxSize = maxSize
20                 self.currPos = 0
21                 self.overwrite = 0
22                 self.setText(text)
23                 
24         def __len__(self):
25                 return len(self.text)
26
27         def update(self):
28                 self.setMarkedPos(self.currPos)
29                 if self.type == self.PIN:
30                         self.text = "*" * len(self.Text)
31                 else:
32                         self.text = self.Text.encode("utf-8")
33
34         def setText(self, text):
35                 if not len(text):
36                         self.currPos = 0
37                         self.Text = u""
38                 else:
39                         try:
40                                 self.Text = text.decode("utf-8")
41                         except UnicodeDecodeError:
42                                 print "utf8 kaputt!"
43                                 self.Text = text
44                 self.update()
45
46         def getText(self):
47                 return self.Text.encode("utf-8")
48
49         def createWidget(self, parent):
50                 return eLabel(parent, self.currPos)
51
52         def getSize(self):
53                 s = self.instance.calculateSize()
54                 return (s.width(), s.height())
55         
56         def right(self):
57                 self.currPos += 1
58                 if self.currPos == len(self.Text):
59                         if self.maxSize:
60                                 self.currPos -= 1
61                         else:
62                                 self.Text = self.Text + " "
63                 self.update()
64
65         def left(self):
66                 if self.currPos > 0:
67                         self.currPos -= 1
68                         self.update()
69
70         def up(self):
71                 if self.Text[self.currPos] == "9" or self.Text[self.currPos] == " ":
72                         newNumber = "0"
73                 else:
74                         newNumber = str(int(self.Text[self.currPos]) + 1)
75                 self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
76                 self.update()
77
78         def down(self):
79                 if self.Text[self.currPos] == "0" or self.Text[self.currPos] == " ":
80                         newNumber = "9"
81                 else:
82                         newNumber = str(int(self.Text[self.currPos]) - 1)
83                 self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
84                 self.update()
85                 
86         def home(self):
87                 self.currPos = 0
88                 self.update()
89         
90         def end(self):
91                 self.currPos = len(self.Text) - 1
92                 self.update()
93
94         def tab(self):
95                 if self.currPos == len(self.Text) - 1:
96                         self.Text=self.Text+ " "
97                         self.end()
98                 else:
99                         self.Text = self.Text[0:self.currPos] + " " + self.Text[self.currPos:]
100                 self.update()
101
102         def delete(self):
103                 self.Text = self.Text[:self.currPos] + self.Text[self.currPos + 1:]
104                 self.update()
105
106         def toggleOverwrite(self):
107                 if self.overwrite==1:
108                         self.overwrite=0
109                 else:
110                         self.overwrite=1
111                 self.update()
112
113         def deleteBackward(self):
114                 self.Text = self.Text[:self.currPos - 1] + self.Text[self.currPos:]
115                 self.left()
116                 self.update()
117
118         def handleAscii(self, code):
119                 newChar = unichr(code)
120                 if self.overwrite==1:
121                         self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos + 1:]
122                 else:
123                         self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos:]
124                 self.right()
125
126         def number(self, number):
127                 if self.type == self.TEXT:
128                         newChar = self.getKey(number)
129                 elif self.type == self.PIN or self.type == self.NUMBER:
130                         newChar = str(number)
131                 self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos + 1:]
132                 if self.type == self.PIN or self.type == self.NUMBER:
133                         self.right()
134                 self.update()