Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Slides.remove_slide(slide_id) #1029

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/pptx/oxml/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ def add_sldId(self, rId: str) -> CT_SlideId:
The new `p:sldId` element has its r:id attribute set to `rId`.
"""
return self._add_sldId(id=self._next_id, rId=rId)

def remove_sldId(self, slide_id: int) -> None:
"""Remove the `p:sldId` element with the specified slide ID."""
for sldId in self.sldId_lst:
if sldId.id == slide_id:
self.remove(sldId)
return
raise KeyError(f"no slide with id {slide_id}")

@property
def _next_id(self) -> int:
Expand Down
8 changes: 8 additions & 0 deletions src/pptx/parts/presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ def add_slide(self, slide_layout: SlideLayout):
rId = self.relate_to(slide_part, RT.SLIDE)
return rId, slide_part.slide

def remove_slide(self, slide_id: int):
"""Remove slide with `slide_id` from this presentation."""
for sldId in self._element.sldIdLst:
if sldId.id == slide_id:
self.drop_rel(sldId.rId)
return
raise KeyError("no slide with id %d" % slide_id)

@property
def core_properties(self) -> CorePropertiesPart:
"""A |CoreProperties| object for the presentation.
Expand Down
5 changes: 5 additions & 0 deletions src/pptx/slide.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ def add_slide(self, slide_layout: SlideLayout) -> Slide:
self._sldIdLst.add_sldId(rId)
return slide

def remove_slide(self, slide_id: int) -> None:
"""Remove slide with `slide_id` from this presentation."""
self.part.remove_slide(slide_id)
self._sldIdLst.remove_sldId(slide_id)

def get(self, slide_id: int, default: Slide | None = None) -> Slide | None:
"""Return the slide identified by int `slide_id` in this presentation.

Expand Down