add some new (currently unused) source/renderer based elements
[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.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                 if self.type == self.PIN:
27                         self.message = "*" * len(self.Text)
28                 else:
29                         self.message = convertDVBUTF8(self.Text, 0)
30                 if self.instance:
31                         self.instance.setText(self.message)
32
33         def setText(self, text):
34                 if not len(text):
35                         self.currPos = 0
36                 elif isUTF8(text):
37                         self.Text = convertUTF8DVB(text, 0)
38                 else:
39                         self.Text = text
40                 self.update()
41
42         def getText(self):
43                 return convertDVBUTF8(self.Text, 0)
44
45         def createWidget(self, parent):
46                 return eLabel(parent, self.currPos)
47
48         def getSize(self):
49                 s = self.instance.calculateSize()
50                 return (s.width(), s.height())
51         
52         def right(self):
53                 self.currPos += 1
54                 if self.currPos == len(self.Text):
55                         if self.maxSize:
56                                 self.currPos -= 1
57                         else:
58                                 self.Text = self.Text + " "
59                 self.update()
60
61         def left(self):
62                 if self.currPos > 0:
63                         self.currPos -= 1
64                         self.update()
65
66         def up(self):
67                 if self.Text[self.currPos] == "9" or self.Text[self.currPos] == " ":
68                         newNumber = "0"
69                 else:
70                         newNumber = str(int(self.Text[self.currPos]) + 1)
71                 self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
72                 self.update()
73
74         def down(self):
75                 if self.Text[self.currPos] == "0" or self.Text[self.currPos] == " ":
76                         newNumber = "9"
77                 else:
78                         newNumber = str(int(self.Text[self.currPos]) - 1)
79                 self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
80                 self.update()
81
82         def delete(self):
83                 self.Text = self.Text[:self.currPos] + self.Text[self.currPos + 1:]
84                 self.update()
85
86         def handleAscii(self, code):
87                 newChar = chr(code)
88                 self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos + 1:]
89                 self.right()
90
91         def number(self, number):
92                 if self.type == self.TEXT:
93                         newChar = self.numericalTextInput.getKey(number)
94                 elif self.type == self.PIN or self.type == self.NUMBER:
95                         newChar = str(number)
96                 self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos + 1:]
97                 if self.type == self.PIN or self.type == self.NUMBER:
98                         self.right()
99                 self.update()