Merge branch 'bug_532_fixed_servicelist_contextmenu_crash'
[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
5 class Keyboard:
6         def __init__(self):
7                 self.keyboardmaps = []
8                 self.readKeyboardMapFiles()
9
10         def readKeyboardMapFiles(self):
11                 for keymapfile in os_listdir('/usr/share/keymaps/'):
12                         if (keymapfile.endswith(".info")):
13                                 f = open('/usr/share/keymaps/' + keymapfile)
14                                 mapfile = None
15                                 mapname = None
16                                 for line in f:
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                                 f.close()
27
28                 if len(self.keyboardmaps) == 0:
29                         self.keyboardmaps = [('dream-de.kmap', 'Dreambox Keyboard Deutsch'), ('eng.kmap', 'Keyboard English')]
30
31         def activateKeyboardMap(self, index):
32                 try:
33                         keymap = self.keyboardmaps[index]
34                         print "Activating keymap:",keymap[1]
35                         keymappath = '/usr/share/keymaps/' + keymap[0]
36                         if os_path.exists(keymappath):
37                                 Console().ePopen(("loadkmap < " + str(keymappath)))
38                 except:
39                         print "Selected keymap does not exist!"
40
41         def getKeyboardMaplist(self):
42                 return self.keyboardmaps
43
44         def getDefaultKeyboardMap(self):
45                 return 'eng.kmap'
46
47 keyboard = Keyboard()