Skip to content

on_disk argument for IconWidget to use OnDiskBitmap #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions adafruit_displayio_layout/widgets/icon_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


import terminalio
from displayio import TileGrid
from displayio import TileGrid, OnDiskBitmap, ColorConverter
import adafruit_imageload
from adafruit_display_text import bitmap_label
from adafruit_displayio_layout.widgets.control import Control
Expand All @@ -39,6 +39,8 @@ class IconWidget(Widget, Control):

:param string label_text: the text that will be shown beneath the icon image.
:param string icon: the filepath of the bmp image to be used as the icon.
:param boolean on_disk: if True use OnDiskBitmap instead of imageload.
This can be helpful to save memory. Defaults to False

:param int x: x location the icon widget should be placed. Pixel coordinates.
:param int y: y location the icon widget should be placed. Pixel coordinates.
Expand All @@ -53,10 +55,16 @@ class IconWidget(Widget, Control):

"""

def __init__(self, label_text, icon, **kwargs):
def __init__(self, label_text, icon, on_disk=False, **kwargs):
super().__init__(**kwargs)
image, palette = adafruit_imageload.load(icon)
tile_grid = TileGrid(image, pixel_shader=palette)

if on_disk:
self._file = open(icon, "rb")
image = OnDiskBitmap(self._file)
tile_grid = TileGrid(image, pixel_shader=ColorConverter())
else:
image, palette = adafruit_imageload.load(icon)
tile_grid = TileGrid(image, pixel_shader=palette)
self.append(tile_grid)
_label = bitmap_label.Label(
terminalio.FONT,
Expand Down