Skip to content

Commit 03bd012

Browse files
committed
Pass filename to OnDiskBitmap to avoid closed file problem
1 parent d5aa61d commit 03bd012

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

adafruit_displayio_layout/widgets/icon_widget.py

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

2525

2626
import terminalio
27-
from displayio import TileGrid, OnDiskBitmap, ColorConverter
27+
from displayio import TileGrid, OnDiskBitmap
2828
import adafruit_imageload
2929
from adafruit_display_text import bitmap_label
3030
from adafruit_displayio_layout.widgets.control import Control
@@ -57,14 +57,8 @@ def __init__(self, label_text, icon, on_disk=False, **kwargs):
5757
self._icon = icon
5858

5959
if on_disk:
60-
with open(self._icon, "rb") as self._file:
61-
image = OnDiskBitmap(self._file)
62-
tile_grid = TileGrid(
63-
image,
64-
pixel_shader=getattr(image, "pixel_shader", ColorConverter())
65-
# TODO: Once CP6 is no longer supported replace the above line with below.
66-
# tile_grid = TileGrid(image, pixel_shader=image.pixel_shader)
67-
)
60+
image = OnDiskBitmap(self._icon)
61+
tile_grid = TileGrid(image, pixel_shader=image.pixel_shader)
6862
else:
6963
image, palette = adafruit_imageload.load(icon)
7064
tile_grid = TileGrid(image, pixel_shader=palette)

0 commit comments

Comments
 (0)