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

Method remove

src/pptx/slide.py:390–411  ·  view source on GitHub ↗

Remove `slide_layout` from the collection. Raises ValueError when `slide_layout` is in use; a slide layout which is the basis for one or more slides cannot be removed.

(self, slide_layout: SlideLayout)

Source from the content-addressed store, hash-verified

388 raise ValueError("layout not in this SlideLayouts collection")
389
390 def remove(self, slide_layout: SlideLayout) -> None:
391 """Remove `slide_layout` from the collection.
392
393 Raises ValueError when `slide_layout` is in use; a slide layout which is the basis for one
394 or more slides cannot be removed.
395 """
396 # ---raise if layout is in use---
397 if slide_layout.used_by_slides:
398 raise ValueError("cannot remove slide-layout in use by one or more slides")
399
400 # ---target layout is identified by its index in this collection---
401 target_idx = self.index(slide_layout)
402
403 # --remove layout from p:sldLayoutIds of its master
404 # --this stops layout from showing up, but doesn't remove it from package
405 target_sldLayoutId = self._sldLayoutIdLst.sldLayoutId_lst[target_idx]
406 self._sldLayoutIdLst.remove(target_sldLayoutId)
407
408 # --drop relationship from master to layout
409 # --this removes layout from package, along with everything (only) it refers to,
410 # --including images (not used elsewhere) and hyperlinks
411 slide_layout.slide_master.part.drop_rel(target_sldLayoutId.rId)
412
413
414class SlideMaster(_BaseMaster):

Calls 2

indexMethod · 0.95
drop_relMethod · 0.45