53
53
print (f"launching: { next_code_file } " )
54
54
supervisor .reload ()
55
55
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
-
64
56
if (width_config := os .getenv ("CIRCUITPY_DISPLAY_WIDTH" )) is not None :
65
57
if width_config not in [x [0 ] for x in VALID_DISPLAY_SIZES ]:
66
58
raise ValueError (f"Invalid display size. Must be one of: { VALID_DISPLAY_SIZES } " )
76
68
if display .width > 360 :
77
69
scale = 2
78
70
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
+
79
78
font_file = "/fonts/terminal.lvfontbin"
80
79
font = bitmap_font .load_font (font_file )
81
80
scaled_group = displayio .Group (scale = scale )
87
86
88
87
background_bmp = displayio .Bitmap (display .width , display .height , 1 )
89
88
bg_palette = displayio .Palette (1 )
90
- bg_palette [0 ] = color_palette [ "bg" ]
89
+ bg_palette [0 ] = int ( launcher_config [ "palette" ]. get ( "bg" , "0x222222" ), 16 )
91
90
bg_tg = displayio .TileGrid (bitmap = background_bmp , pixel_shader = bg_palette )
92
91
scaled_group .append (bg_tg )
93
92
105
104
mouse_tg .y = display .height // (2 * scale )
106
105
# 046d:c52f
107
106
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
-
113
107
# mouse = usb.core.find(idVendor=0x046d, idProduct=0xc52f)
114
108
115
109
DIR_IN = 0x80
204
198
divider_lines = False )
205
199
scaled_group .append (menu_grid )
206
200
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 ) )
208
202
menu_title_txt .anchor_point = (0.5 , 0.5 )
209
203
menu_title_txt .anchored_position = (display .width // (2 * scale ), 2 )
210
204
scaled_group .append (menu_title_txt )
@@ -288,7 +282,7 @@ def _create_cell_group(app):
288
282
289
283
icon_tg .x = cell_width // 2 - icon_tg .tile_width // 2
290
284
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 ) )
292
286
icon_tg .y = (cell_height - icon_tg .tile_height - title_txt .height ) // 2
293
287
cell_group .append (title_txt )
294
288
title_txt .anchor_point = (0 , 0 )
@@ -310,7 +304,7 @@ def _reuse_cell_group(app, cell_group):
310
304
311
305
icon_tg .x = cell_width // 2 - icon_tg .tile_width // 2
312
306
# 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) )
314
308
# cell_group.append(title_txt)
315
309
title_txt = cell_group [1 ]
316
310
title_txt .text = app ["title" ]
@@ -359,7 +353,7 @@ def display_page(page_index):
359
353
print (f"{ grid_index } | { grid_index % config ["width" ], grid_index // config ["width" ]} " )
360
354
361
355
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 ) )
363
357
page_txt .anchor_point = (1.0 , 1.0 )
364
358
page_txt .anchored_position = (display .width - 2 , display .height - 2 )
365
359
main_group .append (page_txt )
@@ -371,8 +365,8 @@ def display_page(page_index):
371
365
left_palette .make_transparent (0 )
372
366
right_bmp , right_palette = adafruit_imageload .load ("launcher_assets/arrow_right.bmp" )
373
367
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 )
376
370
377
371
left_tg = AnchoredTileGrid (bitmap = left_bmp , pixel_shader = left_palette )
378
372
left_tg .anchor_point = (0 , 0.5 )
@@ -395,8 +389,8 @@ def display_page(page_index):
395
389
396
390
397
391
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")
400
394
help_txt .anchor_point = (0 , 0 )
401
395
402
396
help_txt .anchored_position = (2 , 2 )
@@ -433,10 +427,10 @@ def change_selected(new_selected):
433
427
434
428
# tuple means an item in the grid is selected
435
429
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 )
437
431
# TileGrid means arrow is selected
438
432
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 )
440
434
selected = new_selected
441
435
442
436
@@ -552,7 +546,7 @@ def handle_key_press(key):
552
546
553
547
handle_key_press (c )
554
548
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)
556
550
557
551
if mouse :
558
552
try :
0 commit comments