|
53 | 53 | //| splash = displayio.Group()
|
54 | 54 | //| board.DISPLAY.show(splash)
|
55 | 55 | //|
|
56 |
| -//| with open("/sample.bmp", "rb") as f: |
57 |
| -//| odb = displayio.OnDiskBitmap(f) |
58 |
| -//| face = displayio.TileGrid(odb, pixel_shader=odb.pixel_shader) |
59 |
| -//| splash.append(face) |
60 |
| -//| # Wait for the image to load. |
61 |
| -//| board.DISPLAY.refresh(target_frames_per_second=60) |
| 56 | +//| odb = displayio.OnDiskBitmap('/sample.bmp') |
| 57 | +//| face = displayio.TileGrid(odb, pixel_shader=odb.pixel_shader) |
| 58 | +//| splash.append(face) |
| 59 | +//| # Wait for the image to load. |
| 60 | +//| board.DISPLAY.refresh(target_frames_per_second=60) |
62 | 61 | //|
|
63 |
| -//| # Fade up the backlight |
64 |
| -//| for i in range(100): |
65 |
| -//| board.DISPLAY.brightness = 0.01 * i |
66 |
| -//| time.sleep(0.05) |
| 62 | +//| # Fade up the backlight |
| 63 | +//| for i in range(100): |
| 64 | +//| board.DISPLAY.brightness = 0.01 * i |
| 65 | +//| time.sleep(0.05) |
67 | 66 | //|
|
68 |
| -//| # Wait forever |
69 |
| -//| while True: |
70 |
| -//| pass""" |
| 67 | +//| # Wait forever |
| 68 | +//| while True: |
| 69 | +//| pass""" |
71 | 70 | //|
|
72 |
| -//| def __init__(self, file: typing.BinaryIO) -> None: |
| 71 | +//| def __init__(self, file: Union[str,typing.BinaryIO]) -> None: |
73 | 72 | //| """Create an OnDiskBitmap object with the given file.
|
74 | 73 | //|
|
75 |
| -//| :param file file: The open bitmap file""" |
| 74 | +//| :param file file: The name of the bitmap file. For backwards compatibility, a file opened in binary mode may also be passed. |
| 75 | +//| |
| 76 | +//| Older versions of CircuitPython required a file opened in binary |
| 77 | +//| mode. CircuitPython 7.0 modified OnDiskBitmap so that it takes a |
| 78 | +//| filename instead, and opens the file internally. A future version |
| 79 | +//| of CircuitPython will remove the ability to pass in an opened file. |
| 80 | +//| """ |
76 | 81 | //| ...
|
77 | 82 | //|
|
78 | 83 | STATIC mp_obj_t displayio_ondiskbitmap_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
79 | 84 | mp_arg_check_num(n_args, kw_args, 1, 1, false);
|
| 85 | + mp_obj_t arg = pos_args[0]; |
80 | 86 |
|
81 |
| - if (!mp_obj_is_type(pos_args[0], &mp_type_fileio)) { |
| 87 | + if (mp_obj_is_str(arg)) { |
| 88 | + arg = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), arg, MP_ROM_QSTR(MP_QSTR_rb)); |
| 89 | + } |
| 90 | + if (!mp_obj_is_type(arg, &mp_type_fileio)) { |
82 | 91 | mp_raise_TypeError(translate("file must be a file opened in byte mode"));
|
83 | 92 | }
|
84 | 93 |
|
85 | 94 | displayio_ondiskbitmap_t *self = m_new_obj(displayio_ondiskbitmap_t);
|
86 | 95 | self->base.type = &displayio_ondiskbitmap_type;
|
87 |
| - common_hal_displayio_ondiskbitmap_construct(self, MP_OBJ_TO_PTR(pos_args[0])); |
| 96 | + common_hal_displayio_ondiskbitmap_construct(self, MP_OBJ_TO_PTR(arg)); |
88 | 97 |
|
89 | 98 | return MP_OBJ_FROM_PTR(self);
|
90 | 99 | }
|
|
0 commit comments