Wizard shouldn't be a subclass of HelpableScreen since there is no help
[enigma2.git] / lib / python / Tools / NumericalTextInput.py
1 # -*- coding: iso-8859-1 -*-
2 from enigma import eTimer
3 from Components.Language import language
4
5 class NumericalTextInput:
6         def __init__(self, nextFunc=None, handleTimeout = True):
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                 if self.lang in ['sv_SE', 'fi_FI']:
35                         self.mapping.append (u".,?'+\"0-()@/:_$") # 0
36                         self.mapping.append (u" 1") # 1
37                         self.mapping.append (u"abcåä2ABCÅÄ") # 2
38                         self.mapping.append (u"defé3DEFÉ") # 3
39                         self.mapping.append (u"ghi4GHI") # 4
40                         self.mapping.append (u"jkl5JKL") # 5
41                         self.mapping.append (u"mnoö6MNOÖ") # 6
42                         self.mapping.append (u"pqrs7PQRS") # 7
43                         self.mapping.append (u"tuv8TUV") # 8
44                         self.mapping.append (u"wxyz9WXYZ") # 9
45                 else:
46                         self.mapping.append (u".,?'+\"0-()@/:_$") # 0
47                         self.mapping.append (u" 1") # 1
48                         self.mapping.append (u"abc2ABC") # 2
49                         self.mapping.append (u"def3DEF") # 3
50                         self.mapping.append (u"ghi4GHI") # 4
51                         self.mapping.append (u"jkl5JKL") # 5
52                         self.mapping.append (u"mno6MNO") # 6
53                         self.mapping.append (u"pqrs7PQRS") # 7
54                         self.mapping.append (u"tuv8TUV") # 8
55                         self.mapping.append (u"wxyz9WXYZ") # 9
56
57                 if handleTimeout:
58                         self.timer = eTimer()
59                         self.timer.callback.append(self.timeout)
60                 else:
61                         self.timer = None
62                 self.lastKey = -1
63                 self.pos = -1
64
65         def setUseableChars(self, useable):
66                 self.useableChars = useable
67
68         def getKey(self, num):
69                 cnt=0
70                 if self.lastKey != num:
71                         if self.lastKey != -1:
72                                 self.nextChar()
73                         self.lastKey = num
74                         self.pos = -1
75                 if self.timer is not None:
76                         self.timer.start(1000, True)
77                 while True:
78                         self.pos += 1
79                         if len(self.mapping[num]) <= self.pos:
80                                 self.pos = 0
81                         if self.useableChars:
82                                 pos = self.useableChars.find(self.mapping[num][self.pos])
83                                 if pos == -1:
84                                         cnt += 1
85                                         if cnt < len(self.mapping[num]):
86                                                 continue
87                                         else:
88                                                 return None
89                         break
90                 return self.mapping[num][self.pos]
91
92         def nextKey(self):
93                 if self.timer is not None:
94                         self.timer.stop()
95                 self.lastKey = -1
96
97         def nextChar(self):
98                 self.nextKey()
99                 if self.nextFunction:
100                         self.nextFunction()
101
102         def timeout(self):
103                 if self.lastKey != -1:
104                         self.nextChar()