4.3.3r1
[enigma2.git] / usr / lib / enigma2 / python / Tools / KeyBindings.py
1
2 keyBindings = { }
3
4 from keyids import KEYIDS
5 from Components.config import config
6
7 keyDescriptions = [{
8                 KEYIDS["BTN_0"]: ("UP", "fp"),
9                 KEYIDS["BTN_1"]: ("DOWN", "fp"),
10                 KEYIDS["KEY_OK"]: ("OK", ""),
11                 KEYIDS["KEY_UP"]: ("UP",),
12                 KEYIDS["KEY_DOWN"]: ("DOWN",),
13                 KEYIDS["KEY_POWER"]: ("POWER",),
14                 KEYIDS["KEY_RED"]: ("RED",),
15                 KEYIDS["KEY_BLUE"]: ("BLUE",),
16                 KEYIDS["KEY_GREEN"]: ("GREEN",),
17                 KEYIDS["KEY_YELLOW"]: ("YELLOW",),
18                 KEYIDS["KEY_MENU"]: ("MENU",),
19                 KEYIDS["KEY_LEFT"]: ("LEFT",),
20                 KEYIDS["KEY_RIGHT"]: ("RIGHT",),
21                 KEYIDS["KEY_VIDEO"]: ("PVR",),
22                 KEYIDS["KEY_INFO"]: ("INFO",),
23                 KEYIDS["KEY_AUDIO"]: ("YELLOW",),
24                 KEYIDS["KEY_TV"]: ("TV",),
25                 KEYIDS["KEY_RADIO"]: ("RADIO",),
26                 KEYIDS["KEY_TEXT"]: ("TEXT",),
27                 KEYIDS["KEY_NEXT"]: ("ARROWRIGHT",),
28                 KEYIDS["KEY_PREVIOUS"]: ("ARROWLEFT",),
29                 KEYIDS["KEY_PREVIOUSSONG"]: ("BLUE", "SHIFT"),
30                 KEYIDS["KEY_PLAYPAUSE"]: ("PLAYPAUSE",),
31                 KEYIDS["KEY_PLAY"]: ("PLAYPAUSE",),
32                 KEYIDS["KEY_NEXTSONG"]: ("RED", "SHIFT"),
33                 KEYIDS["KEY_CHANNELUP"]: ("BOUQUET+",),
34                 KEYIDS["KEY_CHANNELDOWN"]: ("BOUQUET-",),
35                 KEYIDS["KEY_0"]: ("0",),
36                 KEYIDS["KEY_1"]: ("1",),
37                 KEYIDS["KEY_2"]: ("2",),
38                 KEYIDS["KEY_3"]: ("3",),
39                 KEYIDS["KEY_4"]: ("4",),
40                 KEYIDS["KEY_5"]: ("5",),
41                 KEYIDS["KEY_6"]: ("6",),
42                 KEYIDS["KEY_7"]: ("7",),
43                 KEYIDS["KEY_8"]: ("8",),
44                 KEYIDS["KEY_9"]: ("9",),
45                 KEYIDS["KEY_EXIT"]: ("EXIT",),
46                 KEYIDS["KEY_STOP"]: ("TV", "SHIFT"),
47                 KEYIDS["KEY_RECORD"]: ("RECORD",)
48         },
49         {
50                 KEYIDS["BTN_0"]: ("UP", "fp"),
51                 KEYIDS["BTN_1"]: ("DOWN", "fp"),
52                 KEYIDS["KEY_OK"]: ("OK", ""),
53                 KEYIDS["KEY_UP"]: ("UP",),
54                 KEYIDS["KEY_DOWN"]: ("DOWN",),
55                 KEYIDS["KEY_POWER"]: ("POWER",),
56                 KEYIDS["KEY_RED"]: ("RED",),
57                 KEYIDS["KEY_BLUE"]: ("BLUE",),
58                 KEYIDS["KEY_GREEN"]: ("GREEN",),
59                 KEYIDS["KEY_YELLOW"]: ("YELLOW",),
60                 KEYIDS["KEY_MENU"]: ("MENU",),
61                 KEYIDS["KEY_LEFT"]: ("LEFT",),
62                 KEYIDS["KEY_RIGHT"]: ("RIGHT",),
63                 KEYIDS["KEY_VIDEO"]: ("VIDEO",),
64                 KEYIDS["KEY_INFO"]: ("INFO",),
65                 KEYIDS["KEY_AUDIO"]: ("AUDIO",),
66                 KEYIDS["KEY_TV"]: ("TV",),
67                 KEYIDS["KEY_RADIO"]: ("RADIO",),
68                 KEYIDS["KEY_TEXT"]: ("TEXT",),
69                 KEYIDS["KEY_NEXT"]: ("ARROWRIGHT",),
70                 KEYIDS["KEY_PREVIOUS"]: ("ARROWLEFT",),
71                 KEYIDS["KEY_PREVIOUSSONG"]: ("BLUE", "SHIFT"),
72                 KEYIDS["KEY_PLAYPAUSE"]: ("YELLOW", "SHIFT"),
73                 KEYIDS["KEY_PLAY"]: ("GREEN", "SHIFT"),
74                 KEYIDS["KEY_NEXTSONG"]: ("RED", "SHIFT"),
75                 KEYIDS["KEY_CHANNELUP"]: ("BOUQUET+",),
76                 KEYIDS["KEY_CHANNELDOWN"]: ("BOUQUET-",),
77                 KEYIDS["KEY_0"]: ("0",),
78                 KEYIDS["KEY_1"]: ("1",),
79                 KEYIDS["KEY_2"]: ("2",),
80                 KEYIDS["KEY_3"]: ("3",),
81                 KEYIDS["KEY_4"]: ("4",),
82                 KEYIDS["KEY_5"]: ("5",),
83                 KEYIDS["KEY_6"]: ("6",),
84                 KEYIDS["KEY_7"]: ("7",),
85                 KEYIDS["KEY_8"]: ("8",),
86                 KEYIDS["KEY_9"]: ("9",),
87                 KEYIDS["KEY_EXIT"]: ("EXIT",),
88                 KEYIDS["KEY_STOP"]: ("TV", "SHIFT"),
89                 KEYIDS["KEY_RECORD"]: ("RADIO", "SHIFT")
90         },
91         {
92                 KEYIDS["BTN_0"]: ("UP", "fp"),
93                 KEYIDS["BTN_1"]: ("DOWN", "fp"),
94                 KEYIDS["KEY_OK"]: ("OK", ""),
95                 KEYIDS["KEY_UP"]: ("UP",),
96                 KEYIDS["KEY_DOWN"]: ("DOWN",),
97                 KEYIDS["KEY_POWER"]: ("POWER",),
98                 KEYIDS["KEY_RED"]: ("RED",),
99                 KEYIDS["KEY_BLUE"]: ("BLUE",),
100                 KEYIDS["KEY_GREEN"]: ("GREEN",),
101                 KEYIDS["KEY_YELLOW"]: ("YELLOW",),
102                 KEYIDS["KEY_MENU"]: ("MENU",),
103                 KEYIDS["KEY_LEFT"]: ("LEFT",),
104                 KEYIDS["KEY_RIGHT"]: ("RIGHT",),
105                 KEYIDS["KEY_VIDEO"]: ("PVR",),
106                 KEYIDS["KEY_INFO"]: ("INFO",),
107                 KEYIDS["KEY_AUDIO"]: ("AUDIO",),
108                 KEYIDS["KEY_TV"]: ("TV",),
109                 KEYIDS["KEY_RADIO"]: ("RADIO",),
110                 KEYIDS["KEY_TEXT"]: ("TEXT",),
111                 KEYIDS["KEY_NEXT"]: ("ARROWRIGHT",),
112                 KEYIDS["KEY_PREVIOUS"]: ("ARROWLEFT",),
113                 KEYIDS["KEY_PREVIOUSSONG"]: ("BLUE", "SHIFT"),
114                 KEYIDS["KEY_PLAYPAUSE"]: ("PLAYPAUSE",),
115                 KEYIDS["KEY_PLAY"]: ("PLAYPAUSE",),
116                 KEYIDS["KEY_NEXTSONG"]: ("RED", "SHIFT"),
117                 KEYIDS["KEY_CHANNELUP"]: ("BOUQUET+",),
118                 KEYIDS["KEY_CHANNELDOWN"]: ("BOUQUET-",),
119                 KEYIDS["KEY_0"]: ("0",),
120                 KEYIDS["KEY_1"]: ("1",),
121                 KEYIDS["KEY_2"]: ("2",),
122                 KEYIDS["KEY_3"]: ("3",),
123                 KEYIDS["KEY_4"]: ("4",),
124                 KEYIDS["KEY_5"]: ("5",),
125                 KEYIDS["KEY_6"]: ("6",),
126                 KEYIDS["KEY_7"]: ("7",),
127                 KEYIDS["KEY_8"]: ("8",),
128                 KEYIDS["KEY_9"]: ("9",),
129                 KEYIDS["KEY_EXIT"]: ("EXIT",),
130                 KEYIDS["KEY_STOP"]: ("TV", "SHIFT"),
131                 KEYIDS["KEY_RECORD"]: ("RECORD",)
132         },
133         {
134                 KEYIDS["BTN_0"]: ("UP", "fp"),
135                 KEYIDS["BTN_1"]: ("DOWN", "fp"),
136                 KEYIDS["KEY_OK"]: ("OK", ""),
137                 KEYIDS["KEY_UP"]: ("UP",),
138                 KEYIDS["KEY_DOWN"]: ("DOWN",),
139                 KEYIDS["KEY_POWER"]: ("POWER",),
140                 KEYIDS["KEY_RED"]: ("RED",),
141                 KEYIDS["KEY_BLUE"]: ("BLUE",),
142                 KEYIDS["KEY_GREEN"]: ("GREEN",),
143                 KEYIDS["KEY_YELLOW"]: ("YELLOW",),
144                 KEYIDS["KEY_MENU"]: ("MENU",),
145                 KEYIDS["KEY_LEFT"]: ("LEFT",),
146                 KEYIDS["KEY_RIGHT"]: ("RIGHT",),
147                 KEYIDS["KEY_VIDEO"]: ("PVR",),
148                 KEYIDS["KEY_INFO"]: ("INFO",),
149                 KEYIDS["KEY_AUDIO"]: ("AUDIO",),
150                 KEYIDS["KEY_TV"]: ("TV",),
151                 KEYIDS["KEY_RADIO"]: ("RADIO",),
152                 KEYIDS["KEY_TEXT"]: ("TEXT",),
153                 KEYIDS["KEY_NEXT"]: ("ARROWRIGHT",),
154                 KEYIDS["KEY_PREVIOUS"]: ("ARROWLEFT",),
155                 KEYIDS["KEY_PLAYPAUSE"]: ("PLAYPAUSE",),
156                 KEYIDS["KEY_PLAY"]: ("PLAYPAUSE",),
157                 KEYIDS["KEY_CHANNELUP"]: ("BOUQUET+",),
158                 KEYIDS["KEY_CHANNELDOWN"]: ("BOUQUET-",),
159                 KEYIDS["KEY_0"]: ("0",),
160                 KEYIDS["KEY_1"]: ("1",),
161                 KEYIDS["KEY_2"]: ("2",),
162                 KEYIDS["KEY_3"]: ("3",),
163                 KEYIDS["KEY_4"]: ("4",),
164                 KEYIDS["KEY_5"]: ("5",),
165                 KEYIDS["KEY_6"]: ("6",),
166                 KEYIDS["KEY_7"]: ("7",),
167                 KEYIDS["KEY_8"]: ("8",),
168                 KEYIDS["KEY_9"]: ("9",),
169                 KEYIDS["KEY_EXIT"]: ("EXIT",),
170                 KEYIDS["KEY_STOP"]: ("STOP",),
171                 KEYIDS["KEY_RECORD"]: ("RECORD",),
172                 KEYIDS["KEY_VOLUMEDOWN"]: ("VOL-",),
173                 KEYIDS["KEY_VOLUMEUP"]: ("VOL+",),
174                 KEYIDS["KEY_FASTFORWARD"] : ("FORWARD",),
175                 KEYIDS["KEY_REWIND"] : ("REWIND",),
176                 KEYIDS["KEY_MUTE"] : ("MUTE",),
177         }
178 ]
179
180 def addKeyBinding(domain, key, context, action, flags):
181         keyBindings.setdefault((context, action), []).append((key, domain, flags))
182
183 # returns a list of (key, flags) for a specified action
184 def queryKeyBinding(context, action):
185         if (context, action) in keyBindings:
186                 return [(x[0], x[2]) for x in keyBindings[(context, action)]]
187         else:
188                 return [ ]
189
190 def getKeyDescription(key):
191         if key in keyDescriptions[config.misc.rcused.value]:
192                 return keyDescriptions[config.misc.rcused.value].get(key, [ ])
193
194 def removeKeyBindings(domain):
195         # remove all entries of domain 'domain'
196         for x in keyBindings:
197                 keyBindings[x] = [e for e in keyBindings[x] if e[1] != domain]