Source code for svgwriter.model.elements.structure._descriptive

"""
``desc``, ``title`` and ``metadata``.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

from .._behavior import CoreAttributes, StyleAttributes
from ..core import Category, Child, ContentModel

# region generated by `python scripts/dev.py svgwriter signatures write`: names used by the signatures
if TYPE_CHECKING:
    from collections.abc import Mapping, Sequence

    from ...attributes.style import StyleLike
    from .._behavior import XmlSpace
    from ..core import AttrValue
# endregion

__all__ = ["Desc", "Metadata", "Title"]


class _Descriptive(StyleAttributes, CoreAttributes, category=Category.DESCRIPTIVE, content=ContentModel.TEXT):
    def __init__(self, text: str = "", **kwargs: Any) -> None:
        super().__init__(*([text] if text else []), **kwargs)


[docs] class Desc(_Descriptive, tag="desc"): """``<desc>``: a long description. Parameters ---------- text : str, optional The description text. Defaults to empty. **kwargs Style, core and other SVG attributes in Python spelling. See Also -------- Title : A short, tooltip-style description. Examples -------- >>> import svgwriter as svg >>> str(svg.Desc("A red square")) '<desc>A red square</desc>' """ # region generated by `python scripts/dev.py svgwriter signatures write` def __init__( self, text: str = "", *, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any, ) -> None: """Create a ``<desc>`` element. Parameters ---------- text See the class docstring. class_, style, xml_base, xml_lang, xml_space, id, attrs The attribute groups of :class:`~svgwriter.StyleAttributes`, :class:`~svgwriter.CoreAttributes`, :class:`~svgwriter.Element`. Defaults to None (unset). **kwargs Any other SVG attribute in Python spelling, including namespaced and open ones (``inkscape_label``, ``data_*``). """ self._forward_common( kwargs, id, attrs, xml_base, xml_lang, xml_space, None, None, None, None, None, None, None, None, None, None, class_, style ) super().__init__(text, **kwargs)
# endregion
[docs] class Title(_Descriptive, tag="title"): """``<title>``: a short, tooltip-style description. Parameters ---------- text : str, optional The title text. Defaults to empty. **kwargs Style, core and other SVG attributes in Python spelling. See Also -------- Desc : A longer description. Examples -------- >>> import svgwriter as svg >>> str(svg.Title("Square")) '<title>Square</title>' """ # region generated by `python scripts/dev.py svgwriter signatures write` def __init__( self, text: str = "", *, class_: str | Sequence[str] | None = None, style: StyleLike | None = None, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any, ) -> None: """Create a ``<title>`` element. Parameters ---------- text See the class docstring. class_, style, xml_base, xml_lang, xml_space, id, attrs The attribute groups of :class:`~svgwriter.StyleAttributes`, :class:`~svgwriter.CoreAttributes`, :class:`~svgwriter.Element`. Defaults to None (unset). **kwargs Any other SVG attribute in Python spelling, including namespaced and open ones (``inkscape_label``, ``data_*``). """ self._forward_common( kwargs, id, attrs, xml_base, xml_lang, xml_space, None, None, None, None, None, None, None, None, None, None, class_, style ) super().__init__(text, **kwargs)
# endregion
[docs] class Metadata(CoreAttributes, tag="metadata", category=Category.DESCRIPTIVE, content=ContentModel.MIXED): """``<metadata>``: arbitrary content, usually RDF in a foreign namespace. Parameters ---------- *children : Element or str The content. **kwargs Core and other SVG attributes in Python spelling. Examples -------- >>> import svgwriter as svg >>> str(svg.Metadata("licensed")) '<metadata>licensed</metadata>' """ # region generated by `python scripts/dev.py svgwriter signatures write` def __init__( self, *children: Child, xml_base: str | None = None, xml_lang: str | None = None, xml_space: XmlSpace | None = None, id: str | None = None, attrs: Mapping[str, AttrValue] | None = None, **kwargs: Any, ) -> None: """Create a ``<metadata>`` element. Parameters ---------- *children See the class docstring. xml_base, xml_lang, xml_space, id, attrs The attribute groups of :class:`~svgwriter.CoreAttributes`, :class:`~svgwriter.Element`. Defaults to None (unset). **kwargs Any other SVG attribute in Python spelling, including namespaced and open ones (``inkscape_label``, ``data_*``). """ self._forward_common( kwargs, id, attrs, xml_base, xml_lang, xml_space ) # endregion super().__init__(*children, **kwargs)