Skip to content

Draw Page

DrawPage class for “draw:page” tag.

Classes:

Name Description
DrawPage

ODF draw page for presentations and drawings, “draw:page”.

DrawPage

Bases: SvgMixin, OfficeFormsMixin, Element

ODF draw page for presentations and drawings, “draw:page”.

Methods:

Name Description
__init__

Initialize the DrawPage.

get_formatted_text

Return a formatted string representation of the page’s content.

get_shapes

Get all shape elements within the page.

get_transition

Get the animation transition element for the page.

set_transition

Set or replace the animation transition for the page.

Attributes:

Name Type Description
draw_id
master_page
name
presentation_page_layout
style
Source code in odfdo/draw_page.py
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
class DrawPage(SvgMixin, OfficeFormsMixin, Element):
    """ODF draw page for presentations and drawings, "draw:page"."""

    _tag = "draw:page"
    _properties = (
        PropDef("name", "draw:name"),
        PropDef("draw_id", "draw:id"),
        PropDef("master_page", "draw:master-page-name"),
        PropDef(
            "presentation_page_layout", "presentation:presentation-page-layout-name"
        ),
        PropDef("style", "draw:style-name"),
    )

    def __init__(
        self,
        draw_id: str | None = None,
        name: str | None = None,
        master_page: str | None = None,
        presentation_page_layout: str | None = None,
        style: str | None = None,
        **kwargs: Any,
    ) -> None:
        """Initialize the DrawPage.

        Args:
            draw_id: The ID of the draw page ('draw:id').
            name: The name of the draw page ('draw:name').
            master_page: The name of the master page to use
                ('draw:master-page-name').
            presentation_page_layout: The name of the
                presentation page layout to use
                ('presentation:presentation-page-layout-name').
            style: The name of the style to apply to the page
                ('draw:style-name').
            **kwargs: Additional keyword arguments for the parent `Element` class.
        """
        super().__init__(**kwargs)
        if self._do_init:
            if draw_id:
                self.draw_id = draw_id
            if name:
                self.name = name
            if master_page:
                self.master_page = master_page
            if presentation_page_layout:
                self.presentation_page_layout = presentation_page_layout
            if style:
                self.style = style

    def get_transition(self) -> AnimPar | None:
        """Get the animation transition element for the page.

        Returns:
            AnimPar | None: The animation transition element (`anim:par`),
                or `None` if no transition is defined.
        """
        return self.get_element("anim:par")  # type: ignore

    def set_transition(
        self,
        smil_type: str,
        subtype: str | None = None,
        dur: str = "2s",
        node_type: str = "default",
    ) -> None:
        """Set or replace the animation transition for the page.

        This method creates a new animation transition (`anim:par` element)
        and replaces any existing transition on the page.

        Args:
            smil_type: The SMIL type for the transition (e.g., "fade").
            subtype: The SMIL subtype for the transition.
            dur: The duration of the transition (e.g., "2s").
            node_type: The presentation node type.
        """
        # Create the new animation
        anim_page = AnimPar(presentation_node_type=node_type)
        anim_begin = AnimPar(smil_begin=f"{self.draw_id}.begin")
        transition = AnimTransFilter(
            smil_dur=dur, smil_type=smil_type, smil_subtype=subtype
        )
        anim_page.append(anim_begin)
        anim_begin.append(transition)
        # Replace when already a transition:
        #   anim:seq => After the frame's transition
        #   cf page 349 of OpenDocument-v1.0-os.pdf
        #   Conclusion: We must delete the first child 'anim:par'
        previous_transition = self.get_transition()
        if previous_transition:
            self.delete(previous_transition)
        self.append(anim_page)

    def get_shapes(self) -> list[Element]:
        """Get all shape elements within the page.

        This includes all registered shapes such as lines, rectangles,
        ellipses, and connectors.

        Returns:
            list[Element]: A list of all shape elements found on the page.
        """
        query = "(descendant::" + "|descendant::".join(registered_shapes) + ")"
        return self.get_elements(query)

    def get_formatted_text(self, context: dict | None = None) -> str:
        """Return a formatted string representation of the page's content.

        This method recursively formats the text of all child elements,
        including presentation notes.

        Args:
            context: A dictionary providing context for formatting,
                such as footnote or annotation tracking.

        Returns:
            str: A formatted string of the page's textual content.
        """
        result: list[str] = []
        for child in self.children:
            if child.tag == "presentation:notes":
                # No need for an advanced odf_notes.get_formatted_text()
                # because the text seems to be only contained in paragraphs
                # and frames, that we already handle
                for sub_child in child.children:
                    result.append(sub_child.get_formatted_text(context))
                result.append("\n")
            result.append(child.get_formatted_text(context))
        result.append("\n")
        return "".join(result)

_properties class-attribute instance-attribute

_properties = (
    PropDef("name", "draw:name"),
    PropDef("draw_id", "draw:id"),
    PropDef("master_page", "draw:master-page-name"),
    PropDef(
        "presentation_page_layout",
        "presentation:presentation-page-layout-name",
    ),
    PropDef("style", "draw:style-name"),
)

_tag class-attribute instance-attribute

_tag = 'draw:page'

draw_id instance-attribute

draw_id = draw_id

master_page instance-attribute

master_page = master_page

name instance-attribute

name = name

presentation_page_layout instance-attribute

presentation_page_layout = presentation_page_layout

style instance-attribute

style = style

__init__

__init__(
    draw_id: str | None = None,
    name: str | None = None,
    master_page: str | None = None,
    presentation_page_layout: str | None = None,
    style: str | None = None,
    **kwargs: Any,
) -> None

Initialize the DrawPage.

Parameters:

Name Type Description Default
draw_id str | None

The ID of the draw page (‘draw:id’).

None
name str | None

The name of the draw page (‘draw:name’).

None
master_page str | None

The name of the master page to use (‘draw:master-page-name’).

None
presentation_page_layout str | None

The name of the presentation page layout to use (‘presentation:presentation-page-layout-name’).

None
style str | None

The name of the style to apply to the page (‘draw:style-name’).

None
**kwargs Any

Additional keyword arguments for the parent Element class.

{}
Source code in odfdo/draw_page.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def __init__(
    self,
    draw_id: str | None = None,
    name: str | None = None,
    master_page: str | None = None,
    presentation_page_layout: str | None = None,
    style: str | None = None,
    **kwargs: Any,
) -> None:
    """Initialize the DrawPage.

    Args:
        draw_id: The ID of the draw page ('draw:id').
        name: The name of the draw page ('draw:name').
        master_page: The name of the master page to use
            ('draw:master-page-name').
        presentation_page_layout: The name of the
            presentation page layout to use
            ('presentation:presentation-page-layout-name').
        style: The name of the style to apply to the page
            ('draw:style-name').
        **kwargs: Additional keyword arguments for the parent `Element` class.
    """
    super().__init__(**kwargs)
    if self._do_init:
        if draw_id:
            self.draw_id = draw_id
        if name:
            self.name = name
        if master_page:
            self.master_page = master_page
        if presentation_page_layout:
            self.presentation_page_layout = presentation_page_layout
        if style:
            self.style = style

get_formatted_text

get_formatted_text(context: dict | None = None) -> str

Return a formatted string representation of the page’s content.

This method recursively formats the text of all child elements, including presentation notes.

Parameters:

Name Type Description Default
context dict | None

A dictionary providing context for formatting, such as footnote or annotation tracking.

None

Returns:

Name Type Description
str str

A formatted string of the page’s textual content.

Source code in odfdo/draw_page.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
def get_formatted_text(self, context: dict | None = None) -> str:
    """Return a formatted string representation of the page's content.

    This method recursively formats the text of all child elements,
    including presentation notes.

    Args:
        context: A dictionary providing context for formatting,
            such as footnote or annotation tracking.

    Returns:
        str: A formatted string of the page's textual content.
    """
    result: list[str] = []
    for child in self.children:
        if child.tag == "presentation:notes":
            # No need for an advanced odf_notes.get_formatted_text()
            # because the text seems to be only contained in paragraphs
            # and frames, that we already handle
            for sub_child in child.children:
                result.append(sub_child.get_formatted_text(context))
            result.append("\n")
        result.append(child.get_formatted_text(context))
    result.append("\n")
    return "".join(result)

get_shapes

get_shapes() -> list[Element]

Get all shape elements within the page.

This includes all registered shapes such as lines, rectangles, ellipses, and connectors.

Returns:

Type Description
list[Element]

list[Element]: A list of all shape elements found on the page.

Source code in odfdo/draw_page.py
128
129
130
131
132
133
134
135
136
137
138
def get_shapes(self) -> list[Element]:
    """Get all shape elements within the page.

    This includes all registered shapes such as lines, rectangles,
    ellipses, and connectors.

    Returns:
        list[Element]: A list of all shape elements found on the page.
    """
    query = "(descendant::" + "|descendant::".join(registered_shapes) + ")"
    return self.get_elements(query)

get_transition

get_transition() -> AnimPar | None

Get the animation transition element for the page.

Returns:

Type Description
AnimPar | None

AnimPar | None: The animation transition element (anim:par), or None if no transition is defined.

Source code in odfdo/draw_page.py
84
85
86
87
88
89
90
91
def get_transition(self) -> AnimPar | None:
    """Get the animation transition element for the page.

    Returns:
        AnimPar | None: The animation transition element (`anim:par`),
            or `None` if no transition is defined.
    """
    return self.get_element("anim:par")  # type: ignore

set_transition

set_transition(
    smil_type: str,
    subtype: str | None = None,
    dur: str = "2s",
    node_type: str = "default",
) -> None

Set or replace the animation transition for the page.

This method creates a new animation transition (anim:par element) and replaces any existing transition on the page.

Parameters:

Name Type Description Default
smil_type str

The SMIL type for the transition (e.g., “fade”).

required
subtype str | None

The SMIL subtype for the transition.

None
dur str

The duration of the transition (e.g., “2s”).

'2s'
node_type str

The presentation node type.

'default'
Source code in odfdo/draw_page.py
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
def set_transition(
    self,
    smil_type: str,
    subtype: str | None = None,
    dur: str = "2s",
    node_type: str = "default",
) -> None:
    """Set or replace the animation transition for the page.

    This method creates a new animation transition (`anim:par` element)
    and replaces any existing transition on the page.

    Args:
        smil_type: The SMIL type for the transition (e.g., "fade").
        subtype: The SMIL subtype for the transition.
        dur: The duration of the transition (e.g., "2s").
        node_type: The presentation node type.
    """
    # Create the new animation
    anim_page = AnimPar(presentation_node_type=node_type)
    anim_begin = AnimPar(smil_begin=f"{self.draw_id}.begin")
    transition = AnimTransFilter(
        smil_dur=dur, smil_type=smil_type, smil_subtype=subtype
    )
    anim_page.append(anim_begin)
    anim_begin.append(transition)
    # Replace when already a transition:
    #   anim:seq => After the frame's transition
    #   cf page 349 of OpenDocument-v1.0-os.pdf
    #   Conclusion: We must delete the first child 'anim:par'
    previous_transition = self.get_transition()
    if previous_transition:
        self.delete(previous_transition)
    self.append(anim_page)