24
24
25
25
26
26
import terminalio
27
- from displayio import TileGrid
27
+ from displayio import TileGrid , OnDiskBitmap , ColorConverter
28
28
import adafruit_imageload
29
29
from adafruit_display_text import bitmap_label
30
30
from adafruit_displayio_layout .widgets .control import Control
@@ -39,6 +39,8 @@ class IconWidget(Widget, Control):
39
39
40
40
:param string label_text: the text that will be shown beneath the icon image.
41
41
: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
42
44
43
45
:param int x: x location the icon widget should be placed. Pixel coordinates.
44
46
:param int y: y location the icon widget should be placed. Pixel coordinates.
@@ -53,10 +55,16 @@ class IconWidget(Widget, Control):
53
55
54
56
"""
55
57
56
- def __init__ (self , label_text , icon , ** kwargs ):
58
+ def __init__ (self , label_text , icon , on_disk = False , ** kwargs ):
57
59
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 )
60
68
self .append (tile_grid )
61
69
_label = bitmap_label .Label (
62
70
terminalio .FONT ,
0 commit comments