Merge branch 'master' into obi/master
[enigma2.git] / lib / python / Tools / KeyBindings.py
index f0a70d5ced5ad6850b9021838ba39a9139b015bc..c73ecf537933aedb9950dad03c7601e28147a5ea 100644 (file)
 keyBindings = { }
 
 from keyids import KEYIDS
+from Components.config import config
 
-keyDescriptions = {
-               KEYIDS["BTN_0"]: ("fp_up", 630, 320),
-               KEYIDS["BTN_1"]: ("fp_down", 565, 320),
-               KEYIDS["KEY_OK"]: ("ok", 585, 320),
-               KEYIDS["KEY_UP"]: ("up", 585, 290),
-               KEYIDS["KEY_DOWN"]: ("down", 585, 355),
-               KEYIDS["KEY_POWER"]: ("power", 615, 80),
-               KEYIDS["KEY_RED"]: ("red", 555, 390),
-               KEYIDS["KEY_BLUE"]: ("blue", 640, 390),
-               KEYIDS["KEY_GREEN"]: ("green", 585, 390),
-               KEYIDS["KEY_YELLOW"]: ("yellow", 610, 390),
-               KEYIDS["KEY_MENU"]: ("menu", 645, 290),
-               KEYIDS["KEY_LEFT"]: ("left", 565, 320),
-               KEYIDS["KEY_RIGHT"]: ("right", 630, 320),
-               KEYIDS["KEY_VIDEO"]: ("video", 645, 355),
-               KEYIDS["KEY_INFO"]: ("info", 550, 290),
-               KEYIDS["KEY_AUDIO"]: ("audio", 555, 355),
-               KEYIDS["KEY_TV"]: ("tv", 560, 425),
-               KEYIDS["KEY_RADIO"]: ("radio", 585, 425),
-               KEYIDS["KEY_TEXT"]: ("text", 610, 425),
-               KEYIDS["KEY_NEXT"]: ("next", 635, 203),
-               KEYIDS["KEY_PREVIOUS"]: ("prev", 559, 203)
+keyDescriptions = [{
+               KEYIDS["BTN_0"]: ("UP", "fp"),
+               KEYIDS["BTN_1"]: ("DOWN", "fp"),
+               KEYIDS["KEY_OK"]: ("OK", ""),
+               KEYIDS["KEY_UP"]: ("UP",),
+               KEYIDS["KEY_DOWN"]: ("DOWN",),
+               KEYIDS["KEY_POWER"]: ("POWER",),
+               KEYIDS["KEY_RED"]: ("RED",),
+               KEYIDS["KEY_BLUE"]: ("BLUE",),
+               KEYIDS["KEY_GREEN"]: ("GREEN",),
+               KEYIDS["KEY_YELLOW"]: ("YELLOW",),
+               KEYIDS["KEY_MENU"]: ("MENU",),
+               KEYIDS["KEY_LEFT"]: ("LEFT",),
+               KEYIDS["KEY_RIGHT"]: ("RIGHT",),
+               KEYIDS["KEY_VIDEO"]: ("PVR",),
+               KEYIDS["KEY_INFO"]: ("INFO",),
+               KEYIDS["KEY_AUDIO"]: ("YELLOW",),
+               KEYIDS["KEY_TV"]: ("TV",),
+               KEYIDS["KEY_RADIO"]: ("RADIO",),
+               KEYIDS["KEY_TEXT"]: ("TEXT",),
+               KEYIDS["KEY_NEXT"]: ("ARROWRIGHT",),
+               KEYIDS["KEY_PREVIOUS"]: ("ARROWLEFT",),
+               KEYIDS["KEY_PREVIOUSSONG"]: ("BLUE", "SHIFT"),
+               KEYIDS["KEY_PLAYPAUSE"]: ("PLAYPAUSE",),
+               KEYIDS["KEY_PLAY"]: ("PLAYPAUSE",),
+               KEYIDS["KEY_NEXTSONG"]: ("RED", "SHIFT"),
+               KEYIDS["KEY_CHANNELUP"]: ("BOUQUET+",),
+               KEYIDS["KEY_CHANNELDOWN"]: ("BOUQUET-",),
+               KEYIDS["KEY_0"]: ("0",),
+               KEYIDS["KEY_1"]: ("1",),
+               KEYIDS["KEY_2"]: ("2",),
+               KEYIDS["KEY_3"]: ("3",),
+               KEYIDS["KEY_4"]: ("4",),
+               KEYIDS["KEY_5"]: ("5",),
+               KEYIDS["KEY_6"]: ("6",),
+               KEYIDS["KEY_7"]: ("7",),
+               KEYIDS["KEY_8"]: ("8",),
+               KEYIDS["KEY_9"]: ("9",),
+               KEYIDS["KEY_EXIT"]: ("EXIT",),
+               KEYIDS["KEY_STOP"]: ("TV", "SHIFT"),
+               KEYIDS["KEY_RECORD"]: ("RECORD",)
+       },
+       {
+               KEYIDS["BTN_0"]: ("UP", "fp"),
+               KEYIDS["BTN_1"]: ("DOWN", "fp"),
+               KEYIDS["KEY_OK"]: ("OK", ""),
+               KEYIDS["KEY_UP"]: ("UP",),
+               KEYIDS["KEY_DOWN"]: ("DOWN",),
+               KEYIDS["KEY_POWER"]: ("POWER",),
+               KEYIDS["KEY_RED"]: ("RED",),
+               KEYIDS["KEY_BLUE"]: ("BLUE",),
+               KEYIDS["KEY_GREEN"]: ("GREEN",),
+               KEYIDS["KEY_YELLOW"]: ("YELLOW",),
+               KEYIDS["KEY_MENU"]: ("MENU",),
+               KEYIDS["KEY_LEFT"]: ("LEFT",),
+               KEYIDS["KEY_RIGHT"]: ("RIGHT",),
+               KEYIDS["KEY_VIDEO"]: ("VIDEO",),
+               KEYIDS["KEY_INFO"]: ("INFO",),
+               KEYIDS["KEY_AUDIO"]: ("AUDIO",),
+               KEYIDS["KEY_TV"]: ("TV",),
+               KEYIDS["KEY_RADIO"]: ("RADIO",),
+               KEYIDS["KEY_TEXT"]: ("TEXT",),
+               KEYIDS["KEY_NEXT"]: ("ARROWRIGHT",),
+               KEYIDS["KEY_PREVIOUS"]: ("ARROWLEFT",),
+               KEYIDS["KEY_PREVIOUSSONG"]: ("BLUE", "SHIFT"),
+               KEYIDS["KEY_PLAYPAUSE"]: ("YELLOW", "SHIFT"),
+               KEYIDS["KEY_PLAY"]: ("GREEN", "SHIFT"),
+               KEYIDS["KEY_NEXTSONG"]: ("RED", "SHIFT"),
+               KEYIDS["KEY_CHANNELUP"]: ("BOUQUET+",),
+               KEYIDS["KEY_CHANNELDOWN"]: ("BOUQUET-",),
+               KEYIDS["KEY_0"]: ("0",),
+               KEYIDS["KEY_1"]: ("1",),
+               KEYIDS["KEY_2"]: ("2",),
+               KEYIDS["KEY_3"]: ("3",),
+               KEYIDS["KEY_4"]: ("4",),
+               KEYIDS["KEY_5"]: ("5",),
+               KEYIDS["KEY_6"]: ("6",),
+               KEYIDS["KEY_7"]: ("7",),
+               KEYIDS["KEY_8"]: ("8",),
+               KEYIDS["KEY_9"]: ("9",),
+               KEYIDS["KEY_EXIT"]: ("EXIT",),
+               KEYIDS["KEY_STOP"]: ("TV", "SHIFT"),
+               KEYIDS["KEY_RECORD"]: ("RADIO", "SHIFT")
        }
+]
 
-def addKeyBinding(key, context, action):
-       if (context, action) in keyBindings:
-               keyBindings[(context, action)].append(key)
-       else:
-               keyBindings[(context, action)] = [key]
+def addKeyBinding(domain, key, context, action, flags):
+       keyBindings.setdefault((context, action), []).append((key, domain, flags))
 
+# returns a list of (key, flags) for a specified action
 def queryKeyBinding(context, action):
        if (context, action) in keyBindings:
-               return keyBindings[(context, action)]
+               return [(x[0], x[2]) for x in keyBindings[(context, action)]]
        else:
                return [ ]
 
 def getKeyDescription(key):
-       if key in keyDescriptions:
-               return keyDescriptions.get(key, [ ])
+       if key in keyDescriptions[config.misc.rcused.value]:
+               return keyDescriptions[config.misc.rcused.value].get(key, [ ])
+
+def removeKeyBindings(domain):
+       # remove all entries of domain 'domain'
+       for x in keyBindings:
+               keyBindings[x] = filter(lambda e: e[1] != domain, keyBindings[x])