Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
PetePriority
firmware
Commits
ba4a314d
Verified
Commit
ba4a314d
authored
Aug 27, 2019
by
Rahix
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(simple_menu): Add inactivity timeout
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
3030f5f9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
1 deletion
+27
-1
pycardium/modules/py/simple_menu.py
pycardium/modules/py/simple_menu.py
+27
-1
No files found.
pycardium/modules/py/simple_menu.py
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
Write
Preview
Markdown
is supported
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