Merge pull request #47 from relic-se/color-palette-json
Use `launcher.conf.json` for user color palette configuration
This commit is contained in:
commit
aa5ed36c5f
2 changed files with 19 additions and 29 deletions
44
src/code.py
44
src/code.py
|
|
@ -53,14 +53,6 @@ if args is not None and len(args) > 0:
|
||||||
print(f"launching: {next_code_file}")
|
print(f"launching: {next_code_file}")
|
||||||
supervisor.reload()
|
supervisor.reload()
|
||||||
|
|
||||||
# read environment variables
|
|
||||||
color_palette = {
|
|
||||||
"bg": os.getenv("FRUIT_JAM_OS_BG", 0x222222),
|
|
||||||
"fg": os.getenv("FRUIT_JAM_OS_FG", 0xffffff),
|
|
||||||
"accent": os.getenv("FRUIT_JAM_OS_ACCENT", 0x008800),
|
|
||||||
"arrow": os.getenv("FRUIT_JAM_OS_ARROW"),
|
|
||||||
}
|
|
||||||
|
|
||||||
if (width_config := os.getenv("CIRCUITPY_DISPLAY_WIDTH")) is not None:
|
if (width_config := os.getenv("CIRCUITPY_DISPLAY_WIDTH")) is not None:
|
||||||
if width_config not in [x[0] for x in VALID_DISPLAY_SIZES]:
|
if width_config not in [x[0] for x in VALID_DISPLAY_SIZES]:
|
||||||
raise ValueError(f"Invalid display size. Must be one of: {VALID_DISPLAY_SIZES}")
|
raise ValueError(f"Invalid display size. Must be one of: {VALID_DISPLAY_SIZES}")
|
||||||
|
|
@ -76,6 +68,13 @@ scale = 1
|
||||||
if display.width > 360:
|
if display.width > 360:
|
||||||
scale = 2
|
scale = 2
|
||||||
|
|
||||||
|
launcher_config = {}
|
||||||
|
if pathlib.Path("launcher.conf.json").exists():
|
||||||
|
with open("launcher.conf.json", "r") as f:
|
||||||
|
launcher_config = json.load(f)
|
||||||
|
if "palette" not in launcher_config:
|
||||||
|
launcher_config["palette"] = {}
|
||||||
|
|
||||||
font_file = "/fonts/terminal.lvfontbin"
|
font_file = "/fonts/terminal.lvfontbin"
|
||||||
font = bitmap_font.load_font(font_file)
|
font = bitmap_font.load_font(font_file)
|
||||||
scaled_group = displayio.Group(scale=scale)
|
scaled_group = displayio.Group(scale=scale)
|
||||||
|
|
@ -87,7 +86,7 @@ display.root_group = main_group
|
||||||
|
|
||||||
background_bmp = displayio.Bitmap(display.width, display.height, 1)
|
background_bmp = displayio.Bitmap(display.width, display.height, 1)
|
||||||
bg_palette = displayio.Palette(1)
|
bg_palette = displayio.Palette(1)
|
||||||
bg_palette[0] = color_palette["bg"]
|
bg_palette[0] = int(launcher_config["palette"].get("bg", "0x222222"), 16)
|
||||||
bg_tg = displayio.TileGrid(bitmap=background_bmp, pixel_shader=bg_palette)
|
bg_tg = displayio.TileGrid(bitmap=background_bmp, pixel_shader=bg_palette)
|
||||||
scaled_group.append(bg_tg)
|
scaled_group.append(bg_tg)
|
||||||
|
|
||||||
|
|
@ -105,11 +104,6 @@ mouse_tg.x = display.width // (2 * scale)
|
||||||
mouse_tg.y = display.height // (2 * scale)
|
mouse_tg.y = display.height // (2 * scale)
|
||||||
# 046d:c52f
|
# 046d:c52f
|
||||||
|
|
||||||
launcher_config = {}
|
|
||||||
if pathlib.Path("launcher.conf.json").exists():
|
|
||||||
with open("launcher.conf.json", "r") as f:
|
|
||||||
launcher_config = json.load(f)
|
|
||||||
|
|
||||||
# mouse = usb.core.find(idVendor=0x046d, idProduct=0xc52f)
|
# mouse = usb.core.find(idVendor=0x046d, idProduct=0xc52f)
|
||||||
|
|
||||||
DIR_IN = 0x80
|
DIR_IN = 0x80
|
||||||
|
|
@ -204,7 +198,7 @@ menu_grid = GridLayout(x=(display.width // scale - WIDTH) // 2,
|
||||||
divider_lines=False)
|
divider_lines=False)
|
||||||
scaled_group.append(menu_grid)
|
scaled_group.append(menu_grid)
|
||||||
|
|
||||||
menu_title_txt = Label(font, text="Fruit Jam OS", color=color_palette["fg"])
|
menu_title_txt = Label(font, text="Fruit Jam OS", color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
|
||||||
menu_title_txt.anchor_point = (0.5, 0.5)
|
menu_title_txt.anchor_point = (0.5, 0.5)
|
||||||
menu_title_txt.anchored_position = (display.width // (2 * scale), 2)
|
menu_title_txt.anchored_position = (display.width // (2 * scale), 2)
|
||||||
scaled_group.append(menu_title_txt)
|
scaled_group.append(menu_title_txt)
|
||||||
|
|
@ -288,7 +282,7 @@ def _create_cell_group(app):
|
||||||
|
|
||||||
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
|
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
|
||||||
title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
|
title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
|
||||||
align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
|
align=TextBox.ALIGN_CENTER, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
|
||||||
icon_tg.y = (cell_height - icon_tg.tile_height - title_txt.height) // 2
|
icon_tg.y = (cell_height - icon_tg.tile_height - title_txt.height) // 2
|
||||||
cell_group.append(title_txt)
|
cell_group.append(title_txt)
|
||||||
title_txt.anchor_point = (0, 0)
|
title_txt.anchor_point = (0, 0)
|
||||||
|
|
@ -310,7 +304,7 @@ def _reuse_cell_group(app, cell_group):
|
||||||
|
|
||||||
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
|
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
|
||||||
# title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
|
# title_txt = TextBox(font, text=app["title"], width=cell_width, height=18,
|
||||||
# align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
|
# align=TextBox.ALIGN_CENTER, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
|
||||||
# cell_group.append(title_txt)
|
# cell_group.append(title_txt)
|
||||||
title_txt = cell_group[1]
|
title_txt = cell_group[1]
|
||||||
title_txt.text = app["title"]
|
title_txt.text = app["title"]
|
||||||
|
|
@ -359,7 +353,7 @@ def display_page(page_index):
|
||||||
print(f"{grid_index} | {grid_index % config["width"], grid_index // config["width"]}")
|
print(f"{grid_index} | {grid_index % config["width"], grid_index // config["width"]}")
|
||||||
|
|
||||||
|
|
||||||
page_txt = Label(terminalio.FONT, text="", scale=scale, color=color_palette["fg"])
|
page_txt = Label(terminalio.FONT, text="", scale=scale, color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
|
||||||
page_txt.anchor_point = (1.0, 1.0)
|
page_txt.anchor_point = (1.0, 1.0)
|
||||||
page_txt.anchored_position = (display.width - 2, display.height - 2)
|
page_txt.anchored_position = (display.width - 2, display.height - 2)
|
||||||
main_group.append(page_txt)
|
main_group.append(page_txt)
|
||||||
|
|
@ -371,8 +365,8 @@ left_bmp, left_palette = adafruit_imageload.load("launcher_assets/arrow_left.bmp
|
||||||
left_palette.make_transparent(0)
|
left_palette.make_transparent(0)
|
||||||
right_bmp, right_palette = adafruit_imageload.load("launcher_assets/arrow_right.bmp")
|
right_bmp, right_palette = adafruit_imageload.load("launcher_assets/arrow_right.bmp")
|
||||||
right_palette.make_transparent(0)
|
right_palette.make_transparent(0)
|
||||||
if color_palette["arrow"] is not None:
|
if "arrow" in launcher_config["palette"]:
|
||||||
left_palette[2] = right_palette[2] = color_palette["arrow"]
|
left_palette[2] = right_palette[2] = int(launcher_config["palette"].get("arrow"), 16)
|
||||||
|
|
||||||
left_tg = AnchoredTileGrid(bitmap=left_bmp, pixel_shader=left_palette)
|
left_tg = AnchoredTileGrid(bitmap=left_bmp, pixel_shader=left_palette)
|
||||||
left_tg.anchor_point = (0, 0.5)
|
left_tg.anchor_point = (0, 0.5)
|
||||||
|
|
@ -395,8 +389,8 @@ if mouse:
|
||||||
|
|
||||||
|
|
||||||
help_txt = Label(terminalio.FONT, text="[Arrow]: Move\n[E]: Edit\n[Enter]: Run\n[1-9]: Page",
|
help_txt = Label(terminalio.FONT, text="[Arrow]: Move\n[E]: Edit\n[Enter]: Run\n[1-9]: Page",
|
||||||
color=color_palette["fg"])
|
color=int(launcher_config["palette"].get("fg", "0xffffff"), 16))
|
||||||
# help_txt = TextBox(terminalio.FONT, width=88, height=30, align=TextBox.ALIGN_RIGHT, background_color=color_palette["accent"], text="[E]: Edit\n[Enter]: Run")
|
# 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")
|
||||||
help_txt.anchor_point = (0, 0)
|
help_txt.anchor_point = (0, 0)
|
||||||
|
|
||||||
help_txt.anchored_position = (2, 2)
|
help_txt.anchored_position = (2, 2)
|
||||||
|
|
@ -433,10 +427,10 @@ def change_selected(new_selected):
|
||||||
|
|
||||||
# tuple means an item in the grid is selected
|
# tuple means an item in the grid is selected
|
||||||
if isinstance(new_selected, tuple):
|
if isinstance(new_selected, tuple):
|
||||||
menu_grid.get_content(new_selected)[1].background_color = color_palette["accent"]
|
menu_grid.get_content(new_selected)[1].background_color = int(launcher_config["palette"].get("accent", "0x008800"), 16)
|
||||||
# TileGrid means arrow is selected
|
# TileGrid means arrow is selected
|
||||||
elif isinstance(new_selected, AnchoredTileGrid):
|
elif isinstance(new_selected, AnchoredTileGrid):
|
||||||
new_selected.pixel_shader[2] = color_palette["accent"]
|
new_selected.pixel_shader[2] = int(launcher_config["palette"].get("accent", "0x008800"), 16)
|
||||||
selected = new_selected
|
selected = new_selected
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -552,7 +546,7 @@ while True:
|
||||||
|
|
||||||
handle_key_press(c)
|
handle_key_press(c)
|
||||||
print("selected", selected)
|
print("selected", selected)
|
||||||
# app_titles[selected].background_color = color_palette["accent"]
|
# app_titles[selected].background_color = int(launcher_config["palette"].get("accent", "0x008800"), 16)
|
||||||
|
|
||||||
if mouse:
|
if mouse:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1 @@
|
||||||
CIRCUITPY_PYSTACK_SIZE=4000
|
CIRCUITPY_PYSTACK_SIZE=4000
|
||||||
# FRUIT_JAM_OS_BG=0x222222
|
|
||||||
# FRUIT_JAM_OS_FG=0xffffff
|
|
||||||
# FRUIT_JAM_OS_ACCENT=0x008800
|
|
||||||
# FRUIT_JAM_OS_ARROW=0x004abe
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue