f954adb2a4b87d9b60c8314efc6dfe02ea8147f3
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Keyboard.py
1 from Components.Console import Console
2 from os import listdir as os_listdir, path as os_path
3 from re import compile as re_compile
4 from enigma import eEnv
5
6 class Keyboard:
7         def __init__(self):
8                 self.keyboardmaps = []
9                 self.readKeyboardMapFiles()
10
11         def readKeyboardMapFiles(self):
12                 for keymapfile in os_listdir(eEnv.resolve('${datadir}/keymaps/')):
13                         if (keymapfile.endswith(".info")):
14                                 mapfile = None
15                                 mapname = None
16                                 for line in open(eEnv.resolve('${datadir}/keymaps/') + keymapfile):
17                                         m = re_compile('^\s*(\w+)\s*=\s*(.*)\s*$').match(line)
18                                         if m:
19                                                 key, val = m.groups()
20                                                 if key == 'kmap':
21                                                     mapfile = val
22                                                 if key == 'name':
23                                                     mapname = val
24                                                 if (mapfile is not None) and (mapname is not None):
25                                                     self.keyboardmaps.append(( mapfile,mapname))
26
27         def activateKeyboardMap(self, index):
28                 try:
29                         keymap = self.keyboardmaps[index]
30                         print "Activating keymap:",keymap[1]
31                         keymappath = eEnv.resolve('${datadir}/keymaps/') + keymap[0]
32                         if os_path.exists(keymappath):
33                                 Console().ePopen(("loadkmap < " + str(keymappath)))
34                 except:
35                         print "Selected keymap does not exist!"
36
37         def getKeyboardMaplist(self):
38                 return self.keyboardmaps
39
40         def getDefaultKeyboardMap(self):
41                 return 'default.kmap'
42
43 keyboard = Keyboard()