9
9
import json
10
10
import math
11
11
import displayio
12
- import os
13
12
import supervisor
14
13
import sys
15
14
import terminalio
53
52
print (f"launching: { next_code_file } " )
54
53
supervisor .reload ()
55
54
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
-
64
55
request_display_config (720 , 400 )
65
56
display = supervisor .runtime .display
66
57
67
58
scale = 1
68
59
if display .width > 360 :
69
60
scale = 2
70
61
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
+
71
69
font_file = "/fonts/terminal.lvfontbin"
72
70
font = bitmap_font .load_font (font_file )
73
71
scaled_group = displayio .Group (scale = scale )
79
77
80
78
background_bmp = displayio .Bitmap (display .width , display .height , 1 )
81
79
bg_palette = displayio .Palette (1 )
82
- bg_palette [0 ] = color_palette [ "bg" ]
80
+ bg_palette [0 ] = int ( launcher_config [ "palette" ]. get ( "bg" , "0x222222" ), 16 )
83
81
bg_tg = displayio .TileGrid (bitmap = background_bmp , pixel_shader = bg_palette )
84
82
scaled_group .append (bg_tg )
85
83
97
95
mouse_tg .y = display .height // (2 * scale )
98
96
# 046d:c52f
99
97
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
-
105
98
# mouse = usb.core.find(idVendor=0x046d, idProduct=0xc52f)
106
99
107
100
DIR_IN = 0x80
193
186
divider_lines = False )
194
187
scaled_group .append (menu_grid )
195
188
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 ) )
197
190
menu_title_txt .anchor_point = (0.5 , 0.5 )
198
191
menu_title_txt .anchored_position = (display .width // (2 * scale ), 2 )
199
192
scaled_group .append (menu_title_txt )
@@ -277,7 +270,7 @@ def _create_cell_group(app):
277
270
278
271
icon_tg .x = cell_width // 2 - icon_tg .tile_width // 2
279
272
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 ) )
281
274
cell_group .append (title_txt )
282
275
title_txt .anchor_point = (0 , 0 )
283
276
title_txt .anchored_position = (0 , icon_tg .y + icon_tg .tile_height )
@@ -298,7 +291,7 @@ def _reuse_cell_group(app, cell_group):
298
291
299
292
icon_tg .x = cell_width // 2 - icon_tg .tile_width // 2
300
293
# 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) )
302
295
# cell_group.append(title_txt)
303
296
title_txt = cell_group [1 ]
304
297
title_txt .text = app ["title" ]
@@ -347,7 +340,7 @@ def display_page(page_index):
347
340
print (f"{ grid_index } | { grid_index % config ["width" ], grid_index // config ["width" ]} " )
348
341
349
342
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 ) )
351
344
page_txt .anchor_point = (1.0 , 1.0 )
352
345
page_txt .anchored_position = (display .width - 2 , display .height - 2 )
353
346
main_group .append (page_txt )
@@ -359,8 +352,8 @@ def display_page(page_index):
359
352
left_palette .make_transparent (0 )
360
353
right_bmp , right_palette = adafruit_imageload .load ("launcher_assets/arrow_right.bmp" )
361
354
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 )
364
357
365
358
left_tg = AnchoredTileGrid (bitmap = left_bmp , pixel_shader = left_palette )
366
359
left_tg .anchor_point = (0 , 0.5 )
@@ -383,8 +376,8 @@ def display_page(page_index):
383
376
384
377
385
378
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")
388
381
help_txt .anchor_point = (0 , 0 )
389
382
390
383
help_txt .anchored_position = (2 , 2 )
@@ -421,10 +414,10 @@ def change_selected(new_selected):
421
414
422
415
# tuple means an item in the grid is selected
423
416
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 )
425
418
# TileGrid means arrow is selected
426
419
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 )
428
421
selected = new_selected
429
422
430
423
@@ -540,7 +533,7 @@ def handle_key_press(key):
540
533
541
534
handle_key_press (c )
542
535
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)
544
537
545
538
if mouse :
546
539
try :
0 commit comments