`p:txBody` custom element class. Also used for `c:txPr` in charts and perhaps other elements.
| 77 | |
| 78 | |
| 79 | class CT_TextBody(BaseOxmlElement): |
| 80 | """`p:txBody` custom element class. |
| 81 | |
| 82 | Also used for `c:txPr` in charts and perhaps other elements. |
| 83 | """ |
| 84 | |
| 85 | add_p: Callable[[], CT_TextParagraph] |
| 86 | p_lst: list[CT_TextParagraph] |
| 87 | |
| 88 | bodyPr: CT_TextBodyProperties = OneAndOnlyOne( # pyright: ignore[reportAssignmentType] |
| 89 | "a:bodyPr" |
| 90 | ) |
| 91 | p: CT_TextParagraph = OneOrMore("a:p") # pyright: ignore[reportAssignmentType] |
| 92 | |
| 93 | def clear_content(self): |
| 94 | """Remove all `a:p` children, but leave any others. |
| 95 | |
| 96 | cf. lxml `_Element.clear()` method which removes all children. |
| 97 | """ |
| 98 | for p in self.p_lst: |
| 99 | self.remove(p) |
| 100 | |
| 101 | @property |
| 102 | def defRPr(self) -> CT_TextCharacterProperties: |
| 103 | """`a:defRPr` element of required first `p` child, added with its ancestors if not present. |
| 104 | |
| 105 | Used when element is a ``c:txPr`` in a chart and the `p` element is used only to specify |
| 106 | formatting, not content. |
| 107 | """ |
| 108 | p = self.p_lst[0] |
| 109 | pPr = p.get_or_add_pPr() |
| 110 | defRPr = pPr.get_or_add_defRPr() |
| 111 | return defRPr |
| 112 | |
| 113 | @property |
| 114 | def is_empty(self) -> bool: |
| 115 | """True if only a single empty `a:p` element is present.""" |
| 116 | ps = self.p_lst |
| 117 | if len(ps) > 1: |
| 118 | return False |
| 119 | |
| 120 | if not ps: |
| 121 | raise InvalidXmlError("p:txBody must have at least one a:p") |
| 122 | |
| 123 | if ps[0].text != "": |
| 124 | return False |
| 125 | return True |
| 126 | |
| 127 | @classmethod |
| 128 | def new(cls): |
| 129 | """Return a new `p:txBody` element tree.""" |
| 130 | xml = cls._txBody_tmpl() |
| 131 | txBody = parse_xml(xml) |
| 132 | return txBody |
| 133 | |
| 134 | @classmethod |
| 135 | def new_a_txBody(cls) -> CT_TextBody: |
| 136 | """Return a new `a:txBody` element tree. |
nothing calls this directly
no test coverage detected
searching dependent graphs…