From 214dfed703e81770b3a74df09ce13d8f86fa7211 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Fri, 10 May 2019 16:41:13 -0500 Subject: [PATCH 1/3] Add documentation for Palette shared binding Add documentation for the palette subscript operator and how to use it. --- shared-bindings/displayio/Palette.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 799d42bef8376..55692eae194f6 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -66,7 +66,17 @@ STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_a return MP_OBJ_FROM_PTR(self); } - +//| .. method:: __setitem__(index, value) +//| +//| Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1 +//| +//| The color can be from 0x000000 to 0xFFFFFF, and can be an int or bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)) +//| +//| This allows you to:: +//| +//| palette[0] = 0xFFFFFF +//| palette[1] = 0xFF0000 +//| STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { if (value == MP_OBJ_NULL) { // delete item From ad211b23be17ed058ca686644d5e2323a005d0a4 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Fri, 10 May 2019 17:35:51 -0500 Subject: [PATCH 2/3] add documentation of transparency --- shared-bindings/displayio/Palette.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 55692eae194f6..90fd9bf525142 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -68,14 +68,16 @@ STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_a } //| .. method:: __setitem__(index, value) //| -//| Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1 +//| Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1. //| -//| The color can be from 0x000000 to 0xFFFFFF, and can be an int or bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)) +//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value), +//| or None to represent transparency. Value can be an int or bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)). //| //| This allows you to:: //| //| palette[0] = 0xFFFFFF //| palette[1] = 0xFF0000 +//| palette[2] = None # transparency //| STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { if (value == MP_OBJ_NULL) { From 0b1c1c1d929352c9995bcb1e58e90309d89b9d38 Mon Sep 17 00:00:00 2001 From: Matt Land Date: Tue, 14 May 2019 08:03:34 -0500 Subject: [PATCH 3/3] Update Palette.c Remove None, add in byte and bytearray examples --- shared-bindings/displayio/Palette.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 90fd9bf525142..11c2f677ce3bf 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -70,14 +70,15 @@ STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_a //| //| Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1. //| -//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value), -//| or None to represent transparency. Value can be an int or bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)). +//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value). +//| Value can be an int, bytes (3 bytes (RGB) or 4 bytes (RGB + pad byte)), or bytearray. //| //| This allows you to:: //| -//| palette[0] = 0xFFFFFF -//| palette[1] = 0xFF0000 -//| palette[2] = None # transparency +//| palette[0] = 0xFFFFFF # set using an integer +//| palette[1] = b'\xff\xff\x00' # set using 3 bytes +//| palette[2] = b'\xff\xff\x00\x00' # set using 4 bytes +//| palette[3] = bytearray(b'\x00\x00\xFF') # set using a bytearay of 3 or 4 bytes //| STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { if (value == MP_OBJ_NULL) {