Skip to content

Commit e9a56b1

Browse files
committed
Rename Button.check_buttons to buttons_pressed, get rid of Button.which
I had to look at the implementation of `which` to understand what was the purpose of the method, which is a bad sign. I think `buttons_pressed` is a better name for that. Also, no need to keep both `check_buttons` and `which`.
1 parent 09e612e commit e9a56b1

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

ev3dev.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,8 @@ def read_buttons(self):
17521752
for b in self.buffer_cache:
17531753
fcntl.ioctl(self.filehandle_cache[b], self.EVIOCGKEY, self.buffer_cache[b])
17541754

1755-
def check_buttons(self):
1755+
@property
1756+
def buttons_pressed(self):
17561757
pressed = []
17571758
self.read_buttons()
17581759
for k,v in self._buttons.items():
@@ -1764,16 +1765,12 @@ def check_buttons(self):
17641765

17651766
@property
17661767
def any(self):
1767-
return bool(len(self.check_buttons()) != 0)
1768-
1769-
@property
1770-
def which(self):
1771-
return self.check_buttons()
1768+
return bool(self.buttons_pressed)
17721769

17731770
def these(self,buttons={}):
17741771
if len(buttons) == 0:
17751772
return False
1776-
s = self.check_buttons()
1773+
s = self.buttons_pressed
17771774
if len(s) == 0:
17781775
return False
17791776
for b in buttons:
@@ -1794,27 +1791,27 @@ def these(self,buttons={}):
17941791

17951792
@property
17961793
def up(self):
1797-
return 'up' in self.check_buttons()
1794+
return 'up' in self.buttons_pressed
17981795

17991796
@property
18001797
def down(self):
1801-
return 'down' in self.check_buttons()
1798+
return 'down' in self.buttons_pressed
18021799

18031800
@property
18041801
def left(self):
1805-
return 'left' in self.check_buttons()
1802+
return 'left' in self.buttons_pressed
18061803

18071804
@property
18081805
def right(self):
1809-
return 'right' in self.check_buttons()
1806+
return 'right' in self.buttons_pressed
18101807

18111808
@property
18121809
def enter(self):
1813-
return 'enter' in self.check_buttons()
1810+
return 'enter' in self.buttons_pressed
18141811

18151812
@property
18161813
def backspace(self):
1817-
return 'backspace' in self.check_buttons()
1814+
return 'backspace' in self.buttons_pressed
18181815

18191816

18201817
#~autogen

templates/button-property.liquid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
{% for instance in currentClass.instances %}
77
@property
88
def {{ instance.name }}(self):
9-
return '{{ instance.name }}' in self.check_buttons()
9+
return '{{ instance.name }}' in self.buttons_pressed
1010
{% endfor %}

0 commit comments

Comments
 (0)