Skip to content

Commit 6b8b3b4

Browse files
committed
Add support for color palette environment variables
1 parent 8b5b975 commit 6b8b3b4

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/code.py

Lines changed: 19 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,13 @@
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+
}
62+
5563
request_display_config(720, 400)
5664
display = supervisor.runtime.display
5765

@@ -70,7 +78,7 @@
7078

7179
background_bmp = displayio.Bitmap(display.width, display.height, 1)
7280
bg_palette = displayio.Palette(1)
73-
bg_palette[0] = 0x222222
81+
bg_palette[0] = color_palette["bg"]
7482
bg_tg = displayio.TileGrid(bitmap=background_bmp, pixel_shader=bg_palette)
7583
scaled_group.append(bg_tg)
7684

@@ -184,7 +192,7 @@
184192
divider_lines=False)
185193
scaled_group.append(menu_grid)
186194

187-
menu_title_txt = Label(font, text="Fruit Jam OS")
195+
menu_title_txt = Label(font, text="Fruit Jam OS", color=color_palette["fg"])
188196
menu_title_txt.anchor_point = (0.5, 0.5)
189197
menu_title_txt.anchored_position = (display.width // (2 * scale), 2)
190198
scaled_group.append(menu_title_txt)
@@ -268,7 +276,7 @@ def _create_cell_group(app):
268276

269277
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
270278
title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
271-
align=TextBox.ALIGN_CENTER)
279+
align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
272280
cell_group.append(title_txt)
273281
title_txt.anchor_point = (0, 0)
274282
title_txt.anchored_position = (0, icon_tg.y + icon_tg.tile_height)
@@ -289,7 +297,7 @@ def _reuse_cell_group(app, cell_group):
289297

290298
icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2
291299
# title_txt = TextBox(font, text=app["title"], width=WIDTH // config["width"], height=18,
292-
# align=TextBox.ALIGN_CENTER)
300+
# align=TextBox.ALIGN_CENTER, color=color_palette["fg"])
293301
# cell_group.append(title_txt)
294302
title_txt = cell_group[1]
295303
title_txt.text = app["title"]
@@ -338,7 +346,7 @@ def display_page(page_index):
338346
print(f"{grid_index} | {grid_index % config["width"], grid_index // config["width"]}")
339347

340348

341-
page_txt = Label(terminalio.FONT, text="", scale=2)
349+
page_txt = Label(terminalio.FONT, text="", scale=2, color=color_palette["fg"])
342350
page_txt.anchor_point = (1.0, 1.0)
343351
page_txt.anchored_position = (display.width - 2, display.height - 2)
344352
main_group.append(page_txt)
@@ -371,8 +379,9 @@ def display_page(page_index):
371379
scaled_group.append(mouse_tg)
372380

373381

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")
382+
help_txt = Label(terminalio.FONT, text="[Arrow]: Move\n[E]: Edit\n[Enter]: Run\n[1-9]: Page",
383+
color=color_palette["fg"])
384+
# help_txt = TextBox(terminalio.FONT, width=88, height=30, align=TextBox.ALIGN_RIGHT, background_color=color_palette["accent"], text="[E]: Edit\n[Enter]: Run")
376385
help_txt.anchor_point = (0, 0)
377386

378387
help_txt.anchored_position = (2, 2)
@@ -409,10 +418,10 @@ def change_selected(new_selected):
409418

410419
# tuple means an item in the grid is selected
411420
if isinstance(new_selected, tuple):
412-
menu_grid.get_content(new_selected)[1].background_color = 0x008800
421+
menu_grid.get_content(new_selected)[1].background_color = color_palette["accent"]
413422
# TileGrid means arrow is selected
414423
elif isinstance(new_selected, AnchoredTileGrid):
415-
new_selected.pixel_shader[2] = 0x008800
424+
new_selected.pixel_shader[2] = color_palette["accent"]
416425
selected = new_selected
417426

418427

@@ -528,7 +537,7 @@ def handle_key_press(key):
528537

529538
handle_key_press(c)
530539
print("selected", selected)
531-
# app_titles[selected].background_color = 0x008800
540+
# app_titles[selected].background_color = color_palette["accent"]
532541

533542
if mouse:
534543
try:

src/settings.toml

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

0 commit comments

Comments
 (0)