enigma2 20130114 (master) -> 20130216 (master)
[enigma2.git] / usr / lib / enigma2 / 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                         if isinstance(search, basestring):
22                                 self.mapping.append (unicode(search)+u"0") # 0
23                         else:
24                                 self.mapping.append (u"%_0") # 1
25                         self.mapping.append (u" 1") # 1
26                         self.mapping.append (u"abc2") # 2
27                         self.mapping.append (u"def3") # 3
28                         self.mapping.append (u"ghi4") # 4
29                         self.mapping.append (u"jkl5") # 5
30                         self.mapping.append (u"mno6") # 6
31                         self.mapping.append (u"pqrs7") # 7
32                         self.mapping.append (u"tuv8") # 8
33                         self.mapping.append (u"wxyz9") # 9
34                         return
35
36                 if self.lang == 'de_DE':
37                         self.mapping.append (u"0,?!&@=*'+\"()$~") # 0
38                         self.mapping.append (u" 1.:/-_") # 1
39                         self.mapping.append (u"abc2ABC") # 2
40                         self.mapping.append (u"def3DEF") # 3
41                         self.mapping.append (u"ghi4GHI") # 4
42                         self.mapping.append (u"jkl5JKL") # 5
43                         self.mapping.append (u"mno6MNO") # 6
44                         self.mapping.append (u"pqrs7PQRS") # 7
45                         self.mapping.append (u"tuv8TUV") # 8
46                         self.mapping.append (u"wxyz9WXYZ") # 9
47                 elif self.lang == 'es_ES':
48                         self.mapping.append (u"0,?!&@=*'+\"()$~") # 0
49                         self.mapping.append (u" 1.:/-_") # 1
50                         self.mapping.append (u"abc2ABC") # 2
51                         self.mapping.append (u"def3DEF") # 3
52                         self.mapping.append (u"ghi4GHI") # 4
53                         self.mapping.append (u"jkl5JKL") # 5
54                         self.mapping.append (u"mno6MNO") # 6
55                         self.mapping.append (u"pqrs7PQRS") # 7
56                         self.mapping.append (u"tuv8TUV") # 8
57                         self.mapping.append (u"wxyz9WXYZ") # 9
58                 if self.lang in ('sv_SE', 'fi_FI'):
59                         self.mapping.append (u"0,?!&@=*'+\"()$~") # 0
60                         self.mapping.append (u" 1.:/-_") # 1
61                         self.mapping.append (u"abc2ABC") # 2
62                         self.mapping.append (u"def3DEF") # 3
63                         self.mapping.append (u"ghi4GHI") # 4
64                         self.mapping.append (u"jkl5JKL") # 5
65                         self.mapping.append (u"mno6MNO") # 6
66                         self.mapping.append (u"pqrs7PQRS") # 7
67                         self.mapping.append (u"tuv8TUV") # 8
68                         self.mapping.append (u"wxyz9WXYZ") # 9
69                 elif self.lang in ('cs_CZ', 'sk_SK'):
70                         self.mapping.append (u"0,?'+\"()@$!=&*") # 0
71                         self.mapping.append (u" 1.:/-_") # 1
72                         self.mapping.append (u"abc2áäčABCÁÄČ") # 2
73                         self.mapping.append (u"def3ďéěDEFĎÉĚ") # 3
74                         self.mapping.append (u"ghi4GHI") # 4
75                         self.mapping.append (u"jkl5ľĺJKLĽĹ") # 5
76                         self.mapping.append (u"mno6ňóöôMNOŇÓÖÔ") # 6
77                         self.mapping.append (u"pqrs7řŕšPQRSŘŔŠ") # 7
78                         self.mapping.append (u"tuv8ťúůüTUVŤÚŮÜ") # 8
79                         self.mapping.append (u"wxyz9ýžWXYZÝŽ") # 9
80                 else:
81                         self.mapping.append (u"0,?!&@=*'+\"()$~") # 0
82                         self.mapping.append (u" 1.:/-_") # 1
83                         self.mapping.append (u"abc2ABC") # 2
84                         self.mapping.append (u"def3DEF") # 3
85                         self.mapping.append (u"ghi4GHI") # 4
86                         self.mapping.append (u"jkl5JKL") # 5
87                         self.mapping.append (u"mno6MNO") # 6
88                         self.mapping.append (u"pqrs7PQRS") # 7
89                         self.mapping.append (u"tuv8TUV") # 8
90                         self.mapping.append (u"wxyz9WXYZ") # 9
91
92         def setUseableChars(self, useable):
93                 self.useableChars = unicode(useable)
94                 
95
96         def getKey(self, num):
97                 cnt=0
98                 if self.lastKey != num:
99                         if self.lastKey != -1:
100                                 self.nextChar()
101                         self.lastKey = num
102                         self.pos = -1
103                 if self.timer is not None:
104                         self.timer.start(1000, True)
105                 while True:
106                         self.pos += 1
107                         if len(self.mapping[num]) <= self.pos:
108                                 self.pos = 0
109                         if self.useableChars:
110                                 pos = self.useableChars.find(self.mapping[num][self.pos])
111                                 if pos == -1:
112                                         cnt += 1
113                                         if cnt < len(self.mapping[num]):
114                                                 continue
115                                         else:
116                                                 return None
117                         break
118                 return self.mapping[num][self.pos]
119
120         def nextKey(self):
121                 if self.timer is not None:
122                         self.timer.stop()
123                 self.lastKey = -1
124
125         def nextChar(self):
126                 self.nextKey()
127                 if self.nextFunction:
128                         self.nextFunction()
129
130         def timeout(self):
131                 if self.lastKey != -1:
132                         self.nextChar()