1
- from sys import version_info
2
-
3
1
import warnings
4
- from collections import namedtuple
2
+
5
3
from typing import List , Union , Tuple , Dict , Any , Callable , Set , Optional
6
4
from typing import TYPE_CHECKING
7
5
13
11
from pygame_gui .core .utility import basic_blit
14
12
from pygame_gui .core .layered_gui_group import GUISprite
15
13
from pygame_gui .core .utility import get_default_manager
16
-
14
+ from pygame_gui . core . object_id import ObjectID
17
15
18
16
if TYPE_CHECKING :
19
17
from pygame_gui .core .drawable_shapes .drawable_shape import DrawableShape
20
18
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
-
28
19
29
20
class UIElement (GUISprite , IUIElementInterface ):
30
21
"""
@@ -285,13 +276,29 @@ def get_element_ids(self) -> List[str]:
285
276
"""
286
277
A list of all the element IDs in this element's theming/event hierarchy.
287
278
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.
289
280
"""
290
281
return self .element_ids
291
282
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
+
292
299
def _create_valid_ids (self ,
293
300
container : Union [IContainerLikeInterface , None ],
294
- parent_element : Union [None , 'UIElement' ],
301
+ parent_element : Union [None , IUIElementInterface ],
295
302
object_id : Union [ObjectID , str , None ],
296
303
element_id : str ):
297
304
"""
@@ -308,9 +315,10 @@ def _create_valid_ids(self,
308
315
:param element_id: A string ID representing this element's class.
309
316
310
317
"""
318
+ id_parent : Union [IContainerLikeInterface , IUIElementInterface , None ] = None
311
319
if parent_element is None and container is not None :
312
320
id_parent = container
313
- else :
321
+ elif parent_element is not None :
314
322
id_parent = parent_element
315
323
316
324
if isinstance (object_id , str ):
@@ -326,13 +334,13 @@ def _create_valid_ids(self,
326
334
class_id = None
327
335
328
336
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 ()
330
338
self .element_ids .append (element_id )
331
339
332
- self .class_ids = id_parent .class_ids .copy ()
340
+ self .class_ids = id_parent .get_class_ids () .copy ()
333
341
self .class_ids .append (class_id )
334
342
335
- self .object_ids = id_parent .object_ids .copy ()
343
+ self .object_ids = id_parent .get_object_ids () .copy ()
336
344
self .object_ids .append (obj_id )
337
345
else :
338
346
self .element_ids = [element_id ]
0 commit comments