work on web interface
[enigma2.git] / lib / python / Tools / NumericalTextInput.py
1 # -*- coding: latin-1 -*-
2 from enigma import *
3 from Components.Language import language
4
5 class NumericalTextInput:
6         def __init__(self, nextFunc=None):
7                 self.mapping = []
8                 self.lang = language.getLanguage()
9                 self.useableChars=None
10                 self.nextFunction=nextFunc
11                 
12                 if self.lang == 'de_DE':
13                         self.mapping.append (u".,?'\"0-()@/:_") # 0
14                         self.mapping.append (u" 1") # 1
15                         self.mapping.append (u"aäbc2AÄBC") # 2
16                         self.mapping.append (u"def3DEF") # 3
17                         self.mapping.append (u"ghi4GHI") # 4
18                         self.mapping.append (u"jkl5JKL") # 5
19                         self.mapping.append (u"mnoö6MNOÖ") # 6
20                         self.mapping.append (u"pqrsß7PQRSß") # 7
21                         self.mapping.append (u"tuüv8TUÜV") # 8
22                         self.mapping.append (u"wxyz9WXYZ") # 9
23                 elif self.lang == 'es_ES':
24                         self.mapping.append (u".,?'\"0-()@/:_") # 0
25                         self.mapping.append (u" 1") # 1
26                         self.mapping.append (u"abcáà2ABCÁÀ") # 2
27                         self.mapping.append (u"deéèf3DEFÉÈ") # 3
28                         self.mapping.append (u"ghiíì4GHIÍÌ") # 4
29                         self.mapping.append (u"jkl5JKL") # 5
30                         self.mapping.append (u"mnñoóò6MNÑOÓÒ") # 6
31                         self.mapping.append (u"pqrs7PQRS") # 7
32                         self.mapping.append (u"tuvúù8TUVÚÙ") # 8
33                         self.mapping.append (u"wxyz9WXYZ") # 9
34                 else:
35                         self.mapping.append (u".,?'\"0-()@/:_") # 0
36                         self.mapping.append (u" 1") # 1
37                         self.mapping.append (u"abc2ABC") # 2
38                         self.mapping.append (u"def3DEF") # 3
39                         self.mapping.append (u"ghi4GHI") # 4
40                         self.mapping.append (u"jkl5JKL") # 5
41                         self.mapping.append (u"mno6MNO") # 6
42                         self.mapping.append (u"pqrs7PQRS") # 7
43                         self.mapping.append (u"tuv8TUV") # 8
44                         self.mapping.append (u"wxyz9WXYZ") # 9
45
46                 self.Timer = eTimer()
47                 self.Timer.timeout.get().append(self.nextChar)
48                 self.lastKey = -1
49                 self.pos = -1
50
51         def setUseableChars(self, useable):
52                 self.useableChars = useable
53
54         def getKey(self, num):
55                 cnt=0
56                 self.Timer.start(1000, True)
57                 if (self.lastKey != num):
58                         self.lastKey = num
59                         self.pos = -1
60                 while(True):
61                         self.pos += 1
62                         if (len(self.mapping[num]) <= self.pos):
63                                 self.pos = 0
64                         if self.useableChars:
65                                 pos = self.useableChars.find(self.mapping[num][self.pos])
66                                 if pos == -1:
67                                         cnt += 1
68                                         if cnt < len(self.mapping[num]):
69                                                 continue
70                                         else:
71                                                 return None
72                         break
73                 return self.mapping[num][self.pos]
74
75         def nextKey(self):
76                 self.Timer.stop()
77                 self.lastKey = -1
78
79         def nextChar(self):
80                 self.nextKey()
81                 if self.nextFunction:
82                         self.nextFunction()