summaryrefslogtreecommitdiffstats
path: root/xkb.py
blob: f4903dbf2fe3d6cbfea0eb57350b9a9c22378362 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import _xkb
import tree
import string
import os

class XKB:
    def __init__ (self):
        self.rules = _xkb.list_rules ()                            

    def getRules (self):
        return self.rules

    def getModels (self):
        return self.rules[0]

    def getLayouts (self):
        return self.rules[1]

    def getVariants (self):
        return self.rules[2]

    def getOptions (self):
        keys = self.rules[3].keys (); keys.sort ()
        groups = ()
        for x in keys:
            groups = tree.merge (groups, string.split (x, ":"))
        return (groups, self.rules[3])

    def setRule (self, model, layout, variant, options):
	if model == None: model = ""
	if layout == None: layout = ""
	if variant == None: variant = ""
	if options == None: options = ""

	args = ()

	if (model):
            args = args + ("-model", model)
        if (layout):
            args = args + ("-layout", layout)
        if (variant):
            args = args + ("-variant", variant)

	path = ("/usr/X11R6/bin/setxkbmap",)
        child = os.fork ()
        if (child == 0):
            os.execv (path[0], path + args)

        try:
            pid, status = os.waitpid(child, 0)
        except OSError, (errno, msg):
            print __name__, "waitpid:", msg
        return

        # don't use any of our code, since it seems to corrupt
        # lots of memory
        return _xkb.set_rule (model, layout, variant, options)

    def getRulesBase (self):
        return _xkb.get_rulesbase ()

    def setMouseKeys (self, flag):
        return _xkb.set_mousekeys (flag)
    
    def getMouseKeys (self):
        return _xkb.get_mousekeys ()

if __name__ == "__main__":
    xkb = XKB()
    print xkb.getVariants()