diff --git a/src/code.py b/src/code.py index 3e969c5..acf9a82 100644 --- a/src/code.py +++ b/src/code.py @@ -7,13 +7,11 @@ """ import array -import board import displayio import pathlib import supervisor import sys import usb -from adafruit_display_text import label from adafruit_bitmap_font import bitmap_font from adafruit_display_text.text_box import TextBox from adafruit_display_text.bitmap_label import Label @@ -21,7 +19,7 @@ from adafruit_anchored_tilegrid import AnchoredTileGrid import adafruit_imageload import adafruit_usb_host_descriptors -from sized_group import SizedGroup +from adafruit_anchored_group import AnchoredGroup display = supervisor.runtime.display font_file = "/fonts/terminal.lvfontbin" @@ -36,7 +34,7 @@ main_group.append(bg_tg) # load the mouse cursor bitmap -mouse_bmp = displayio.OnDiskBitmap("mouse_cursor.bmp") +mouse_bmp = displayio.OnDiskBitmap("launcher_assets/mouse_cursor.bmp") # make the background pink pixels transparent mouse_bmp.pixel_shader.make_transparent(0) @@ -47,15 +45,15 @@ # move it to the center of the display mouse_tg.x = display.width // 2 mouse_tg.y = display.height // 2 -#046d:c52f +# 046d:c52f -#mouse = usb.core.find(idVendor=0x046d, idProduct=0xc52f) +# mouse = usb.core.find(idVendor=0x046d, idProduct=0xc52f) DIR_IN = 0x80 mouse_interface_index, mouse_endpoint_address = None, None mouse = None -#scan for connected USB device and loop over any found +# scan for connected USB device and loop over any found print("scanning usb") for device in usb.core.find(find_all=True): # print device info @@ -152,7 +150,7 @@ cell_width = WIDTH // config["width"] -default_icon_bmp, default_icon_palette = adafruit_imageload.load("default_icon_64.bmp") +default_icon_bmp, default_icon_palette = adafruit_imageload.load("launcher_assets/default_icon.bmp") default_icon_palette.make_transparent(0) menu_grid = GridLayout(x=10, y=26, width=WIDTH, height=HEIGHT, grid_size=(config["width"], config["height"]), divider_lines=False) @@ -160,7 +158,7 @@ menu_title_txt = Label(font, text=config["menu_title"]) menu_title_txt.anchor_point = (0.5, 0.5) -menu_title_txt.anchored_position = (display.width//2, 2) +menu_title_txt.anchored_position = (display.width // 2, 2) main_group.append(menu_title_txt) app_titles = [] @@ -172,7 +170,7 @@ code_file = path / "code.py" if not code_file.exists(): continue - cell_group = SizedGroup() + cell_group = AnchoredGroup() icon_file = path / "icon.bmp" if not icon_file.exists(): icon_file = None @@ -189,18 +187,19 @@ icon_tg = displayio.TileGrid(bitmap=icon_bmp, pixel_shader=icon_palette) cell_group.append(icon_tg) - icon_tg.x = cell_width//2 - icon_tg.tile_width//2 - title_txt = TextBox(font, text=apps[-1]["title"], width=WIDTH // config["width"], height=18, align=TextBox.ALIGN_CENTER) + icon_tg.x = cell_width // 2 - icon_tg.tile_width // 2 + title_txt = TextBox(font, text=apps[-1]["title"], width=WIDTH // config["width"], height=18, + align=TextBox.ALIGN_CENTER) cell_group.append(title_txt) - title_txt.anchor_point = (0,0) + title_txt.anchor_point = (0, 0) title_txt.anchored_position = (0, icon_tg.y + icon_tg.tile_height) app_titles.append(title_txt) menu_grid.add_content(cell_group, grid_position=(i % config["width"], i // config["width"]), cell_size=(1, 1)) i += 1 -left_bmp, left_palette = adafruit_imageload.load("arrow_left.bmp") +left_bmp, left_palette = adafruit_imageload.load("launcher_assets/arrow_left.bmp") left_palette.make_transparent(0) -right_bmp, right_palette = adafruit_imageload.load("arrow_right.bmp") +right_bmp, right_palette = adafruit_imageload.load("launcher_assets/arrow_right.bmp") right_palette.make_transparent(0) left_tg = AnchoredTileGrid(bitmap=left_bmp, pixel_shader=left_palette) @@ -257,9 +256,10 @@ clicked_cell = menu_grid.which_cell_contains((mouse_tg.x, mouse_tg.y)) if clicked_cell is not None: index = clicked_cell[1] * config["width"] + clicked_cell[0] - + if index is not None: - supervisor.set_next_code_file(config["apps"][index]["file"], sticky_on_reload=True, reload_on_error=True, working_directory="/apps/matrix") + supervisor.set_next_code_file(config["apps"][index]["file"], sticky_on_reload=True, reload_on_error=True, + working_directory="/apps/matrix") if mouse and not mouse.is_kernel_driver_active(0): mouse.attach_kernel_driver(0) diff --git a/src/launcher_assets/arrow_left.bmp b/src/launcher_assets/arrow_left.bmp new file mode 100644 index 0000000..27e5875 Binary files /dev/null and b/src/launcher_assets/arrow_left.bmp differ diff --git a/src/launcher_assets/arrow_right.bmp b/src/launcher_assets/arrow_right.bmp new file mode 100644 index 0000000..b495b96 Binary files /dev/null and b/src/launcher_assets/arrow_right.bmp differ diff --git a/src/launcher_assets/default_icon.bmp b/src/launcher_assets/default_icon.bmp new file mode 100644 index 0000000..9112f8d Binary files /dev/null and b/src/launcher_assets/default_icon.bmp differ diff --git a/src/launcher_assets/mouse_cursor.bmp b/src/launcher_assets/mouse_cursor.bmp new file mode 100644 index 0000000..94ec328 Binary files /dev/null and b/src/launcher_assets/mouse_cursor.bmp differ diff --git a/src/sized_group.py b/src/sized_group.py deleted file mode 100644 index b16f680..0000000 --- a/src/sized_group.py +++ /dev/null @@ -1,49 +0,0 @@ -import displayio - -class SizedGroup(displayio.Group): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - - @property - def size(self): - min_x = 0 - min_y = 0 - max_x = 0 - max_y = 0 - - for element in self: - # print(type(element)) - if type(element) == displayio.TileGrid: - if element.x < min_x: - min_x = element.x - if element.y < min_y: - min_y = element.y - - _element_max_x = element.x + (element.width * element.tile_width) - _element_max_y = element.y + (element.height * element.tile_height) - if _element_max_x > max_x: - max_x = _element_max_x - if _element_max_y > max_y: - max_y = _element_max_y - else: - if element.x < min_x: - min_x = element.x - if element.y < min_y: - min_y = element.y - - _element_max_x = element.x + (element.width * element.scale) - _element_max_y = element.y + (element.height * element.scale) - if _element_max_x > max_x: - max_x = _element_max_x - if _element_max_y > max_y: - max_y = _element_max_y - return max_x - min_x, max_y - min_y - - @property - def width(self): - return self.size[0] - - @property - def height(self): - return self.size[1]