MCPcopy Create free account
hub / github.com/scanny/python-pptx / CT_Slide

Class CT_Slide

src/pptx/oxml/slide.py:159–251  ·  view source on GitHub ↗

`p:sld` element, root element of a slide part (XML document).

Source from the content-addressed store, hash-verified

157
158
159class CT_Slide(_BaseSlideElement):
160 """`p:sld` element, root element of a slide part (XML document)."""
161
162 _tag_seq = ("p:cSld", "p:clrMapOvr", "p:transition", "p:timing", "p:extLst")
163 cSld: CT_CommonSlideData = OneAndOnlyOne("p:cSld") # pyright: ignore[reportAssignmentType]
164 clrMapOvr = ZeroOrOne("p:clrMapOvr", successors=_tag_seq[2:])
165 timing = ZeroOrOne("p:timing", successors=_tag_seq[4:])
166 del _tag_seq
167
168 @classmethod
169 def new(cls) -> CT_Slide:
170 """Return new `p:sld` element configured as base slide shape."""
171 return cast(CT_Slide, parse_xml(cls._sld_xml()))
172
173 @property
174 def bg(self):
175 """Return `p:bg` grandchild or None if not present."""
176 return self.cSld.bg
177
178 def get_or_add_childTnLst(self):
179 """Return parent element for a new `p:video` child element.
180
181 The `p:video` element causes play controls to appear under a video
182 shape (pic shape containing video). There can be more than one video
183 shape on a slide, which causes the precondition to vary. It needs to
184 handle the case when there is no `p:sld/p:timing` element and when
185 that element already exists. If the case isn't simple, it just nukes
186 what's there and adds a fresh one. This could theoretically remove
187 desired existing timing information, but there isn't any evidence
188 available to me one way or the other, so I've taken the simple
189 approach.
190 """
191 childTnLst = self._childTnLst
192 if childTnLst is None:
193 childTnLst = self._add_childTnLst()
194 return childTnLst
195
196 def _add_childTnLst(self):
197 """Add `./p:timing/p:tnLst/p:par/p:cTn/p:childTnLst` descendant.
198
199 Any existing `p:timing` child element is ruthlessly removed and
200 replaced.
201 """
202 self.remove(self.get_or_add_timing())
203 timing = parse_xml(self._childTnLst_timing_xml())
204 self._insert_timing(timing)
205 return timing.xpath("./p:tnLst/p:par/p:cTn/p:childTnLst")[0]
206
207 @property
208 def _childTnLst(self):
209 """Return `./p:timing/p:tnLst/p:par/p:cTn/p:childTnLst` descendant.
210
211 Return None if that element is not present.
212 """
213 childTnLsts = self.xpath("./p:timing/p:tnLst/p:par/p:cTn/p:childTnLst")
214 if not childTnLsts:
215 return None
216 return childTnLsts[0]

Callers

nothing calls this directly

Calls 2

OneAndOnlyOneClass · 0.90
ZeroOrOneClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…