2424
2525
2626import terminalio
27- from displayio import TileGrid
27+ from displayio import TileGrid , OnDiskBitmap , ColorConverter
2828import adafruit_imageload
2929from adafruit_display_text import bitmap_label
3030from adafruit_displayio_layout .widgets .control import Control
@@ -39,6 +39,8 @@ class IconWidget(Widget, Control):
3939
4040 :param string label_text: the text that will be shown beneath the icon image.
4141 :param string icon: the filepath of the bmp image to be used as the icon.
42+ :param boolean on_disk: if True use OnDiskBitmap instead of imageload.
43+ This can be helpful to save memory. Defaults to False
4244
4345 :param int x: x location the icon widget should be placed. Pixel coordinates.
4446 :param int y: y location the icon widget should be placed. Pixel coordinates.
@@ -53,10 +55,16 @@ class IconWidget(Widget, Control):
5355
5456 """
5557
56- def __init__ (self , label_text , icon , ** kwargs ):
58+ def __init__ (self , label_text , icon , on_disk = False , ** kwargs ):
5759 super ().__init__ (** kwargs )
58- image , palette = adafruit_imageload .load (icon )
59- tile_grid = TileGrid (image , pixel_shader = palette )
60+
61+ if on_disk :
62+ self ._file = open (icon , "rb" )
63+ image = OnDiskBitmap (self ._file )
64+ tile_grid = TileGrid (image , pixel_shader = ColorConverter ())
65+ else :
66+ image , palette = adafruit_imageload .load (icon )
67+ tile_grid = TileGrid (image , pixel_shader = palette )
6068 self .append (tile_grid )
6169 _label = bitmap_label .Label (
6270 terminalio .FONT ,
0 commit comments