Skip to content

Commit eca8cf6

Browse files
committedAug 2, 2020
buttons now a list
1 parent 4b339d0 commit eca8cf6

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed
 

‎bluedot/dot.py

+16-23
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,11 @@ class BlueDot(Dot):
772772
bd.wait_for_press()
773773
print("The button was pressed")
774774
775+
If there are multiple buttons, each button can be referenced using its [col, row]::
776+
777+
bd = BlueDot()
778+
first_button = bd[0,0]
779+
775780
:param str device:
776781
The Bluetooth device the server should use, the default is "hci0", if
777782
your device only has 1 Bluetooth adapter this shouldn't need to be changed.
@@ -842,21 +847,9 @@ def __init__(self,
842847
@property
843848
def buttons(self):
844849
"""
845-
A dictionary of :class:`BlueDotButton` objects in the "grid".
846-
847-
The key is [col,row].
848-
849-
To return the 'first' button at grid position 0,0 ::
850-
851-
bd = BlueDot()
852-
first_button = bd.buttons[0,0]
853-
854-
Or alternatively:
855-
856-
bd = BlueDot()
857-
first_button = bd[0,0]
850+
A list of :class:`BlueDotButton` objects in the "grid".
858851
"""
859-
return self._buttons
852+
return self._buttons.values()
860853

861854
@property
862855
def cols(self):
@@ -959,7 +952,7 @@ def is_pressed(self):
959952
If there are multiple buttons, if any button is pressed, `True`
960953
will be returned.
961954
"""
962-
for button in self.buttons.values():
955+
for button in self.buttons:
963956
if button._is_pressed:
964957
return True
965958

@@ -999,7 +992,7 @@ def rotation_segments(self):
999992
@rotation_segments.setter
1000993
def rotation_segments(self, value):
1001994
super(BlueDot, self.__class__).rotation_segments.fset(self, value)
1002-
for button in self.buttons.values():
995+
for button in self.buttons:
1003996
button.rotation_segments = value
1004997

1005998
@property
@@ -1017,7 +1010,7 @@ def double_press_time(self):
10171010
@double_press_time.setter
10181011
def double_press_time(self, value):
10191012
super(BlueDot, self.__class__).double_press_time.fset(self, value)
1020-
for button in self.buttons.values():
1013+
for button in self.buttons:
10211014
button.double_press_time = value
10221015

10231016
@property
@@ -1044,7 +1037,7 @@ def color(self):
10441037
@color.setter
10451038
def color(self, value):
10461039
super(BlueDot, self.__class__).color.fset(self, value)
1047-
for button in self.buttons.values():
1040+
for button in self.buttons:
10481041
button.color = value
10491042

10501043
@property
@@ -1062,7 +1055,7 @@ def square(self):
10621055
@square.setter
10631056
def square(self, value):
10641057
super(BlueDot, self.__class__).square.fset(self, value)
1065-
for button in self.buttons.values():
1058+
for button in self.buttons:
10661059
button.square = value
10671060

10681061
@property
@@ -1080,7 +1073,7 @@ def border(self):
10801073
@border.setter
10811074
def border(self, value):
10821075
super(BlueDot, self.__class__).border.fset(self, value)
1083-
for button in self.buttons.values():
1076+
for button in self.buttons:
10841077
button.border = value
10851078

10861079
@property
@@ -1101,7 +1094,7 @@ def visible(self):
11011094
@visible.setter
11021095
def visible(self, value):
11031096
super(BlueDot, self.__class__).visible.fset(self, value)
1104-
for button in self.buttons.values():
1097+
for button in self.buttons:
11051098
button.visible = value
11061099

11071100
@property
@@ -1242,7 +1235,7 @@ def resize(self, cols, rows):
12421235

12431236
def _get_button(self, key):
12441237
try:
1245-
return self.buttons[key]
1238+
return self._buttons[key]
12461239
except KeyError:
12471240
raise ButtonDoesNotExist("The button `{}` does not exist".format(key))
12481241

@@ -1399,7 +1392,7 @@ def _send_bluedot_config(self):
13991392

14001393
# send the configuration for the individual buttons
14011394
button_config_msg = ""
1402-
for button in self.buttons.values():
1395+
for button in self.buttons:
14031396
if button.modified:
14041397
button_config_msg += button.build_config_msg()
14051398

‎tests/test_blue_dot.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_default_values():
2424
assert mbd.when_released == None
2525
assert mbd.when_swiped == None
2626

27-
assert len(mbd.buttons.values()) == 1
27+
assert len(mbd.buttons) == 1
2828

2929
def test_modify_values():
3030
mbd = MockBlueDot(device = "hci1", port = 2, auto_start_server = False, print_messages = False, cols = 3, rows = 2)
@@ -46,7 +46,7 @@ def test_modify_values():
4646
mbd.rotation_segments = 16
4747
assert mbd.rotation_segments == 16
4848

49-
assert len(mbd.buttons.values()) == 6
49+
assert len(mbd.buttons) == 6
5050

5151
def test_start_stop():
5252
mbd = MockBlueDot(auto_start_server = False)
@@ -108,7 +108,7 @@ def test_resize():
108108

109109
assert mbd.cols == 4
110110
assert mbd.rows == 3
111-
assert len(mbd.buttons.values()) == 12
111+
assert len(mbd.buttons) == 12
112112

113113
def test_pressed_moved_released():
114114
mbd = MockBlueDot()
@@ -622,7 +622,7 @@ def test_dot_appearance():
622622

623623
mbd.resize(2,1)
624624

625-
for button in mbd.buttons.values():
625+
for button in mbd.buttons:
626626
assert button.color == "blue"
627627
assert button.border == False
628628
assert button.square == False

0 commit comments

Comments
 (0)
Please sign in to comment.