Skip to content

Commit fb67633

Browse files
committed
Update MatrixPortal example
Use buttons to move bars up and down
1 parent b8120f8 commit fb67633

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

examples/progressbar_matrixportal.py

+32-16
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,14 @@
7474

7575
# Another progress bar, with explicit range and fill from the right
7676
ranged_bar = HorizontalProgressBar(
77-
(2, 20),
78-
(40, 8),
79-
value=40,
80-
min_value=0,
81-
max_value=100,
82-
direction=HorizontalFillDirection.RIGHT_TO_LEFT,
77+
(2, 20), (40, 8), value=40, min_value=0, max_value=100, direction = HorizontalFillDirection.RIGHT_TO_LEFT,
8378
)
8479
group.insert(1, ranged_bar)
8580

8681
# Sample thermometer from -40C to 50C, with a value of +15C
8782
vertical_bar = VerticalProgressBar(
88-
(50, 4),
89-
(10, 24),
83+
(44, 4),
84+
(8, 24),
9085
min_value=-40,
9186
max_value=50,
9287
value=15,
@@ -97,6 +92,20 @@
9792
)
9893
group.insert(2, vertical_bar)
9994

95+
vertical_bar2 = VerticalProgressBar(
96+
(54, 4),
97+
(8, 24),
98+
min_value=-40,
99+
max_value=50,
100+
value=15,
101+
bar_color=0x1111FF,
102+
fill_color=None,
103+
margin_size=0,
104+
outline_color=0x2222AA,
105+
direction=VerticalFillDirection.TOP_TO_BOTTOM,
106+
)
107+
group.insert(3, vertical_bar2)
108+
100109
# Countdown to the start of the bars demo
101110
countdown_bar = HorizontalProgressBar(
102111
(2, 2),
@@ -112,7 +121,7 @@
112121

113122
countdown_end_color = 0xFF1111
114123

115-
group.insert(3, countdown_bar)
124+
group.insert(4, countdown_bar)
116125
# group.insert(0, countdown_bar)
117126

118127
print("Progress bars added. Starting demo...")
@@ -148,6 +157,20 @@
148157
ranged_bar.value = progress_bar_value
149158
progress_bar_value += progress_bar_incr
150159

160+
161+
if not (button1.value and button2.value):
162+
163+
if not button1.value: # "UP" button pushed
164+
print("UP button pressed. Increasing vertical bars by 3")
165+
vertical_bar.value = min(vertical_bar.maximum, vertical_bar.value + 3)
166+
vertical_bar2.value = min(vertical_bar2.maximum, vertical_bar2.value + 3)
167+
168+
if not button2.value: # "DOWN" button pushed
169+
print("DOWN button pressed. Decreasing vertical bars by 3")
170+
vertical_bar.value = max(vertical_bar.minimum, vertical_bar.value - 3)
171+
vertical_bar2.value = max(vertical_bar2.minimum , vertical_bar2.value - 3)
172+
173+
151174
if progress_bar_value > progress_bar.maximum:
152175
progress_bar_value = progress_bar.maximum
153176
progress_bar_incr *= -1
@@ -156,11 +179,4 @@
156179
progress_bar_value = progress_bar.minimum
157180
progress_bar_incr *= -1
158181

159-
# button_pressed = False
160-
# while False == button_pressed:
161-
# button_pressed = button_pressed or not (button1.value and button2.value)
162-
# time.sleep(0.1)
163-
164-
# print("Step")
165-
button_pressed = False
166182
time.sleep(0.5)

0 commit comments

Comments
 (0)