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
acb6085c
Commit
acb6085c
authored
5 years ago
by
fuchsi*
Committed by
rahix
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ecg-app: write setting to and load from file to persistent across launches
parent
5168edff
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
preload/apps/ecg/settings.py
+50
-6
50 additions, 6 deletions
preload/apps/ecg/settings.py
with
50 additions
and
6 deletions
preload/apps/ecg/settings.py
+
50
−
6
View file @
acb6085c
...
...
@@ -7,30 +7,72 @@ class Settings(simple_menu.Menu):
color_1
=
color
.
CAMPGREEN
color_2
=
color
.
CAMPGREEN_DARK
options
=
{}
selected_
options
=
{}
def
__init__
(
self
):
super
().
__init__
([(
"
return
"
,
False
)])
self
.
config_path
=
"
/
"
.
join
(
__file__
.
split
(
"
/
"
)[
0
:
-
1
])
def
on_select
(
self
,
value
,
index
):
if
index
==
0
:
self
.
exit
()
else
:
self
.
options
[
value
[
0
]]
=
next
(
value
[
1
])
self
.
selected_options
[
value
[
0
]]
=
next
(
value
[
1
])
self
.
write_to_file
()
def
entry2name
(
self
,
value
):
if
value
[
0
]
==
"
return
"
:
return
value
[
0
]
else
:
return
"
{}: {}
"
.
format
(
value
[
0
],
self
.
options
[
value
[
0
]][
0
])
return
"
{}: {}
"
.
format
(
value
[
0
],
self
.
selected_
options
[
value
[
0
]][
0
])
def
add_option
(
self
,
option
):
self
.
entries
.
append
(
option
)
self
.
options
[
option
[
0
]]
=
next
(
option
[
1
])
self
.
selected_
options
[
option
[
0
]]
=
next
(
option
[
1
])
def
get_option
(
self
,
name
):
return
self
.
options
[
name
][
1
]
return
self
.
selected_options
[
name
][
1
]
def
load_from_file
(
self
):
config_path
=
"
/
"
.
join
(
__file__
.
split
(
"
/
"
)[
0
:
-
1
])
try
:
f
=
open
(
"
{}/config.cfg
"
.
format
(
config_path
),
"
r
"
)
for
line
in
f
:
parts
=
[
x
.
strip
()
for
x
in
line
.
split
(
"
:
"
)]
if
parts
[
0
]
in
self
.
selected_options
:
# find corresponding entry from menu to get access to the corresponding itertools.cycle
option_cycle
=
next
(
x
for
x
in
self
.
entries
if
x
[
0
]
==
parts
[
0
])[
1
]
if
self
.
selected_options
[
parts
[
0
]][
0
]
!=
parts
[
1
]:
previous
=
self
.
selected_options
[
parts
[
0
]][
0
]
self
.
selected_options
[
parts
[
0
]]
=
next
(
option_cycle
)
while
self
.
selected_options
[
parts
[
0
]][
0
]
not
in
{
parts
[
1
],
previous
,
}:
self
.
selected_options
[
parts
[
0
]]
=
next
(
option_cycle
)
if
self
.
selected_options
[
parts
[
0
]][
0
]
==
previous
:
print
(
"
Settings: unknown option
'
{}
'
for key
'
{}
'"
.
format
(
parts
[
1
],
parts
[
0
]
)
)
else
:
print
(
"
Settings: unknown key
'
{}
'"
.
format
(
parts
[
0
]))
f
.
close
()
except
OSError
:
print
(
"
Settings could not be loaded from file. Maybe it did not exist yet?
"
)
def
write_to_file
(
self
):
config_path
=
"
/
"
.
join
(
__file__
.
split
(
"
/
"
)[
0
:
-
1
])
try
:
f
=
open
(
"
{}/config.cfg
"
.
format
(
config_path
),
"
w
"
)
for
option_name
in
self
.
selected_options
:
f
.
write
(
"
{}:{}
\n
"
.
format
(
option_name
,
self
.
selected_options
[
option_name
][
0
])
)
f
.
close
()
except
OSError
as
e
:
print
(
"
Settings could not be written to file! Error: {}
"
.
format
(
e
))
def
ecg_settings
():
...
...
@@ -66,4 +108,6 @@ def ecg_settings():
)
)
config
.
load_from_file
()
return
config
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