]> Dogcows Code - chaz/openbox/blob - python/buttonmap.py
merge the C branch into HEAD
[chaz/openbox] / python / buttonmap.py
1 from input import Pointer
2
3 def set(map):
4 """Set your buttonmap. Functions in the button map should all take a single
5 argument, a Client object, except for functions for Action_Motion events,
6 who should take 2 arguments, a PointerData object and a Client object."""
7 global _press_map, _release_map, _click_map, _doubleclick_map, _motion_map
8 Pointer.clearBinds()
9 _press_map = []
10 _release_map = []
11 _click_map = []
12 _doubleclick_map = []
13 _motion_map = []
14 for button, context, action, func in map:
15 if (action == Pointer.Action_Press):
16 _press_map.append((button, context, func))
17 mapfunc = press_run
18 if (action == Pointer.Action_Release):
19 _release_map.append((button, context, func))
20 mapfunc = release_run
21 if (action == Pointer.Action_Click):
22 _click_map.append((button, context, func))
23 mapfunc = click_run
24 if (action == Pointer.Action_DoubleClick):
25 _doubleclick_map.append((button, context, func))
26 mapfunc = doubleclick_run
27 if (action == Pointer.Action_Motion):
28 _motion_map.append((button, context, func))
29 mapfunc = motion_run
30 Pointer.bind(button, context, action, mapfunc)
31
32 def press_run(ptrdata, client):
33 """Run a button press event through the buttonmap"""
34 button = ptrdata.button
35 context = ptrdata.context
36 for but, cont, func in _press_map:
37 if (but == button and cont == context):
38 func(client)
39
40 def release_run(ptrdata, client):
41 """Run a button release event through the buttonmap"""
42 button = ptrdata.button
43 context = ptrdata.context
44 for but, cont, func in _release_map:
45 if (but == button and cont == context):
46 func(client)
47
48 def click_run(ptrdata, client):
49 """Run a button click event through the buttonmap"""
50 button = ptrdata.button
51 context = ptrdata.context
52 for but, cont, func in _click_map:
53 if (but == button and cont == context):
54 func(client)
55
56 def doubleclick_run(ptrdata, client):
57 """Run a button doubleclick event through the buttonmap"""
58 button = ptrdata.button
59 context = ptrdata.context
60 for but, cont, func in _doubleclick_map:
61 if (but == button and cont == context):
62 func(client)
63
64 def motion_run(ptrdata, client):
65 """Run a pointer motion event through the buttonmap"""
66 button = ptrdata.button
67 context = ptrdata.context
68 for but, cont, func in _motion_map:
69 if (but == button and cont == context):
70 func(ptrdata, client)
71
72 _press_map = ()
73 _release_map = ()
74 _click_map = ()
75 _doubleclick_map = ()
76 _motion_map = ()
This page took 0.037337 seconds and 4 git commands to generate.