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())
88 self.allmarked = False
90 if self.currPos < len(self.Text)-1:
93 if self.currPos < len(self.Text):
97 if self.type == self.TEXT:
103 if self.type == self.TEXT:
107 self.currPos = len(self.Text) - 1
109 self.currPos = len(self.Text)
110 self.allmarked = False
111 elif self.currPos > 0:
116 self.allmarked = False
117 if self.type == self.TEXT:
119 if self.currPos == len(self.Text) or self.Text[self.currPos] == "9" or self.Text[self.currPos] == " ":
122 newNumber = str(int(self.Text[self.currPos]) + 1)
123 self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
127 self.allmarked = False
128 if self.type == self.TEXT:
130 if self.currPos == len(self.Text) or self.Text[self.currPos] == "0" or self.Text[self.currPos] == " ":
133 newNumber = str(int(self.Text[self.currPos]) - 1)
134 self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
138 self.allmarked = False
139 if self.type == self.TEXT:
145 self.allmarked = False
146 if self.type == self.TEXT:
149 self.currPos = len(self.Text) - 1
151 self.currPos = len(self.Text)
154 def insertChar(self, ch, pos, owr, ins):
155 if ins and not self.maxSize:
156 self.Text = self.Text[0:pos] + ch + self.Text[pos:]
157 elif owr or self.overwrite:
158 self.Text = self.Text[0:pos] + ch + self.Text[pos + 1:]
160 self.Text = self.Text[0:pos] + ch + self.Text[pos:-1]
162 self.Text = self.Text[0:pos] + ch + self.Text[pos:]
164 def deleteChar(self, pos):
166 self.Text = self.Text[0:pos] + self.Text[pos + 1:]
168 self.Text = self.Text[0:pos] + " " + self.Text[pos + 1:]
170 self.Text = self.Text[0:pos] + self.Text[pos + 1:] + " "
172 def deleteAllChars(self):
174 self.Text = " " * len(self.Text)
180 if self.type == self.TEXT:
183 self.deleteAllChars()
184 self.allmarked = False
186 self.insertChar(" ", self.currPos, False, True);
191 if self.type == self.TEXT:
194 self.deleteAllChars()
195 self.allmarked = False
197 self.deleteChar(self.currPos);
198 if self.maxSize and self.overwrite:
202 def deleteBackward(self):
203 if self.type == self.TEXT:
206 self.deleteAllChars()
207 self.allmarked = False
210 self.deleteChar(self.currPos-1);
211 if not self.maxSize and self.offset > 0:
216 def toggleOverwrite(self):
217 if self.type == self.TEXT:
219 self.overwrite = not self.overwrite
222 def handleAscii(self, code):
223 if self.type == self.TEXT:
226 self.deleteAllChars()
227 self.allmarked = False
228 self.insertChar(unichr(code), self.currPos, False, False);
232 def number(self, number):
233 if self.type == self.TEXT:
234 owr = self.lastKey == number
235 newChar = self.getKey(number)
236 elif self.type == self.PIN or self.type == self.NUMBER:
238 newChar = str(number)
240 self.deleteAllChars()
241 self.allmarked = False
242 self.insertChar(newChar, self.currPos, owr, False);
243 if self.type == self.PIN or self.type == self.NUMBER: