Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
zenox
firmware
Commits
1887124d
Commit
1887124d
authored
4 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
feat(simple_menu): Add a method to detect a long (>1 second) press
parent
d5b7b3f7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pycardium/modules/py/simple_menu.py
+24
-4
24 additions, 4 deletions
pycardium/modules/py/simple_menu.py
with
24 additions
and
4 deletions
pycardium/modules/py/simple_menu.py
+
24
−
4
View file @
1887124d
...
@@ -141,6 +141,18 @@ class Menu:
...
@@ -141,6 +141,18 @@ class Menu:
"""
"""
pass
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
):
def
on_select
(
self
,
item
,
index
):
"""
"""
Hook when an item as selected.
Hook when an item as selected.
...
@@ -238,9 +250,7 @@ class Menu:
...
@@ -238,9 +250,7 @@ class Menu:
offset
+
20
,
offset
+
20
,
col
=
self
.
color_1
if
index
%
2
==
0
else
self
.
color_2
,
col
=
self
.
color_1
if
index
%
2
==
0
else
self
.
color_2
,
)
)
self
.
disp
.
print
(
self
.
disp
.
print
(
string
,
posx
=
14
,
posy
=
offset
,
fg
=
self
.
color_text
,
bg
=
None
)
string
,
posx
=
14
,
posy
=
offset
,
fg
=
self
.
color_text
,
bg
=
None
,
)
def
draw_menu
(
self
,
offset
=
0
):
def
draw_menu
(
self
,
offset
=
0
):
"""
"""
...
@@ -318,8 +328,18 @@ class Menu:
...
@@ -318,8 +328,18 @@ class Menu:
print
(
"
Exception during menu.on_scroll():
"
)
print
(
"
Exception during menu.on_scroll():
"
)
sys
.
print_exception
(
e
)
sys
.
print_exception
(
e
)
elif
ev
==
self
.
button_select
:
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
:
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
()
self
.
select_time
=
utime
.
time_ms
()
except
_ExitMenuException
:
except
_ExitMenuException
:
raise
raise
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment