-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttons.py
56 lines (36 loc) · 1.42 KB
/
buttons.py
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
#!/usr/bin/python
class Buttons(object):
def __init__(self, chord = None, hold = False, middle_switch = False):
self.chord = chord or []
self.hold = hold
self.middle_switch = middle_switch
def get_inferred_arguments(self, actually_pressed):
return []
def __repr__(self):
return "Buttons(%s, %s, %s)"%(repr(self.chord),
repr(self.hold),
repr(self.middle_switch))
def __eq__(self, other):
return (self.chord == other.chord
and self.hold == other.hold
and self.middle_switch == other.middle_switch)
class AnyButtons(Buttons):
def __init__(self, any_of, *args):
Buttons.__init__(self, None, *args)
self.any_of = any_of
def get_inferred_arguments(self, actually_pressed):
args = [self.any_of[btn] for btn in filter((lambda btn: btn in self.any_of),
actually_pressed.buttons.chord)]
return args
def __eq__(self, other):
try:
match = self.any_of == other.any_of
except AttributeError:
match = set(other.chord).issubset(set(self.any_of.iterkeys()))
return (match
and self.hold == other.hold
and self.middle_switch == other.middle_switch)
def __repr__(self):
return "AnyButtons(%s, %s, %s)"%(repr(self.any_of),
repr(self.hold),
repr(self.middle_switch))