Skip to content

Commit 2de4173

Browse files
authored
Merge pull request #45 from relic-se/color-palette
Add support for color palette environment variables
2 parents 8b5b975 + 4c561b5 commit 2de4173

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

src/code.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import json
1010
import math
1111
import displayio
12+
import os
1213
import supervisor
1314
import sys
1415
import terminalio
@@ -52,6 +53,14 @@
5253
print(f"launching: {next_code_file}")
5354
supervisor.reload()
5455

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+
5564
request_display_config(720, 400)
5665
display = supervisor.runtime.display
5766

@@ -70,7 +79,7 @@
7079

7180
background_bmp = displayio.Bitmap(display.width, display.height, 1)
7281
bg_palette = displayio.Palette(1)
73-
bg_palette[0] = 0x222222
82+
bg_palette[0] = color_palette["bg"]
7483
bg_tg = displayio.TileGrid(bitmap=background_bmp, pixel_shader=bg_palette)
7584
scaled_group.append(bg_tg)
7685

@@ -184,7 +193,7 @@
184193
divider_lines=False)
185194
scaled_group.append(menu_grid)
186195

187-
menu_title_txt = Label(font, text="Fruit Jam OS")
196+
menu_title_txt = Label(font, text="Fruit Jam OS", color=color_palette["fg"])
188197
menu_title_txt.anchor_point = (0.5, 0.5)
189198
menu_title_txt.anchored_position = (display.width // (2 * scale), 2)
190199
scaled_group.append(menu_title_txt)
@@ -268,7 +277,7 @@ def _create_cell_group(app):
268277

269278
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
270279
title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
271-
align=TextBox.ALIGN_CENTER)
280+
align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
272281
cell_group.append(title_txt)
273282
title_txt.anchor_point = (0, 0)
274283
title_txt.anchored_position = (0, icon_tg.y + icon_tg.tile_height)
@@ -289,7 +298,7 @@ def _reuse_cell_group(app, cell_group):
289298

290299
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
291300
# title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
292-
# align=TextBox.ALIGN_CENTER)
301+
# align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
293302
# cell_group.append(title_txt)
294303
title_txt = cell_group[1]
295304
title_txt.text = app["title"]
@@ -338,7 +347,7 @@ def display_page(page_index):
338347
print(f"{grid_index} | {grid_index % config["width"], grid_index // config["width"]}")
339348

340349

341-
page_txt = Label(terminalio.FONT, text="", scale=2)
350+
page_txt = Label(terminalio.FONT, text="", scale=2, color=color_palette["fg"])
342351
page_txt.anchor_point = (1.0, 1.0)
343352
page_txt.anchored_position = (display.width - 2, display.height - 2)
344353
main_group.append(page_txt)
@@ -350,6 +359,8 @@ def display_page(page_index):
350359
left_palette.make_transparent(0)
351360
right_bmp, right_palette = adafruit_imageload.load("launcher_assets/arrow_right.bmp")
352361
right_palette.make_transparent(0)
362+
if color_palette["arrow"] >= 0:
363+
left_palette[2] = right_palette[2] = color_palette["arrow"]
353364

354365
left_tg = AnchoredTileGrid(bitmap=left_bmp, pixel_shader=left_palette)
355366
left_tg.anchor_point = (0, 0.5)
@@ -371,8 +382,9 @@ def display_page(page_index):
371382
scaled_group.append(mouse_tg)
372383

373384

374-
help_txt = Label(terminalio.FONT, text="[Arrow]: Move\n[E]: Edit\n[Enter]: Run\n[1-9]: Page")
375-
# help_txt = TextBox(terminalio.FONT, width=88, height=30, align=TextBox.ALIGN_RIGHT, background_color=0x008800, text="[E]: Edit\n[Enter]: Run")
385+
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")
376388
help_txt.anchor_point = (0, 0)
377389

378390
help_txt.anchored_position = (2, 2)
@@ -409,10 +421,10 @@ def change_selected(new_selected):
409421

410422
# tuple means an item in the grid is selected
411423
if isinstance(new_selected, tuple):
412-
menu_grid.get_content(new_selected)[1].background_color = 0x008800
424+
menu_grid.get_content(new_selected)[1].background_color = color_palette["accent"]
413425
# TileGrid means arrow is selected
414426
elif isinstance(new_selected, AnchoredTileGrid):
415-
new_selected.pixel_shader[2] = 0x008800
427+
new_selected.pixel_shader[2] = color_palette["accent"]
416428
selected = new_selected
417429

418430

@@ -528,7 +540,7 @@ def handle_key_press(key):
528540

529541
handle_key_press(c)
530542
print("selected", selected)
531-
# app_titles[selected].background_color = 0x008800
543+
# app_titles[selected].background_color = color_palette["accent"]
532544

533545
if mouse:
534546
try:

src/settings.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
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)