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
External 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
fleur
firmware
Commits
ba4a314d
Verified
Commit
ba4a314d
authored
5 years ago
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
feat(simple_menu): Add inactivity timeout
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
3030f5f9
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
+27
-1
27 additions, 1 deletion
pycardium/modules/py/simple_menu.py
with
27 additions
and
1 deletion
pycardium/modules/py/simple_menu.py
+
27
−
1
View file @
ba4a314d
...
...
@@ -112,6 +112,14 @@ class Menu:
.. versionadded:: 1.9
"""
timeout
=
None
"""
Optional timeout for inactivity. Once this timeout is reached,
:py:meth:`~simple_menu.Menu.on_timeout` will be called.
.. versionadded:: 1.9
"""
def
on_scroll
(
self
,
item
,
index
):
"""
Hook when the selector scrolls to a new item.
...
...
@@ -137,6 +145,15 @@ class Menu:
"""
pass
def
on_timeout
(
self
):
"""
The inactivity timeout has been triggered. See
:py:attr:`simple_menu.Menu.timeout`.
.. versionadded:: 1.9
"""
self
.
exit
()
def
exit
(
self
):
"""
Exit the event-loop. This should be called from inside an ``on_*`` hook.
...
...
@@ -254,7 +271,11 @@ class Menu:
def
run
(
self
):
"""
Start the event-loop.
"""
try
:
for
ev
in
button_events
(
timeout
=
self
.
scroll_speed
):
timeout
=
self
.
scroll_speed
if
self
.
timeout
is
not
None
and
self
.
timeout
<
self
.
scroll_speed
:
timeout
=
self
.
timeout
for
ev
in
button_events
(
timeout
):
if
ev
==
buttons
.
BOTTOM_RIGHT
:
self
.
select_time
=
utime
.
time_ms
()
self
.
draw_menu
(
-
8
)
...
...
@@ -284,5 +305,10 @@ class Menu:
utime
.
sleep
(
1.0
)
self
.
draw_menu
()
if
self
.
timeout
is
not
None
and
(
utime
.
time_ms
()
-
self
.
select_time
)
>
int
(
self
.
timeout
*
1000
):
self
.
on_timeout
()
except
_ExitMenuException
:
pass
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