aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Components/Input.py
blob: e27ef524048b810b3353285c8d7a985c5375876c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from HTMLComponent import *
from GUIComponent import *
from VariableText import *

from enigma import eLabel, isUTF8, convertUTF8DVB, convertDVBUTF8

from Tools.NumericalTextInput import NumericalTextInput

class Input(VariableText, HTMLComponent, GUIComponent):
	TEXT = 0
	PIN = 1
	NUMBER = 2	

	def __init__(self, text="", maxSize = False, type = TEXT):
		GUIComponent.__init__(self)
		VariableText.__init__(self)
		self.table = 0
		self.numericalTextInput = NumericalTextInput(self.right)
		self.type = type
		self.maxSize = maxSize
		self.currPos = 0
		self.Text = text
		self.overwrite = 0
		self.update()

	def update(self):
		self.setMarkedPos(self.currPos)
		if self.type == self.PIN:
			self.message = "*" * len(self.Text)
		else:
			self.message = convertDVBUTF8(self.Text, self.table)
		if self.instance:
			self.instance.setText(self.message)

	def setText(self, text):
		if not len(text):
			self.currPos = 0
			self.Text = ""
		elif isUTF8(text):
			self.Text = convertUTF8DVB(text, self.table)
		else:
			self.Text = text
		self.update()

	def getText(self):
		return convertDVBUTF8(self.Text, self.table)

	def createWidget(self, parent):
		return eLabel(parent, self.currPos)

	def getSize(self):
		s = self.instance.calculateSize()
		return (s.width(), s.height())
	
	def right(self):
		self.currPos += 1
		if self.currPos == len(self.Text):
			if self.maxSize:
				self.currPos -= 1
			else:
				self.Text = self.Text + " "
		self.update()

	def left(self):
		if self.currPos > 0:
			self.currPos -= 1
			self.update()

	def up(self):
		if self.Text[self.currPos] == "9" or self.Text[self.currPos] == " ":
			newNumber = "0"
		else:
			newNumber = str(int(self.Text[self.currPos]) + 1)
		self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
		self.update()

	def down(self):
		if self.Text[self.currPos] == "0" or self.Text[self.currPos] == " ":
			newNumber = "9"
		else:
			newNumber = str(int(self.Text[self.currPos]) - 1)
		self.Text = self.Text[0:self.currPos] + newNumber + self.Text[self.currPos + 1:]
		self.update()
		
	def home(self):
		self.currPos = 0
		self.update()
	
	def end(self):
		self.currPos = len(self.Text) - 1
		self.update()

	def tab(self):
		if self.currPos == len(self.Text) - 1:
			self.Text=self.Text+ " "
			self.end()
		else:
			self.Text = self.Text[0:self.currPos] + " " + self.Text[self.currPos:]
		self.update()

	def delete(self):
		self.Text = self.Text[:self.currPos] + self.Text[self.currPos + 1:]
		self.update()

	def toggleOverwrite(self):
		if self.overwrite==1:
			self.overwrite=0
		else:
			self.overwrite=1
		self.update()

	def deleteBackward(self):
		self.Text = self.Text[:self.currPos - 1] + self.Text[self.currPos:]
		self.left()
		self.update()

	def handleAscii(self, code):
		newChar = chr(code)
		if self.overwrite==1:
			self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos + 1:]
		else:
			self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos:]
		self.right()

	def number(self, number):
		if self.type == self.TEXT:
			newChar = self.numericalTextInput.getKey(number)
		elif self.type == self.PIN or self.type == self.NUMBER:
			newChar = str(number)
		self.Text = self.Text[0:self.currPos] + newChar + self.Text[self.currPos + 1:]
		if self.type == self.PIN or self.type == self.NUMBER:
			self.right()
		self.update()