1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
3 from VariableText import VariableText
5 from enigma import eLabel
7 from Tools.NumericalTextInput import NumericalTextInput
9 class Input(VariableText, HTMLComponent, GUIComponent, NumericalTextInput):
14 def __init__(self, text="", maxSize = False, visible_width = False, type = TEXT):
15 NumericalTextInput.__init__(self, self.right)
16 GUIComponent.__init__(self)
17 VariableText.__init__(self)
19 self.allmarked = (text != "") and (type != self.PIN)
20 self.maxSize = maxSize
22 self.visible_width = visible_width
24 self.overwrite = maxSize
31 if self.visible_width:
32 if self.currPos < self.offset:
33 self.offset = self.currPos
34 if self.currPos >= self.offset + self.visible_width:
35 if self.currPos == len(self.Text):
36 self.offset = self.currPos - self.visible_width
38 self.offset = self.currPos - self.visible_width + 1
39 if self.offset > 0 and self.offset + self.visible_width > len(self.Text):
40 self.offset = max(0, len(self.Text) - self.visible_width)
44 self.setMarkedPos(self.currPos-self.offset)
45 if self.visible_width:
46 if self.type == self.PIN:
48 for x in self.Text[self.offset:self.offset+self.visible_width]:
49 self.text += (x==" " and " " or "*")
51 self.text = self.Text[self.offset:self.offset+self.visible_width].encode("utf-8") + " "
53 if self.type == self.PIN:
56 self.text += (x==" " and " " or "*")
58 self.text = self.Text.encode("utf-8") + " "
60 def setText(self, text):
66 self.Text = text.decode("utf-8")
67 except UnicodeDecodeError:
73 return self.Text.encode("utf-8")
75 def createWidget(self, parent):
77 return eLabel(parent, -2)
79 return eLabel(parent, self.currPos-self.offset)
82 s = self.instance.calculateSize()
83 return (s.width(), s.height())
86 if self.type == self.TEXT:
90 self.allmarked = False
92 if self.currPos < len(self.Text)-1:
95 if self.currPos < len(self.Text):
100 if self.type == self.TEXT:
104 self.currPos = len(self.Text) - 1
106 self.currPos = len(self.Text)
107 self.allmarked = False
108 elif self.currPos > 0:
113 self.allmarked = False
114 if self.type == self.TEXT:
116 if self.Text[self.currPos] == "9" or self.Text[self.currPos] == " ":
119 newNumber = str(int(self.Text[self.currPos]) + 1)
120 self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
124 self.allmarked = False
125 if self.type == self.TEXT:
127 if self.Text[self.currPos] == "0" or self.Text[self.currPos] == " ":
130 newNumber = str(int(self.Text[self.currPos]) - 1)
131 self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
135 self.allmarked = False
136 if self.type == self.TEXT:
142 self.allmarked = False
143 if self.type == self.TEXT:
146 self.currPos = len(self.Text) - 1
148 self.currPos = len(self.Text)
151 def insertChar(self, ch, pos, owr, ins):
152 if ins and not self.maxSize:
153 self.Text = self.Text[0:pos] + ch + self.Text[pos:]
154 elif owr or self.overwrite:
155 self.Text = self.Text[0:pos] + ch + self.Text[pos + 1:]
157 self.Text = self.Text[0:pos] + ch + self.Text[pos:-1]
159 self.Text = self.Text[0:pos] + ch + self.Text[pos:]
161 def deleteChar(self, pos):
163 self.Text = self.Text[0:pos] + self.Text[pos + 1:]
165 self.Text = self.Text[0:pos] + " " + self.Text[pos + 1:]
167 self.Text = self.Text[0:pos] + self.Text[pos + 1:] + " "
169 def deleteAllChars(self):
171 self.Text = " " * len(self.Text)
177 if self.type == self.TEXT:
180 self.deleteAllChars()
181 self.allmarked = False
183 self.insertChar(" ", self.currPos, False, True);
188 if self.type == self.TEXT:
191 self.deleteAllChars()
192 self.allmarked = False
194 self.deleteChar(self.currPos);
195 if self.maxSize and self.overwrite:
199 def deleteBackward(self):
200 if self.type == self.TEXT:
203 self.deleteAllChars()
204 self.allmarked = False
207 self.deleteChar(self.currPos-1);
208 if not self.maxSize and self.offset > 0:
213 def toggleOverwrite(self):
214 if self.type == self.TEXT:
216 self.overwrite = not self.overwrite
219 def handleAscii(self, code):
220 if self.type == self.TEXT:
223 self.deleteAllChars()
224 self.allmarked = False
225 self.insertChar(unichr(code), self.currPos, False, False);
228 def number(self, number):
229 if self.type == self.TEXT:
230 owr = self.lastKey == number
231 newChar = self.getKey(number)
232 elif self.type == self.PIN or self.type == self.NUMBER:
234 newChar = str(number)
236 self.deleteAllChars()
237 self.allmarked = False
238 self.insertChar(newChar, self.currPos, owr, False);
239 if self.type == self.PIN or self.type == self.NUMBER: