Skip to content

Commit 054b12a

Browse files
authored
Merge pull request #17 from FoamyGuy/iconwidget_ondisk
on_disk argument for IconWidget to use OnDiskBitmap
2 parents f922a68 + 31804b3 commit 054b12a

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

adafruit_displayio_layout/widgets/icon_widget.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
import terminalio
27-
from displayio import TileGrid
27+
from displayio import TileGrid, OnDiskBitmap, ColorConverter
2828
import adafruit_imageload
2929
from adafruit_display_text import bitmap_label
3030
from 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

Comments
 (0)