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
chris007
firmware
Commits
79445099
Verified
Commit
79445099
authored
5 years ago
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
reafactor(menu.py): Use simple_menu
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
6ad6f0ea
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
preload/menu.py
+22
-85
22 additions, 85 deletions
preload/menu.py
with
22 additions
and
85 deletions
preload/menu.py
+
22
−
85
View file @
79445099
...
@@ -5,10 +5,10 @@ You can customize this script however you want :) If you want to go back to
...
@@ -5,10 +5,10 @@ You can customize this script however you want :) If you want to go back to
the default version, just delete this file; the firmware will recreate it on
the default version, just delete this file; the firmware will recreate it on
next run.
next run.
"""
"""
import
buttons
import
color
import
color
import
display
import
display
import
os
import
os
import
simple_menu
def
list_apps
():
def
list_apps
():
...
@@ -24,96 +24,33 @@ def list_apps():
...
@@ -24,96 +24,33 @@ def list_apps():
return
apps
return
apps
def
button_events
():
class
MainMenu
(
simple_menu
.
Menu
):
"""
Iterate over button presses (event-loop).
"""
def
on_select
(
self
,
name
,
index
):
yield
0
display
.
open
().
clear
().
update
()
button_pressed
=
False
display
.
close
()
while
True
:
try
:
v
=
buttons
.
read
(
buttons
.
BOTTOM_LEFT
|
buttons
.
BOTTOM_RIGHT
|
buttons
.
TOP_RIGHT
)
os
.
exec
(
name
)
except
OSError
as
e
:
if
v
==
0
:
print
(
"
Loading failed:
"
,
e
)
button_pressed
=
False
os
.
exit
(
1
)
if
not
button_pressed
and
v
&
buttons
.
BOTTOM_LEFT
!=
0
:
button_pressed
=
True
yield
buttons
.
BOTTOM_LEFT
if
not
button_pressed
and
v
&
buttons
.
BOTTOM_RIGHT
!=
0
:
button_pressed
=
True
yield
buttons
.
BOTTOM_RIGHT
if
not
button_pressed
and
v
&
buttons
.
TOP_RIGHT
!=
0
:
button_pressed
=
True
yield
buttons
.
TOP_RIGHT
COLOR1
,
COLOR2
=
(
color
.
CHAOSBLUE_DARK
,
color
.
CHAOSBLUE
)
def
draw_menu
(
disp
,
applist
,
idx
,
offset
):
disp
.
clear
()
# Wrap around the app-list and draw entries from idx - 3 to idx + 4
for
y
,
i
in
enumerate
(
range
(
len
(
applist
)
+
idx
-
3
,
len
(
applist
)
+
idx
+
4
)):
disp
.
print
(
"
"
+
applist
[
i
%
len
(
applist
)]
+
"
"
,
posy
=
offset
+
y
*
20
-
40
,
bg
=
COLOR1
if
i
%
2
==
0
else
COLOR2
,
)
disp
.
print
(
"
>
"
,
posy
=
20
,
fg
=
color
.
COMMYELLOW
,
bg
=
COLOR1
if
(
idx
+
len
(
applist
))
%
2
==
0
else
COLOR2
,
)
disp
.
update
()
def
main
():
def
main
():
disp
=
display
.
open
()
applist
=
list_apps
()
applist
=
list_apps
()
numapps
=
len
(
applist
)
current
=
0
if
applist
==
[]:
for
ev
in
button_events
():
disp
=
display
.
open
()
if
numapps
==
0
:
disp
.
clear
(
color
.
COMMYELLOW
)
disp
.
clear
(
color
.
COMMYELLOW
)
disp
.
print
(
disp
.
print
(
"
No apps
"
,
"
No apps
"
,
posx
=
17
,
posy
=
20
,
fg
=
color
.
COMMYELLOW_DARK
,
bg
=
color
.
COMMYELLOW
posx
=
17
,
posy
=
20
,
fg
=
color
.
COMMYELLOW_DARK
,
bg
=
color
.
COMMYELLOW
,
)
)
disp
.
print
(
disp
.
print
(
"
available
"
,
"
available
"
,
posx
=
17
,
posy
=
40
,
fg
=
color
.
COMMYELLOW_DARK
,
bg
=
color
.
COMMYELLOW
posx
=
17
,
posy
=
40
,
fg
=
color
.
COMMYELLOW_DARK
,
bg
=
color
.
COMMYELLOW
,
)
)
disp
.
update
()
disp
.
update
()
continue
return
if
ev
==
buttons
.
BOTTOM_RIGHT
:
# Scroll down
draw_menu
(
disp
,
applist
,
current
,
-
8
)
current
=
(
current
+
1
)
%
numapps
elif
ev
==
buttons
.
BOTTOM_LEFT
:
# Scroll up
draw_menu
(
disp
,
applist
,
current
,
8
)
current
=
(
current
+
numapps
-
1
)
%
numapps
elif
ev
==
buttons
.
TOP_RIGHT
:
# Select & start
disp
.
clear
().
update
()
disp
.
close
()
try
:
os
.
exec
(
applist
[
current
])
except
OSError
as
e
:
print
(
"
Loading failed:
"
,
e
)
os
.
exit
(
1
)
draw_menu
(
disp
,
applist
,
current
,
0
)
MainMenu
(
applist
).
run
(
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
...
...
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