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
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
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
card10
firmware
Commits
3063400e
Commit
3063400e
authored
5 years ago
by
Daniel Hoffend
Browse files
Options
Downloads
Patches
Plain Diff
feat(main.py) support color themes via json config
parent
54e82152
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!199
Clock colors
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
preload/main.py
+30
-4
30 additions, 4 deletions
preload/main.py
with
30 additions
and
4 deletions
preload/main.py
+
30
−
4
View file @
3063400e
...
...
@@ -5,6 +5,10 @@ import utime
import
math
import
leds
import
buttons
import
ujson
import
os
CONFIG_NAME
=
"
clock.json
"
class
Time
:
def
__init__
(
self
,
start
=
0
):
...
...
@@ -65,14 +69,34 @@ class Clock:
},
]
self
.
themes
=
self
.
default_themes
# TODO load themes from clock.json
# TODO load current theme from clock.json
# check for config file
if
CONFIG_NAME
in
os
.
listdir
(
"
.
"
):
self
.
readConfig
()
else
:
self
.
writeConfig
()
# load colors
print
(
"
theme:
"
,
self
.
theme
)
print
(
"
themes:
"
,
self
.
themes
)
self
.
setTheme
(
self
.
theme
)
def
readConfig
(
self
):
with
open
(
CONFIG_NAME
,
'
r
'
)
as
f
:
try
:
c
=
ujson
.
loads
(
f
.
read
())
if
"
themes
"
in
c
and
len
(
c
[
"
themes
"
])
>
0
and
isinstance
(
c
[
"
themes
"
],
list
):
self
.
themes
=
c
[
"
themes
"
]
if
"
theme
"
and
isinstance
(
c
[
"
theme
"
],
int
):
self
.
theme
=
c
[
"
theme
"
]
except
ValueError
:
print
(
"
parsing %s failed
"
%
CONFIG_NAME
)
def
writeConfig
(
self
):
with
open
(
CONFIG_NAME
,
'
w
'
)
as
f
:
f
.
write
(
ujson
.
dumps
({
"
theme
"
:
self
.
theme
,
"
themes
"
:
self
.
themes
,
}))
def
setTheme
(
self
,
theme
):
self
.
theme
=
theme
%
len
(
self
.
themes
)
self
.
background_col
=
(
...
...
@@ -129,9 +153,11 @@ class Clock:
if
not
button_pressed
and
v
&
buttons
.
BOTTOM_LEFT
!=
0
:
button_pressed
=
True
self
.
setTheme
(
self
.
theme
-
1
)
self
.
writeConfig
()
elif
not
button_pressed
and
v
&
buttons
.
BOTTOM_RIGHT
!=
0
:
button_pressed
=
True
self
.
setTheme
(
self
.
theme
+
1
)
self
.
writeConfig
()
except
KeyboardInterrupt
:
for
i
in
range
(
11
):
...
...
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