From 3d51a5be766e952b7a0123d987197ca4246e885b Mon Sep 17 00:00:00 2001 From: James Carr Date: Fri, 6 Aug 2021 17:39:57 +0100 Subject: [PATCH] Update OnDiskBitmap code to take a filename string with CP7 --- .../displayio_ondiskbitmap.py | 29 ++++++++++++++++++- CircuitPython_displayio/displayio_text.py | 4 +-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/CircuitPython_displayio/displayio_ondiskbitmap.py b/CircuitPython_displayio/displayio_ondiskbitmap.py index 83403c7a7..109d0f9dd 100644 --- a/CircuitPython_displayio/displayio_ondiskbitmap.py +++ b/CircuitPython_displayio/displayio_ondiskbitmap.py @@ -3,6 +3,8 @@ display = board.DISPLAY +# Current method valid for CircuitPython 6 & 7 + # Open the file with open("/purple.bmp", "rb") as bitmap_file: @@ -10,7 +12,10 @@ bitmap = displayio.OnDiskBitmap(bitmap_file) # Create a TileGrid to hold the bitmap - tile_grid = displayio.TileGrid(bitmap, pixel_shader=getattr(bitmap, 'pixel_shader', displayio.ColorConverter())) + tile_grid = displayio.TileGrid( + bitmap, + pixel_shader=getattr(bitmap, 'pixel_shader', displayio.ColorConverter()) + ) # Create a Group to hold the TileGrid group = displayio.Group() @@ -24,3 +29,25 @@ # Loop forever so you can enjoy your image while True: pass + + +# Future method for CircuitPython 7 onwards + +# Setup the file as the bitmap data source +bitmap = displayio.OnDiskBitmap("/purple.bmp") + +# Create a TileGrid to hold the bitmap +tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader) + +# Create a Group to hold the TileGrid +group = displayio.Group() + +# Add the TileGrid to the Group +group.append(tile_grid) + +# Add the Group to the Display +display.show(group) + +# Loop forever so you can enjoy your image +while True: + pass diff --git a/CircuitPython_displayio/displayio_text.py b/CircuitPython_displayio/displayio_text.py index c02c4c03d..72002abb4 100644 --- a/CircuitPython_displayio/displayio_text.py +++ b/CircuitPython_displayio/displayio_text.py @@ -9,8 +9,8 @@ font = terminalio.FONT color = 0x0000FF -# Create the tet label -text_area = label.Label(font, text="HELLO WORLD", color=0x00FF00) +# Create the text label +text_area = label.Label(font, text=text, color=color) # Set the location text_area.x = 100