@@ -195,6 +195,21 @@ STATIC mp_obj_t displayio_group_obj_insert(mp_obj_t self_in, mp_obj_t index_obj,
195195}
196196MP_DEFINE_CONST_FUN_OBJ_3 (displayio_group_insert_obj , displayio_group_obj_insert );
197197
198+
199+ //| .. method:: index(layer)
200+ //|
201+ //| Returns the index of the first copy of layer. Raises ValueError if not found.
202+ //|
203+ STATIC mp_obj_t displayio_group_obj_index (mp_obj_t self_in , mp_obj_t layer ) {
204+ displayio_group_t * self = native_group (self_in );
205+ mp_int_t index = common_hal_displayio_group_index (self , layer );
206+ if (index < 0 ) {
207+ mp_raise_ValueError (translate ("object not in sequence" ));
208+ }
209+ return MP_OBJ_NEW_SMALL_INT (index );
210+ }
211+ MP_DEFINE_CONST_FUN_OBJ_2 (displayio_group_index_obj , displayio_group_obj_index );
212+
198213//| .. method:: pop(i=-1)
199214//|
200215//| Remove the ith item and return it.
@@ -217,6 +232,20 @@ STATIC mp_obj_t displayio_group_obj_pop(size_t n_args, const mp_obj_t *pos_args,
217232}
218233MP_DEFINE_CONST_FUN_OBJ_KW (displayio_group_pop_obj , 1 , displayio_group_obj_pop );
219234
235+
236+ //| .. method:: remove(layer)
237+ //|
238+ //| Remove the first copy of layer. Raises ValueError if it is not present.
239+ //|
240+ STATIC mp_obj_t displayio_group_obj_remove (mp_obj_t self_in , mp_obj_t layer ) {
241+ mp_obj_t index = displayio_group_obj_index (self_in , layer );
242+ displayio_group_t * self = native_group (self_in );
243+
244+ common_hal_displayio_group_pop (self , MP_OBJ_SMALL_INT_VALUE (index ));
245+ return mp_const_none ;
246+ }
247+ MP_DEFINE_CONST_FUN_OBJ_2 (displayio_group_remove_obj , displayio_group_obj_remove );
248+
220249//| .. method:: __len__()
221250//|
222251//| Returns the number of layers in a Group
@@ -281,7 +310,9 @@ STATIC const mp_rom_map_elem_t displayio_group_locals_dict_table[] = {
281310 { MP_ROM_QSTR (MP_QSTR_y ), MP_ROM_PTR (& displayio_group_y_obj ) },
282311 { MP_ROM_QSTR (MP_QSTR_append ), MP_ROM_PTR (& displayio_group_append_obj ) },
283312 { MP_ROM_QSTR (MP_QSTR_insert ), MP_ROM_PTR (& displayio_group_insert_obj ) },
313+ { MP_ROM_QSTR (MP_QSTR_index ), MP_ROM_PTR (& displayio_group_index_obj ) },
284314 { MP_ROM_QSTR (MP_QSTR_pop ), MP_ROM_PTR (& displayio_group_pop_obj ) },
315+ { MP_ROM_QSTR (MP_QSTR_remove ), MP_ROM_PTR (& displayio_group_remove_obj ) },
285316};
286317STATIC MP_DEFINE_CONST_DICT (displayio_group_locals_dict , displayio_group_locals_dict_table );
287318
@@ -291,5 +322,6 @@ const mp_obj_type_t displayio_group_type = {
291322 .make_new = displayio_group_make_new ,
292323 .subscr = group_subscr ,
293324 .unary_op = group_unary_op ,
325+ .getiter = mp_obj_new_generic_iterator ,
294326 .locals_dict = (mp_obj_dict_t * )& displayio_group_locals_dict ,
295327};
0 commit comments