Fix accidentally overwriting custom colour on exit.

This commit is contained in:
Anna_updn 2023-08-18 16:24:40 +02:00
parent c26f9dbc35
commit eef900f832
2 changed files with 12 additions and 18 deletions

View File

@ -17,7 +17,7 @@ class Configuration:
self.strs: list = ['flow3r', '', 'noLang', '', '']
self.size: int = 75
self.font: int = 5
self.colour: int = 0 # (0.5, 0.5, 0.5) # index or tuple
self.colour: int = (1.0, 1.0, 1.0)
self.delay: int = 8
@classmethod
@ -43,22 +43,20 @@ class Configuration:
res.size = data["size"]
if "font" in data and type(data["font"]) == int:
res.font = data["font"]
if "color" in data:
if type(data["color"]) == int:
res.colour = data["color"]
if type(data["color"]) == str and len(data["color"]) == 7 and data["color"][0] == '#':
res.colour = (
int(data["color"][1:3], 16)/256.0,
int(data["color"][3:5], 16)/256.0,
int(data["color"][5:], 16)/256.0
)
if "color" in data and type(data["color"]) == str and len(data["color"]) == 7 and data["color"][0] == '#':
res.colour = (
int(data["color"][1:3], 16)/256.0,
int(data["color"][3:5], 16)/256.0,
int(data["color"][5:], 16)/256.0
)
return res
def save(self, path: str) -> None:
colourstr: str = '#' + hex(int(255*self.colour[0]))[2:4] + hex(int(255*self.colour[1]))[2:4] + hex(int(255*self.colour[2]))[2:4]
d = {
"size": self.size,
"font": self.font,
"color": self.colour if type(self.colour) == int else 0,
"color": colourstr,
"delay": self.delay,
}
for i in range(len(self.hdrs)):
@ -85,12 +83,8 @@ class SensibleNickApp(Application):
self._en_iter_pressed = False
self._filename = "/flash/nick.json"
self._config = Configuration.load(self._filename)
self._colours: list = [GO_GREEN, PUSH_RED, WHITE]
if type(self._config.colour) == int:
self._en_colour = self._config.colour
else:
self._colours[2] = self._config.colour
self._en_colour = 2
self._colours: list = [GO_GREEN, PUSH_RED, self._config.colour]
self._en_colour = 2
self.varprint: list(str) = [str for str in self._config.strs if len(str) > 0]
def draw(self, ctx: Context) -> None:

View File

@ -10,4 +10,4 @@ author = "Anna_updn, Flow3r Badge Authors"
license = "LGPL-3.0-only"
url = "https://git.flow3r.garden/updn/sensiblenickapp"
description = "A sensible nickname app using touch to show up to 5 strings with some quality of life features."
version = 1
version = 2