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

Class Slides

src/pptx/slide.py:238–293  ·  view source on GitHub ↗

Sequence of slides belonging to an instance of |Presentation|. Has list semantics for access to individual slides. Supports indexed access, len(), and iteration.

Source from the content-addressed store, hash-verified

236
237
238class Slides(ParentedElementProxy):
239 """Sequence of slides belonging to an instance of |Presentation|.
240
241 Has list semantics for access to individual slides. Supports indexed access, len(), and
242 iteration.
243 """
244
245 part: PresentationPart # pyright: ignore[reportIncompatibleMethodOverride]
246
247 def __init__(self, sldIdLst: CT_SlideIdList, prs: Presentation):
248 super(Slides, self).__init__(sldIdLst, prs)
249 self._sldIdLst = sldIdLst
250
251 def __getitem__(self, idx: int) -> Slide:
252 """Provide indexed access, (e.g. 'slides[0]')."""
253 try:
254 sldId = self._sldIdLst.sldId_lst[idx]
255 except IndexError:
256 raise IndexError("slide index out of range")
257 return self.part.related_slide(sldId.rId)
258
259 def __iter__(self) -> Iterator[Slide]:
260 """Support iteration, e.g. `for slide in slides:`."""
261 for sldId in self._sldIdLst.sldId_lst:
262 yield self.part.related_slide(sldId.rId)
263
264 def __len__(self) -> int:
265 """Support len() built-in function, e.g. `len(slides) == 4`."""
266 return len(self._sldIdLst)
267
268 def add_slide(self, slide_layout: SlideLayout) -> Slide:
269 """Return a newly added slide that inherits layout from `slide_layout`."""
270 rId, slide = self.part.add_slide(slide_layout)
271 slide.shapes.clone_layout_placeholders(slide_layout)
272 self._sldIdLst.add_sldId(rId)
273 return slide
274
275 def get(self, slide_id: int, default: Slide | None = None) -> Slide | None:
276 """Return the slide identified by int `slide_id` in this presentation.
277
278 Returns `default` if not found.
279 """
280 slide = self.part.get_slide(slide_id)
281 if slide is None:
282 return default
283 return slide
284
285 def index(self, slide: Slide) -> int:
286 """Map `slide` to its zero-based position in this slide sequence.
287
288 Raises |ValueError| on *slide* not present.
289 """
290 for idx, this_slide in enumerate(self):
291 if this_slide == slide:
292 return idx
293 raise ValueError("%s is not in slide collection" % slide)
294
295

Callers 9

slidesMethod · 0.90
add_fixtureMethod · 0.90
get_fixtureMethod · 0.90
getitem_fixtureMethod · 0.90
index_fixtureMethod · 0.90
iter_fixtureMethod · 0.90
len_fixtureMethod · 0.90
raises_fixtureMethod · 0.90

Calls

no outgoing calls

Tested by 8

add_fixtureMethod · 0.72
get_fixtureMethod · 0.72
getitem_fixtureMethod · 0.72
index_fixtureMethod · 0.72
iter_fixtureMethod · 0.72
len_fixtureMethod · 0.72
raises_fixtureMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…