Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
François Revol
firmware
Commits
1887124d
Commit
1887124d
authored
Apr 03, 2020
by
schneider
Browse files
feat(simple_menu): Add a method to detect a long (>1 second) press
parent
d5b7b3f7
Changes
1
Hide whitespace changes
Inline
Side-by-side
pycardium/modules/py/simple_menu.py
View file @
1887124d
...
...
@@ -141,6 +141,18 @@ class Menu:
"""
pass
def
on_long_select
(
self
,
item
,
index
):
"""
Hook when an item as selected using a long press.
The given ``index`` was selected with a long SELECT button press. Overwrite
this function in your menu to perform an action on select.
:param item: The item which was selected.
:param int index: Index into the ``entries`` list of the ``item``.
"""
pass
def
on_select
(
self
,
item
,
index
):
"""
Hook when an item as selected.
...
...
@@ -238,9 +250,7 @@ class Menu:
offset
+
20
,
col
=
self
.
color_1
if
index
%
2
==
0
else
self
.
color_2
,
)
self
.
disp
.
print
(
string
,
posx
=
14
,
posy
=
offset
,
fg
=
self
.
color_text
,
bg
=
None
,
)
self
.
disp
.
print
(
string
,
posx
=
14
,
posy
=
offset
,
fg
=
self
.
color_text
,
bg
=
None
)
def
draw_menu
(
self
,
offset
=
0
):
"""
...
...
@@ -318,8 +328,18 @@ class Menu:
print
(
"Exception during menu.on_scroll():"
)
sys
.
print_exception
(
e
)
elif
ev
==
self
.
button_select
:
t0
=
utime
.
time
()
long_press
=
False
while
buttons
.
read
(
buttons
.
TOP_RIGHT
)
>
0
:
if
utime
.
time
()
-
t0
>
1
:
long_press
=
True
break
try
:
self
.
on_select
(
self
.
entries
[
self
.
idx
],
self
.
idx
)
if
long_press
:
self
.
on_long_select
(
self
.
entries
[
self
.
idx
],
self
.
idx
)
else
:
self
.
on_select
(
self
.
entries
[
self
.
idx
],
self
.
idx
)
self
.
select_time
=
utime
.
time_ms
()
except
_ExitMenuException
:
raise
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment