|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
import re
|
|
import re
|
|
import warnings
|
|
import warnings
|
|
from copy import deepcopy
|
|
from copy import deepcopy
|
|
-from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Union
|
|
|
|
|
|
+from typing import TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Optional, Union
|
|
|
|
|
|
from typing_extensions import Self
|
|
from typing_extensions import Self
|
|
|
|
|
|
@@ -75,9 +75,14 @@ class Element(Visibility):
|
|
def __exit__(self, *_):
|
|
def __exit__(self, *_):
|
|
self.default_slot.__exit__(*_)
|
|
self.default_slot.__exit__(*_)
|
|
|
|
|
|
|
|
+ def __iter__(self) -> Iterator[Element]:
|
|
|
|
+ for slot in self.slots.values():
|
|
|
|
+ for child in slot:
|
|
|
|
+ yield child
|
|
|
|
+
|
|
def _collect_slot_dict(self) -> Dict[str, List[int]]:
|
|
def _collect_slot_dict(self) -> Dict[str, List[int]]:
|
|
return {
|
|
return {
|
|
- name: {'template': slot.template, 'ids': [child.id for child in slot.children]}
|
|
|
|
|
|
+ name: {'template': slot.template, 'ids': [child.id for child in slot]}
|
|
for name, slot in self.slots.items()
|
|
for name, slot in self.slots.items()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -251,9 +256,8 @@ class Element(Visibility):
|
|
|
|
|
|
def _collect_descendant_ids(self) -> List[int]:
|
|
def _collect_descendant_ids(self) -> List[int]:
|
|
ids: List[int] = [self.id]
|
|
ids: List[int] = [self.id]
|
|
- for slot in self.slots.values():
|
|
|
|
- for child in slot.children:
|
|
|
|
- ids.extend(child._collect_descendant_ids())
|
|
|
|
|
|
+ for child in self:
|
|
|
|
+ ids.extend(child._collect_descendant_ids())
|
|
return ids
|
|
return ids
|
|
|
|
|
|
def clear(self) -> None:
|
|
def clear(self) -> None:
|
|
@@ -286,12 +290,12 @@ class Element(Visibility):
|
|
:param element: either the element instance or its ID
|
|
:param element: either the element instance or its ID
|
|
"""
|
|
"""
|
|
if isinstance(element, int):
|
|
if isinstance(element, int):
|
|
- children = [child for slot in self.slots.values() for child in slot.children]
|
|
|
|
|
|
+ children = list(self)
|
|
element = children[element]
|
|
element = children[element]
|
|
binding.remove([element], Element)
|
|
binding.remove([element], Element)
|
|
del self.client.elements[element.id]
|
|
del self.client.elements[element.id]
|
|
for slot in self.slots.values():
|
|
for slot in self.slots.values():
|
|
- slot.children[:] = [e for e in slot.children if e.id != element.id]
|
|
|
|
|
|
+ slot.children[:] = [e for e in slot if e.id != element.id]
|
|
self.update()
|
|
self.update()
|
|
|
|
|
|
def delete(self) -> None:
|
|
def delete(self) -> None:
|