1- from sys import version_info
2-
31import warnings
4- from collections import namedtuple
2+
53from typing import List , Union , Tuple , Dict , Any , Callable , Set , Optional
64from typing import TYPE_CHECKING
75
1311from pygame_gui .core .utility import basic_blit
1412from pygame_gui .core .layered_gui_group import GUISprite
1513from pygame_gui .core .utility import get_default_manager
16-
14+ from pygame_gui . core . object_id import ObjectID
1715
1816if TYPE_CHECKING :
1917 from pygame_gui .core .drawable_shapes .drawable_shape import DrawableShape
2018
21- if version_info .minor >= 7 :
22- ObjectID = namedtuple ('ObjectID' ,
23- field_names = ('object_id' , 'class_id' ),
24- defaults = (None , None ))
25- else :
26- ObjectID = namedtuple ('ObjectID' , field_names = ('object_id' , 'class_id' ))
27-
2819
2920class UIElement (GUISprite , IUIElementInterface ):
3021 """
@@ -285,13 +276,29 @@ def get_element_ids(self) -> List[str]:
285276 """
286277 A list of all the element IDs in this element's theming/event hierarchy.
287278
288- :return: a list of strings, one ofr each element in the hierarchy.
279+ :return: a list of strings, one for each element in the hierarchy.
289280 """
290281 return self .element_ids
291282
283+ def get_class_ids (self ) -> List [str ]:
284+ """
285+ A list of all the class IDs in this element's theming/event hierarchy.
286+
287+ :return: a list of strings, one for each element in the hierarchy.
288+ """
289+ return self .class_ids
290+
291+ def get_object_ids (self ) -> List [str ]:
292+ """
293+ A list of all the object IDs in this element's theming/event hierarchy.
294+
295+ :return: a list of strings, one for each element in the hierarchy.
296+ """
297+ return self .object_ids
298+
292299 def _create_valid_ids (self ,
293300 container : Union [IContainerLikeInterface , None ],
294- parent_element : Union [None , 'UIElement' ],
301+ parent_element : Union [None , IUIElementInterface ],
295302 object_id : Union [ObjectID , str , None ],
296303 element_id : str ):
297304 """
@@ -308,9 +315,10 @@ def _create_valid_ids(self,
308315 :param element_id: A string ID representing this element's class.
309316
310317 """
318+ id_parent : Union [IContainerLikeInterface , IUIElementInterface , None ] = None
311319 if parent_element is None and container is not None :
312320 id_parent = container
313- else :
321+ elif parent_element is not None :
314322 id_parent = parent_element
315323
316324 if isinstance (object_id , str ):
@@ -326,13 +334,13 @@ def _create_valid_ids(self,
326334 class_id = None
327335
328336 if id_parent is not None :
329- self .element_ids = id_parent .element_ids .copy ()
337+ self .element_ids = id_parent .get_element_ids () .copy ()
330338 self .element_ids .append (element_id )
331339
332- self .class_ids = id_parent .class_ids .copy ()
340+ self .class_ids = id_parent .get_class_ids () .copy ()
333341 self .class_ids .append (class_id )
334342
335- self .object_ids = id_parent .object_ids .copy ()
343+ self .object_ids = id_parent .get_object_ids () .copy ()
336344 self .object_ids .append (obj_id )
337345 else :
338346 self .element_ids = [element_id ]
0 commit comments