Skip to content

Commit 2526085

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

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

examples/progressbar_matrixportal.py

+29-10
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585

8686
# Sample thermometer from -40C to 50C, with a value of +15C
8787
vertical_bar = VerticalProgressBar(
88-
(50, 4),
89-
(10, 24),
88+
(44, 4),
89+
(8, 24),
9090
min_value=-40,
9191
max_value=50,
9292
value=15,
@@ -97,6 +97,20 @@
9797
)
9898
group.insert(2, vertical_bar)
9999

100+
vertical_bar2 = VerticalProgressBar(
101+
(54, 4),
102+
(8, 24),
103+
min_value=-40,
104+
max_value=50,
105+
value=15,
106+
bar_color=0x1111FF,
107+
fill_color=None,
108+
margin_size=0,
109+
outline_color=0x2222AA,
110+
direction=VerticalFillDirection.TOP_TO_BOTTOM,
111+
)
112+
group.insert(3, vertical_bar2)
113+
100114
# Countdown to the start of the bars demo
101115
countdown_bar = HorizontalProgressBar(
102116
(2, 2),
@@ -112,7 +126,7 @@
112126

113127
countdown_end_color = 0xFF1111
114128

115-
group.insert(3, countdown_bar)
129+
group.insert(4, countdown_bar)
116130
# group.insert(0, countdown_bar)
117131

118132
print("Progress bars added. Starting demo...")
@@ -148,6 +162,18 @@
148162
ranged_bar.value = progress_bar_value
149163
progress_bar_value += progress_bar_incr
150164

165+
if not (button1.value and button2.value):
166+
167+
if not button1.value: # "UP" button pushed
168+
print("UP button pressed. Increasing vertical bars by 3")
169+
vertical_bar.value = min(vertical_bar.maximum, vertical_bar.value + 3)
170+
vertical_bar2.value = min(vertical_bar2.maximum, vertical_bar2.value + 3)
171+
172+
if not button2.value: # "DOWN" button pushed
173+
print("DOWN button pressed. Decreasing vertical bars by 3")
174+
vertical_bar.value = max(vertical_bar.minimum, vertical_bar.value - 3)
175+
vertical_bar2.value = max(vertical_bar2.minimum, vertical_bar2.value - 3)
176+
151177
if progress_bar_value > progress_bar.maximum:
152178
progress_bar_value = progress_bar.maximum
153179
progress_bar_incr *= -1
@@ -156,11 +182,4 @@
156182
progress_bar_value = progress_bar.minimum
157183
progress_bar_incr *= -1
158184

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
166185
time.sleep(0.5)

0 commit comments

Comments
 (0)