from __future__ import annotations
from typing import cast, TYPE_CHECKING, Tuple
try:
# python 3.12+
from typing import override # noqa # type: ignore
except ImportError:
from typing_extensions import override # noqa # type: ignore
from ooodev.adapter.component_base import ComponentBase
from ooodev.adapter.text.text_section_partial import TextSectionPartial
if TYPE_CHECKING:
from com.sun.star.text import TextSection # service
from com.sun.star.text import XTextSection
[docs]class TextSectionComp(ComponentBase, TextSectionPartial):
"""
Class for managing TextSection Component.
"""
# pylint: disable=unused-argument
[docs] def __init__(self, component: XTextSection) -> None:
"""
Constructor
Args:
component (TextSection): UNO TextRange Component that supports ``com.sun.star.text.TextSection`` service.
"""
ComponentBase.__init__(self, component)
TextSectionPartial.__init__(self, component)
# region Overrides
@override
def _ComponentBase__get_supported_service_names(self) -> tuple[str, ...]:
"""Returns a tuple of supported service names."""
# validated by TextSectionPartial
return () # ("com.sun.star.text.TextSection",)
[docs] @override
def get_child_sections(self) -> Tuple[TextSectionComp, ...]: # type: ignore
"""
Gets all text sections that are children of this text section (recursive).
"""
result = []
sections = self.component.getChildSections()
if sections is not None:
result.extend(TextSectionComp(section) for section in sections)
return tuple(result)
# endregion Overrides
# region Properties
@property
@override
def component(self) -> TextSection:
"""TextSection Component"""
# pylint: disable=no-member
return cast("TextSection", self._ComponentBase__get_component()) # type: ignore
# endregion Properties