[RecordTimer] fix repeat timer issue.
[vuplus_dvbapp] / 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"abcä2ABCÄ") # 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"tuvü8TUVÜ") # 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                 elif self.lang in ('cs_CZ', 'sk_SK'):
67                         self.mapping.append (u"0,?'+\"()@$!=&*") # 0
68                         self.mapping.append (u" 1.:/-_") # 1
69                         self.mapping.append (u"abc2áäčABCÁÄČ") # 2
70                         self.mapping.append (u"def3ďéěDEFĎÉĚ") # 3
71                         self.mapping.append (u"ghi4íGHIÍ") # 4
72                         self.mapping.append (u"jkl5ľĺJKLĽĹ") # 5
73                         self.mapping.append (u"mno6ňóöôMNOŇÓÖÔ") # 6
74                         self.mapping.append (u"pqrs7řŕšPQRSŘŔŠ") # 7
75                         self.mapping.append (u"tuv8ťúůüTUVŤÚŮÜ") # 8
76                         self.mapping.append (u"wxyz9ýžWXYZÝŽ") # 9
77                 else:
78                         self.mapping.append (u"0,?!&@=*'+\"()$~") # 0
79                         self.mapping.append (u" 1.:/-_") # 1
80                         self.mapping.append (u"abc2ABC") # 2
81                         self.mapping.append (u"def3DEF") # 3
82                         self.mapping.append (u"ghi4GHI") # 4
83                         self.mapping.append (u"jkl5JKL") # 5
84                         self.mapping.append (u"mno6MNO") # 6
85                         self.mapping.append (u"pqrs7PQRS") # 7
86                         self.mapping.append (u"tuv8TUV") # 8
87                         self.mapping.append (u"wxyz9WXYZ") # 9
88
89         def setUseableChars(self, useable):
90                 self.useableChars = unicode(useable)
91                 
92
93         def getKey(self, num):
94                 cnt=0
95                 if self.lastKey != num:
96                         if self.lastKey != -1:
97                                 self.nextChar()
98                         self.lastKey = num
99                         self.pos = -1
100                 if self.timer is not None:
101                         self.timer.start(1000, True)
102                 while True:
103                         self.pos += 1
104                         if len(self.mapping[num]) <= self.pos:
105                                 self.pos = 0
106                         if self.useableChars:
107                                 pos = self.useableChars.find(self.mapping[num][self.pos])
108                                 if pos == -1:
109                                         cnt += 1
110                                         if cnt < len(self.mapping[num]):
111                                                 continue
112                                         else:
113                                                 return None
114                         break
115                 return self.mapping[num][self.pos]
116
117         def nextKey(self):
118                 if self.timer is not None:
119                         self.timer.stop()
120                 self.lastKey = -1
121
122         def nextChar(self):
123                 self.nextKey()
124                 if self.nextFunction:
125                         self.nextFunction()
126
127         def timeout(self):
128                 if self.lastKey != -1:
129                         self.nextChar()