change character encoding of source file from 8859-1 to utf-8
[enigma2.git] / lib / python / Tools / NumericalTextInput.py
1 # -*- coding: utf-8 -*-
2 from enigma import eTimer
3 from Components.Language import language
4
5 class NumericalTextInput:
6         def __init__(self, nextFunc=None, handleTimeout = True, search = False):
7                 self.mapping = []
8                 self.lang = language.getLanguage()
9                 self.useableChars=None
10                 self.nextFunction=nextFunc
11
12                 if handleTimeout:
13                         self.timer = eTimer()
14                         self.timer.callback.append(self.timeout)
15                 else:
16                         self.timer = None
17                 self.lastKey = -1
18                 self.pos = -1
19
20                 if search:
21                         self.mapping.append (u"%_0") # 0
22                         self.mapping.append (u" 1") # 1
23                         self.mapping.append (u"abc2") # 2
24                         self.mapping.append (u"def3") # 3
25                         self.mapping.append (u"ghi4") # 4
26                         self.mapping.append (u"jkl5") # 5
27                         self.mapping.append (u"mno6") # 6
28                         self.mapping.append (u"pqrs7") # 7
29                         self.mapping.append (u"tuv8") # 8
30                         self.mapping.append (u"wxyz9") # 9
31                         return
32
33                 if self.lang == 'de_DE':
34                         self.mapping.append (u".,?'+\"0-()@/:_$!") # 0
35                         self.mapping.append (u" 1") # 1
36                         self.mapping.append (u"aäbc2AÄBC") # 2
37                         self.mapping.append (u"def3DEF") # 3
38                         self.mapping.append (u"ghi4GHI") # 4
39                         self.mapping.append (u"jkl5JKL") # 5
40                         self.mapping.append (u"mnoö6MNOÖ") # 6
41                         self.mapping.append (u"pqrsß7PQRSß") # 7
42                         self.mapping.append (u"tuüv8TUÜV") # 8
43                         self.mapping.append (u"wxyz9WXYZ") # 9
44                 elif self.lang == 'es_ES':
45                         self.mapping.append (u".,?'+\"0-()@/:_$!") # 0
46                         self.mapping.append (u" 1") # 1
47                         self.mapping.append (u"abcáà2ABCÁÀ") # 2
48                         self.mapping.append (u"deéèf3DEFÉÈ") # 3
49                         self.mapping.append (u"ghiíì4GHIÍÌ") # 4
50                         self.mapping.append (u"jkl5JKL") # 5
51                         self.mapping.append (u"mnñoóò6MNÑOÓÒ") # 6
52                         self.mapping.append (u"pqrs7PQRS") # 7
53                         self.mapping.append (u"tuvúù8TUVÚÙ") # 8
54                         self.mapping.append (u"wxyz9WXYZ") # 9
55                 if self.lang in ['sv_SE', 'fi_FI']:
56                         self.mapping.append (u".,?'+\"0-()@/:_$!") # 0
57                         self.mapping.append (u" 1") # 1
58                         self.mapping.append (u"abcåä2ABCÅÄ") # 2
59                         self.mapping.append (u"defé3DEFÉ") # 3
60                         self.mapping.append (u"ghi4GHI") # 4
61                         self.mapping.append (u"jkl5JKL") # 5
62                         self.mapping.append (u"mnoö6MNOÖ") # 6
63                         self.mapping.append (u"pqrs7PQRS") # 7
64                         self.mapping.append (u"tuv8TUV") # 8
65                         self.mapping.append (u"wxyz9WXYZ") # 9
66                 else:
67                         self.mapping.append (u".,?'+\"0-()@/:_$!") # 0
68                         self.mapping.append (u" 1") # 1
69                         self.mapping.append (u"abc2ABC") # 2
70                         self.mapping.append (u"def3DEF") # 3
71                         self.mapping.append (u"ghi4GHI") # 4
72                         self.mapping.append (u"jkl5JKL") # 5
73                         self.mapping.append (u"mno6MNO") # 6
74                         self.mapping.append (u"pqrs7PQRS") # 7
75                         self.mapping.append (u"tuv8TUV") # 8
76                         self.mapping.append (u"wxyz9WXYZ") # 9
77
78         def setUseableChars(self, useable):
79                 self.useableChars = useable
80
81         def getKey(self, num):
82                 cnt=0
83                 if self.lastKey != num:
84                         if self.lastKey != -1:
85                                 self.nextChar()
86                         self.lastKey = num
87                         self.pos = -1
88                 if self.timer is not None:
89                         self.timer.start(1000, True)
90                 while True:
91                         self.pos += 1
92                         if len(self.mapping[num]) <= self.pos:
93                                 self.pos = 0
94                         if self.useableChars:
95                                 pos = self.useableChars.find(self.mapping[num][self.pos])
96                                 if pos == -1:
97                                         cnt += 1
98                                         if cnt < len(self.mapping[num]):
99                                                 continue
100                                         else:
101                                                 return None
102                         break
103                 return self.mapping[num][self.pos]
104
105         def nextKey(self):
106                 if self.timer is not None:
107                         self.timer.stop()
108                 self.lastKey = -1
109
110         def nextChar(self):
111                 self.nextKey()
112                 if self.nextFunction:
113                         self.nextFunction()
114
115         def timeout(self):
116                 if self.lastKey != -1:
117                         self.nextChar()