install keymaps
[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                                 f = open(eEnv.resolve('${datadir}/keymaps/') + keymapfile)
15                                 mapfile = None
16                                 mapname = None
17                                 for line in f:
18                                         m = re_compile('^\s*(\w+)\s*=\s*(.*)\s*$').match(line)
19                                         if m:
20                                                 key, val = m.groups()
21                                                 if key == 'kmap':
22                                                     mapfile = val
23                                                 if key == 'name':
24                                                     mapname = val
25                                                 if (mapfile is not None) and (mapname is not None):
26                                                     self.keyboardmaps.append(( mapfile,mapname))
27                                 f.close()
28
29                 if len(self.keyboardmaps) == 0:
30                         self.keyboardmaps = [('dream-de.kmap', 'Dreambox Keyboard Deutsch'), ('eng.kmap', 'Keyboard English')]
31
32         def activateKeyboardMap(self, index):
33                 try:
34                         keymap = self.keyboardmaps[index]
35                         print "Activating keymap:",keymap[1]
36                         keymappath = eEnv.resolve('${datadir}/keymaps/') + keymap[0]
37                         if os_path.exists(keymappath):
38                                 Console().ePopen(("loadkmap < " + str(keymappath)))
39                 except:
40                         print "Selected keymap does not exist!"
41
42         def getKeyboardMaplist(self):
43                 return self.keyboardmaps
44
45         def getDefaultKeyboardMap(self):
46                 return 'eng.kmap'
47
48 keyboard = Keyboard()