Skip to content

OnDiskBitmap fails quietly when file has been closed #4197

@hwiguna

Description

@hwiguna

This might be obvious to experienced Python programmers, but not to me.
The code runs with no errors, but the display does not show the bitmap because the with statement has closed the file.
To help beginners like me, it would be good if OnDiskBitmap would throw an exception if it cannot read the file instead of failing quietly as it does now.

with open("hari/BlobAnim.bmp", "rb") as bitmap_file:
    bitmap = displayio.OnDiskBitmap(bitmap_file) # setup the file as bitmap data source
print("bitmap ok",bitmap) # this confirms that we have an OnDiskBitmap object.

#... much later in code... using this bitmap does not work because the with open() had closed the file :-(
tileGrid = displayio.TileGrid(bitmap, pixel_shader=displayio.ColorConverter(), width=1, height=1, tile_width=7, tile_height=7)
print("tileGrid ok",tileGrid)

code.py output:
bitmap ok
tileGrid ok

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions