Skip to content

Commit aa5ed36

Browse files
authored
Merge pull request #47 from relic-se/color-palette-json
Use `launcher.conf.json` for user color palette configuration
2 parents a69d6c8 + e53cd2e commit aa5ed36

File tree

2 files changed

+19
-29
lines changed

2 files changed

+19
-29
lines changed

src/code.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@
5353
print(f"launching: {next_code_file}")
5454
supervisor.reload()
5555

56-
# read environment variables
57-
color_palette = {
58-
"bg": os.getenv("FRUIT_JAM_OS_BG", 0x222222),
59-
"fg": os.getenv("FRUIT_JAM_OS_FG", 0xffffff),
60-
"accent": os.getenv("FRUIT_JAM_OS_ACCENT", 0x008800),
61-
"arrow": os.getenv("FRUIT_JAM_OS_ARROW"),
62-
}
63-
6456
if (width_config := os.getenv("CIRCUITPY_DISPLAY_WIDTH")) is not None:
6557
if width_config not in [x[0] for x in VALID_DISPLAY_SIZES]:
6658
raise ValueError(f"Invalid display size. Must be one of: {VALID_DISPLAY_SIZES}")
@@ -76,6 +68,13 @@
7668
if display.width > 360:
7769
scale = 2
7870

71+
launcher_config = {}
72+
if pathlib.Path("launcher.conf.json").exists():
73+
with open("launcher.conf.json", "r") as f:
74+
launcher_config = json.load(f)
75+
if "palette" not in launcher_config:
76+
launcher_config["palette"] = {}
77+
7978
font_file = "/fonts/terminal.lvfontbin"
8079
font = bitmap_font.load_font(font_file)
8180
scaled_group = displayio.Group(scale=scale)
@@ -87,7 +86,7 @@
8786

8887
background_bmp = displayio.Bitmap(display.width, display.height, 1)
8988
bg_palette = displayio.Palette(1)
90-
bg_palette[0] = color_palette["bg"]
89+
bg_palette[0] = int(launcher_config["palette"].get("bg", "0x222222"), 16)
9190
bg_tg = displayio.TileGrid(bitmap=background_bmp, pixel_shader=bg_palette)
9291
scaled_group.append(bg_tg)
9392

@@ -105,11 +104,6 @@
105104
mouse_tg.y = display.height // (2 * scale)
106105
# 046d:c52f
107106

108-
launcher_config = {}
109-
if pathlib.Path("launcher.conf.json").exists():
110-
with open("launcher.conf.json", "r") as f:
111-
launcher_config = json.load(f)
112-
113107
# mouse = usb.core.find(idVendor=0x046d, idProduct=0xc52f)
114108

115109
DIR_IN = 0x80
@@ -204,7 +198,7 @@
204198
divider_lines=False)
205199
scaled_group.append(menu_grid)
206200

207-
menu_title_txt = Label(font, text="Fruit Jam OS", color=color_palette["fg"])
201+
menu_title_txt = Label(font, text="Fruit Jam OS", color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
208202
menu_title_txt.anchor_point = (0.5, 0.5)
209203
menu_title_txt.anchored_position = (display.width // (2 * scale), 2)
210204
scaled_group.append(menu_title_txt)
@@ -288,7 +282,7 @@ def _create_cell_group(app):
288282

289283
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
290284
title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
291-
align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
285+
align=TextBox.ALIGN_CENTER, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
292286
icon_tg.y = (cell_height - icon_tg.tile_height - title_txt.height) // 2
293287
cell_group.append(title_txt)
294288
title_txt.anchor_point = (0, 0)
@@ -310,7 +304,7 @@ def _reuse_cell_group(app, cell_group):
310304

311305
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
312306
# title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
313-
# align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
307+
# align=TextBox.ALIGN_CENTER, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
314308
# cell_group.append(title_txt)
315309
title_txt = cell_group[1]
316310
title_txt.text = app["title"]
@@ -359,7 +353,7 @@ def display_page(page_index):
359353
print(f"{grid_index} | {grid_index % config["width"], grid_index // config["width"]}")
360354

361355

362-
page_txt = Label(terminalio.FONT, text="", scale=scale, color=color_palette["fg"])
356+
page_txt = Label(terminalio.FONT, text="", scale=scale, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
363357
page_txt.anchor_point = (1.0, 1.0)
364358
page_txt.anchored_position = (display.width - 2, display.height - 2)
365359
main_group.append(page_txt)
@@ -371,8 +365,8 @@ def display_page(page_index):
371365
left_palette.make_transparent(0)
372366
right_bmp, right_palette = adafruit_imageload.load("launcher_assets/arrow_right.bmp")
373367
right_palette.make_transparent(0)
374-
if color_palette["arrow"] is not None:
375-
left_palette[2] = right_palette[2] = color_palette["arrow"]
368+
if "arrow" in launcher_config["palette"]:
369+
left_palette[2] = right_palette[2] = int(launcher_config["palette"].get("arrow"), 16)
376370

377371
left_tg = AnchoredTileGrid(bitmap=left_bmp, pixel_shader=left_palette)
378372
left_tg.anchor_point = (0, 0.5)
@@ -395,8 +389,8 @@ def display_page(page_index):
395389

396390

397391
help_txt = Label(terminalio.FONT, text="[Arrow]: Move\n[E]: Edit\n[Enter]: Run\n[1-9]: Page",
398-
color=color_palette["fg"])
399-
# help_txt = TextBox(terminalio.FONT, width=88, height=30, align=TextBox.ALIGN_RIGHT, background_color=color_palette["accent"], text="[E]: Edit\n[Enter]: Run")
392+
color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
393+
# help_txt = TextBox(terminalio.FONT, width=88, height=30, align=TextBox.ALIGN_RIGHT, background_color=int(launcher_config["palette"].get("accent", "0x008800"), 16), text="[E]: Edit\n[Enter]: Run")
400394
help_txt.anchor_point = (0, 0)
401395

402396
help_txt.anchored_position = (2, 2)
@@ -433,10 +427,10 @@ def change_selected(new_selected):
433427

434428
# tuple means an item in the grid is selected
435429
if isinstance(new_selected, tuple):
436-
menu_grid.get_content(new_selected)[1].background_color = color_palette["accent"]
430+
menu_grid.get_content(new_selected)[1].background_color = int(launcher_config["palette"].get("accent", "0x008800"), 16)
437431
# TileGrid means arrow is selected
438432
elif isinstance(new_selected, AnchoredTileGrid):
439-
new_selected.pixel_shader[2] = color_palette["accent"]
433+
new_selected.pixel_shader[2] = int(launcher_config["palette"].get("accent", "0x008800"), 16)
440434
selected = new_selected
441435

442436

@@ -552,7 +546,7 @@ def handle_key_press(key):
552546

553547
handle_key_press(c)
554548
print("selected", selected)
555-
# app_titles[selected].background_color = color_palette["accent"]
549+
# app_titles[selected].background_color = int(launcher_config["palette"].get("accent", "0x008800"), 16)
556550

557551
if mouse:
558552
try:

src/settings.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
CIRCUITPY_PYSTACK_SIZE=4000
2-
# FRUIT_JAM_OS_BG=0x222222
3-
# FRUIT_JAM_OS_FG=0xffffff
4-
# FRUIT_JAM_OS_ACCENT=0x008800
5-
# FRUIT_JAM_OS_ARROW=0x004abe

0 commit comments

Comments
 (0)