Merge branch 'master' of https://github.com/OpenPLi/enigma2
[openblackhole/openblackhole-enigma2.git] / lib / python / Tools / KeyBindings.py
1
2 keyBindings = { }
3
4 from keyids import KEYIDS
5 from Components.config import config
6 from Components.RcModel import rc_model
7
8 keyDescriptions = [{
9                 KEYIDS["BTN_0"]: ("UP", "fp"),
10                 KEYIDS["BTN_1"]: ("DOWN", "fp"),
11                 KEYIDS["KEY_OK"]: ("OK", ""),
12                 KEYIDS["KEY_UP"]: ("UP",),
13                 KEYIDS["KEY_DOWN"]: ("DOWN",),
14                 KEYIDS["KEY_POWER"]: ("POWER",),
15                 KEYIDS["KEY_RED"]: ("RED",),
16                 KEYIDS["KEY_BLUE"]: ("BLUE",),
17                 KEYIDS["KEY_GREEN"]: ("GREEN",),
18                 KEYIDS["KEY_YELLOW"]: ("YELLOW",),
19                 KEYIDS["KEY_MENU"]: ("MENU",),
20                 KEYIDS["KEY_LEFT"]: ("LEFT",),
21                 KEYIDS["KEY_RIGHT"]: ("RIGHT",),
22                 KEYIDS["KEY_VIDEO"]: ("PVR",),
23                 KEYIDS["KEY_INFO"]: ("INFO",),
24                 KEYIDS["KEY_AUDIO"]: ("YELLOW",),
25                 KEYIDS["KEY_TV"]: ("TV",),
26                 KEYIDS["KEY_RADIO"]: ("RADIO",),
27                 KEYIDS["KEY_TEXT"]: ("TEXT",),
28                 KEYIDS["KEY_NEXT"]: ("ARROWRIGHT",),
29                 KEYIDS["KEY_PREVIOUS"]: ("ARROWLEFT",),
30                 KEYIDS["KEY_PREVIOUSSONG"]: ("REWIND",),
31                 KEYIDS["KEY_PLAYPAUSE"]: ("PLAYPAUSE",),
32                 KEYIDS["KEY_PLAY"]: ("PLAYPAUSE",),
33                 KEYIDS["KEY_NEXTSONG"]: ("FASTFORWARD",),
34                 KEYIDS["KEY_CHANNELUP"]: ("BOUQUET+",),
35                 KEYIDS["KEY_CHANNELDOWN"]: ("BOUQUET-",),
36                 KEYIDS["KEY_0"]: ("0",),
37                 KEYIDS["KEY_1"]: ("1",),
38                 KEYIDS["KEY_2"]: ("2",),
39                 KEYIDS["KEY_3"]: ("3",),
40                 KEYIDS["KEY_4"]: ("4",),
41                 KEYIDS["KEY_5"]: ("5",),
42                 KEYIDS["KEY_6"]: ("6",),
43                 KEYIDS["KEY_7"]: ("7",),
44                 KEYIDS["KEY_8"]: ("8",),
45                 KEYIDS["KEY_9"]: ("9",),
46                 KEYIDS["KEY_EXIT"]: ("EXIT",),
47                 KEYIDS["KEY_STOP"]: ("STOP",),
48                 KEYIDS["KEY_RECORD"]: ("RECORD",)
49         },
50         {
51                 KEYIDS["BTN_0"]: ("UP", "fp"),
52                 KEYIDS["BTN_1"]: ("DOWN", "fp"),
53                 KEYIDS["KEY_OK"]: ("OK", ""),
54                 KEYIDS["KEY_UP"]: ("UP",),
55                 KEYIDS["KEY_DOWN"]: ("DOWN",),
56                 KEYIDS["KEY_POWER"]: ("POWER",),
57                 KEYIDS["KEY_RED"]: ("RED",),
58                 KEYIDS["KEY_BLUE"]: ("BLUE",),
59                 KEYIDS["KEY_GREEN"]: ("GREEN",),
60                 KEYIDS["KEY_YELLOW"]: ("YELLOW",),
61                 KEYIDS["KEY_MENU"]: ("MENU",),
62                 KEYIDS["KEY_LEFT"]: ("LEFT",),
63                 KEYIDS["KEY_RIGHT"]: ("RIGHT",),
64                 KEYIDS["KEY_VIDEO"]: ("VIDEO",),
65                 KEYIDS["KEY_INFO"]: ("INFO",),
66                 KEYIDS["KEY_AUDIO"]: ("AUDIO",),
67                 KEYIDS["KEY_TV"]: ("TV",),
68                 KEYIDS["KEY_RADIO"]: ("RADIO",),
69                 KEYIDS["KEY_TEXT"]: ("TEXT",),
70                 KEYIDS["KEY_NEXT"]: ("ARROWRIGHT",),
71                 KEYIDS["KEY_PREVIOUS"]: ("ARROWLEFT",),
72                 KEYIDS["KEY_PREVIOUSSONG"]: ("RED", "SHIFT"),
73                 KEYIDS["KEY_PLAYPAUSE"]: ("YELLOW", "SHIFT"),
74                 KEYIDS["KEY_PLAY"]: ("GREEN", "SHIFT"),
75                 KEYIDS["KEY_NEXTSONG"]: ("BLUE", "SHIFT"),
76                 KEYIDS["KEY_CHANNELUP"]: ("BOUQUET+",),
77                 KEYIDS["KEY_CHANNELDOWN"]: ("BOUQUET-",),
78                 KEYIDS["KEY_0"]: ("0",),
79                 KEYIDS["KEY_1"]: ("1",),
80                 KEYIDS["KEY_2"]: ("2",),
81                 KEYIDS["KEY_3"]: ("3",),
82                 KEYIDS["KEY_4"]: ("4",),
83                 KEYIDS["KEY_5"]: ("5",),
84                 KEYIDS["KEY_6"]: ("6",),
85                 KEYIDS["KEY_7"]: ("7",),
86                 KEYIDS["KEY_8"]: ("8",),
87                 KEYIDS["KEY_9"]: ("9",),
88                 KEYIDS["KEY_EXIT"]: ("EXIT",),
89                 KEYIDS["KEY_STOP"]: ("TV", "SHIFT"),
90                 KEYIDS["KEY_RECORD"]: ("RADIO", "SHIFT")
91         },
92         {
93                 KEYIDS["BTN_0"]: ("UP", "fp"),
94                 KEYIDS["BTN_1"]: ("DOWN", "fp"),
95                 KEYIDS["KEY_OK"]: ("OK", ""),
96                 KEYIDS["KEY_UP"]: ("UP",),
97                 KEYIDS["KEY_DOWN"]: ("DOWN",),
98                 KEYIDS["KEY_POWER"]: ("POWER",),
99                 KEYIDS["KEY_RED"]: ("RED",),
100                 KEYIDS["KEY_BLUE"]: ("BLUE",),
101                 KEYIDS["KEY_GREEN"]: ("GREEN",),
102                 KEYIDS["KEY_YELLOW"]: ("YELLOW",),
103                 KEYIDS["KEY_MENU"]: ("MENU",),
104                 KEYIDS["KEY_LEFT"]: ("LEFT",),
105                 KEYIDS["KEY_RIGHT"]: ("RIGHT",),
106                 KEYIDS["KEY_VIDEO"]: ("PVR",),
107                 KEYIDS["KEY_INFO"]: ("INFO",),
108                 KEYIDS["KEY_AUDIO"]: ("AUDIO",),
109                 KEYIDS["KEY_TV"]: ("TV",),
110                 KEYIDS["KEY_RADIO"]: ("RADIO",),
111                 KEYIDS["KEY_TEXT"]: ("TEXT",),
112                 KEYIDS["KEY_NEXT"]: ("ARROWRIGHT",),
113                 KEYIDS["KEY_PREVIOUS"]: ("ARROWLEFT",),
114                 KEYIDS["KEY_PREVIOUSSONG"]: ("REWIND",),
115                 KEYIDS["KEY_PLAYPAUSE"]: ("PAUSE",),
116                 KEYIDS["KEY_PLAY"]: ("PLAY",),
117                 KEYIDS["KEY_NEXTSONG"]: ("FASTFORWARD",),
118                 KEYIDS["KEY_CHANNELUP"]: ("BOUQUET+",),
119                 KEYIDS["KEY_CHANNELDOWN"]: ("BOUQUET-",),
120                 KEYIDS["KEY_0"]: ("0",),
121                 KEYIDS["KEY_1"]: ("1",),
122                 KEYIDS["KEY_2"]: ("2",),
123                 KEYIDS["KEY_3"]: ("3",),
124                 KEYIDS["KEY_4"]: ("4",),
125                 KEYIDS["KEY_5"]: ("5",),
126                 KEYIDS["KEY_6"]: ("6",),
127                 KEYIDS["KEY_7"]: ("7",),
128                 KEYIDS["KEY_8"]: ("8",),
129                 KEYIDS["KEY_9"]: ("9",),
130                 KEYIDS["KEY_EXIT"]: ("EXIT",),
131                 KEYIDS["KEY_STOP"]: ("STOP",),
132                 KEYIDS["KEY_RECORD"]: ("RECORD",)
133         },
134         {       # XP1000
135                 KEYIDS["BTN_0"]: ("UP", "fp"),
136                 KEYIDS["BTN_1"]: ("DOWN", "fp"),
137                 KEYIDS["KEY_OK"]: ("OK", ""),
138                 KEYIDS["KEY_UP"]: ("UP",),
139                 KEYIDS["KEY_DOWN"]: ("DOWN",),
140                 KEYIDS["KEY_POWER"]: ("POWER",),
141                 KEYIDS["KEY_RED"]: ("RED",),
142                 KEYIDS["KEY_BLUE"]: ("BLUE",),
143                 KEYIDS["KEY_GREEN"]: ("GREEN",),
144                 KEYIDS["KEY_YELLOW"]: ("YELLOW",),
145                 KEYIDS["KEY_MENU"]: ("MENU",),
146                 KEYIDS["KEY_LEFT"]: ("LEFT",),
147                 KEYIDS["KEY_RIGHT"]: ("RIGHT",),
148                 KEYIDS["KEY_VIDEO"]: ("PVR",),
149                 KEYIDS["KEY_INFO"]: ("INFO",),
150                 KEYIDS["KEY_AUDIO"]: ("AUDIO",),
151                 KEYIDS["KEY_SUBTITLE"]: ("SUBTITLE",),
152                 KEYIDS["KEY_TV"]: ("TV",),
153                 KEYIDS["KEY_RADIO"]: ("RADIO",),
154                 KEYIDS["KEY_TEXT"]: ("TEXT",),
155                 KEYIDS["KEY_NEXT"]: ("ARROWRIGHT",),
156                 KEYIDS["KEY_PREVIOUS"]: ("ARROWLEFT",),
157                 KEYIDS["KEY_PREVIOUSSONG"]: ("SKIPBACK",),
158                 KEYIDS["KEY_REWIND"]: ("REWIND",),
159                 KEYIDS["KEY_FASTFORWARD"]: ("FASTFORWARD",),
160                 KEYIDS["KEY_NEXTSONG"]: ("SKIPFORWARD",),
161                 KEYIDS["KEY_PLAYPAUSE"]: ("PLAYPAUSE",),
162                 KEYIDS["KEY_CHANNELUP"]: ("BOUQUET+",),
163                 KEYIDS["KEY_CHANNELDOWN"]: ("BOUQUET-",),
164                 KEYIDS["KEY_0"]: ("0",),
165                 KEYIDS["KEY_1"]: ("1",),
166                 KEYIDS["KEY_2"]: ("2",),
167                 KEYIDS["KEY_3"]: ("3",),
168                 KEYIDS["KEY_4"]: ("4",),
169                 KEYIDS["KEY_5"]: ("5",),
170                 KEYIDS["KEY_6"]: ("6",),
171                 KEYIDS["KEY_7"]: ("7",),
172                 KEYIDS["KEY_8"]: ("8",),
173                 KEYIDS["KEY_9"]: ("9",),
174                 KEYIDS["KEY_EXIT"]: ("EXIT",),
175                 KEYIDS["KEY_STOP"]: ("STOP",),
176                 KEYIDS["KEY_RECORD"]: ("RECORD",),
177                 KEYIDS["KEY_BOOKMARKS"]: ("PORTAL",),
178                 KEYIDS["KEY_VMODE"]: ("VMODE",),
179                 KEYIDS["KEY_PROGRAM"]: ("TIMER",),
180                 KEYIDS["KEY_SLEEP"]: ("SLEEP",),
181                 KEYIDS["KEY_EPG"]: ("EPG",),
182         },
183         {       # Formuler F1
184                 KEYIDS["BTN_0"]: ("UP", "fp"),
185                 KEYIDS["BTN_1"]: ("DOWN", "fp"),
186                 KEYIDS["KEY_OK"]: ("OK", ""),
187                 KEYIDS["KEY_UP"]: ("UP",),
188                 KEYIDS["KEY_DOWN"]: ("DOWN",),
189                 KEYIDS["KEY_POWER"]: ("POWER",),
190                 KEYIDS["KEY_RED"]: ("RED",),
191                 KEYIDS["KEY_BLUE"]: ("BLUE",),
192                 KEYIDS["KEY_GREEN"]: ("GREEN",),
193                 KEYIDS["KEY_YELLOW"]: ("YELLOW",),
194                 KEYIDS["KEY_MENU"]: ("MENU",),
195                 KEYIDS["KEY_LEFT"]: ("LEFT",),
196                 KEYIDS["KEY_RIGHT"]: ("RIGHT",),
197                 KEYIDS["KEY_VIDEO"]: ("PVR",),
198                 KEYIDS["KEY_INFO"]: ("INFO",),
199                 KEYIDS["KEY_AUDIO"]: ("AUDIO",),
200                 KEYIDS["KEY_TV"]: ("TV",),
201                 KEYIDS["KEY_RADIO"]: ("RADIO",),
202                 KEYIDS["KEY_TEXT"]: ("TEXT",),
203                 KEYIDS["KEY_NEXT"]: ("ARROWRIGHT",),
204                 KEYIDS["KEY_PREVIOUS"]: ("ARROWLEFT",),
205                 KEYIDS["KEY_REWIND"]: ("REWIND",),
206                 KEYIDS["KEY_PAUSE"]: ("PAUSE",),
207                 KEYIDS["KEY_PLAY"]: ("PLAY",),
208                 KEYIDS["KEY_FASTFORWARD"]: ("FASTFORWARD",),
209                 KEYIDS["KEY_CHANNELUP"]: ("BOUQUET+",),
210                 KEYIDS["KEY_CHANNELDOWN"]: ("BOUQUET-",),
211                 KEYIDS["KEY_0"]: ("0",),
212                 KEYIDS["KEY_1"]: ("1",),
213                 KEYIDS["KEY_2"]: ("2",),
214                 KEYIDS["KEY_3"]: ("3",),
215                 KEYIDS["KEY_4"]: ("4",),
216                 KEYIDS["KEY_5"]: ("5",),
217                 KEYIDS["KEY_6"]: ("6",),
218                 KEYIDS["KEY_7"]: ("7",),
219                 KEYIDS["KEY_8"]: ("8",),
220                 KEYIDS["KEY_9"]: ("9",),
221                 KEYIDS["KEY_EXIT"]: ("EXIT",),
222                 KEYIDS["KEY_STOP"]: ("STOP",),
223                 KEYIDS["KEY_RECORD"]: ("RECORD",),
224                 KEYIDS["KEY_F1"]: ("F1",),
225                 KEYIDS["KEY_F2"]: ("F2",),
226                 KEYIDS["KEY_F3"]: ("F3",),
227                 KEYIDS["KEY_BACK"]: ("RECALL",),
228                 KEYIDS["KEY_CONTEXT_MENU"]: ("CONTEXT",),
229                 KEYIDS["KEY_EPG"]: ("EPG",),
230                 KEYIDS["KEY_BOOKMARKS"]: ("PLAYLIST",),
231         },
232 ]
233
234 def addKeyBinding(domain, key, context, action, flags):
235         keyBindings.setdefault((context, action), []).append((key, domain, flags))
236
237 # returns a list of (key, flags) for a specified action
238 def queryKeyBinding(context, action):
239         if (context, action) in keyBindings:
240                 return [(x[0], x[2]) for x in keyBindings[(context, action)]]
241         else:
242                 return [ ]
243
244 def getKeyDescription(key):
245         if rc_model.rcIsDefault():
246                 idx = config.misc.rcused.value
247         else:
248                 rctype = config.plugins.remotecontroltype.rctype.value
249                 if rctype == 14:        # XP1000
250                         idx = 3
251                 elif rctype == 18:      # F1
252                         idx = 4
253                 else:
254                         idx = 2
255         if key in keyDescriptions[idx]:
256                 return keyDescriptions[idx].get(key, [ ])
257
258 def removeKeyBindings(domain):
259         # remove all entries of domain 'domain'
260         for x in keyBindings:
261                 keyBindings[x] = filter(lambda e: e[1] != domain, keyBindings[x])