Skip to content

Commit 876e5e1

Browse files
committed
Use launcher.conf.json for user color palette configuration
1 parent 2de4173 commit 876e5e1

File tree

2 files changed

+19
-30
lines changed

2 files changed

+19
-30
lines changed

src/code.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import json
1010
import math
1111
import displayio
12-
import os
1312
import supervisor
1413
import sys
1514
import terminalio
@@ -53,21 +52,20 @@
5352
print(f"launching: {next_code_file}")
5453
supervisor.reload()
5554

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", -1),
62-
}
63-
6455
request_display_config(720, 400)
6556
display = supervisor.runtime.display
6657

6758
scale = 1
6859
if display.width > 360:
6960
scale = 2
7061

62+
launcher_config = {}
63+
if pathlib.Path("launcher.conf.json").exists():
64+
with open("launcher.conf.json", "r") as f:
65+
launcher_config = json.load(f)
66+
if "palette" not in launcher_config:
67+
launcher_config["palette"] = {}
68+
7169
font_file = "/fonts/terminal.lvfontbin"
7270
font = bitmap_font.load_font(font_file)
7371
scaled_group = displayio.Group(scale=scale)
@@ -79,7 +77,7 @@
7977

8078
background_bmp = displayio.Bitmap(display.width, display.height, 1)
8179
bg_palette = displayio.Palette(1)
82-
bg_palette[0] = color_palette["bg"]
80+
bg_palette[0] = int(launcher_config["palette"].get("bg", "0x222222"), 16)
8381
bg_tg = displayio.TileGrid(bitmap=background_bmp, pixel_shader=bg_palette)
8482
scaled_group.append(bg_tg)
8583

@@ -97,11 +95,6 @@
9795
mouse_tg.y = display.height // (2 * scale)
9896
# 046d:c52f
9997

100-
launcher_config = {}
101-
if pathlib.Path("launcher.conf.json").exists():
102-
with open("launcher.conf.json", "r") as f:
103-
launcher_config = json.load(f)
104-
10598
# mouse = usb.core.find(idVendor=0x046d, idProduct=0xc52f)
10699

107100
DIR_IN = 0x80
@@ -193,7 +186,7 @@
193186
divider_lines=False)
194187
scaled_group.append(menu_grid)
195188

196-
menu_title_txt = Label(font, text="Fruit Jam OS", color=color_palette["fg"])
189+
menu_title_txt = Label(font, text="Fruit Jam OS", color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
197190
menu_title_txt.anchor_point = (0.5, 0.5)
198191
menu_title_txt.anchored_position = (display.width // (2 * scale), 2)
199192
scaled_group.append(menu_title_txt)
@@ -277,7 +270,7 @@ def _create_cell_group(app):
277270

278271
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
279272
title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
280-
align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
273+
align=TextBox.ALIGN_CENTER, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
281274
cell_group.append(title_txt)
282275
title_txt.anchor_point = (0, 0)
283276
title_txt.anchored_position = (0, icon_tg.y + icon_tg.tile_height)
@@ -298,7 +291,7 @@ def _reuse_cell_group(app, cell_group):
298291

299292
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
300293
# title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
301-
# align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
294+
# align=TextBox.ALIGN_CENTER, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
302295
# cell_group.append(title_txt)
303296
title_txt = cell_group[1]
304297
title_txt.text = app["title"]
@@ -347,7 +340,7 @@ def display_page(page_index):
347340
print(f"{grid_index} | {grid_index % config["width"], grid_index // config["width"]}")
348341

349342

350-
page_txt = Label(terminalio.FONT, text="", scale=2, color=color_palette["fg"])
343+
page_txt = Label(terminalio.FONT, text="", scale=2, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
351344
page_txt.anchor_point = (1.0, 1.0)
352345
page_txt.anchored_position = (display.width - 2, display.height - 2)
353346
main_group.append(page_txt)
@@ -359,8 +352,8 @@ def display_page(page_index):
359352
left_palette.make_transparent(0)
360353
right_bmp, right_palette = adafruit_imageload.load("launcher_assets/arrow_right.bmp")
361354
right_palette.make_transparent(0)
362-
if color_palette["arrow"] >= 0:
363-
left_palette[2] = right_palette[2] = color_palette["arrow"]
355+
if "arrow" in launcher_config["palette"]:
356+
left_palette[2] = right_palette[2] = int(launcher_config["palette"].get("arrow"), 16)
364357

365358
left_tg = AnchoredTileGrid(bitmap=left_bmp, pixel_shader=left_palette)
366359
left_tg.anchor_point = (0, 0.5)
@@ -383,8 +376,8 @@ def display_page(page_index):
383376

384377

385378
help_txt = Label(terminalio.FONT, text="[Arrow]: Move\n[E]: Edit\n[Enter]: Run\n[1-9]: Page",
386-
color=color_palette["fg"])
387-
# help_txt = TextBox(terminalio.FONT, width=88, height=30, align=TextBox.ALIGN_RIGHT, background_color=color_palette["accent"], text="[E]: Edit\n[Enter]: Run")
379+
color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
380+
# 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")
388381
help_txt.anchor_point = (0, 0)
389382

390383
help_txt.anchored_position = (2, 2)
@@ -421,10 +414,10 @@ def change_selected(new_selected):
421414

422415
# tuple means an item in the grid is selected
423416
if isinstance(new_selected, tuple):
424-
menu_grid.get_content(new_selected)[1].background_color = color_palette["accent"]
417+
menu_grid.get_content(new_selected)[1].background_color = int(launcher_config["palette"].get("accent", "0x008800"), 16)
425418
# TileGrid means arrow is selected
426419
elif isinstance(new_selected, AnchoredTileGrid):
427-
new_selected.pixel_shader[2] = color_palette["accent"]
420+
new_selected.pixel_shader[2] = int(launcher_config["palette"].get("accent", "0x008800"), 16)
428421
selected = new_selected
429422

430423

@@ -540,7 +533,7 @@ def handle_key_press(key):
540533

541534
handle_key_press(c)
542535
print("selected", selected)
543-
# app_titles[selected].background_color = color_palette["accent"]
536+
# app_titles[selected].background_color = int(launcher_config["palette"].get("accent", "0x008800"), 16)
544537

545538
if mouse:
546539
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)