support adding slide_layout - #1091
Open
wkpark wants to merge 2 commits into
Open
Conversation
9 tasks
lofcz
added a commit
to lofcz/python-pptx2
that referenced
this pull request
Aug 30, 2026
SlideLayouts.add_layout(name="Layout %s") appends a blank layout to a slide master, and SlideLayouts.clone(layout) deep-copies an existing layout of the same presentation under a non-colliding name. Both are usable with prs.slides.add_slide(), register a fresh presentation- unique p:sldLayoutId (max+1 over 2147483648), and pair with LayoutShapes.add_placeholder(), whose idx defaults to the matching master placeholder so inheritance and shapes.title keep working. The clone path reuses the _slide_importer utilities (_clone_xml_part, _remap_rids, and next_layout_hierarchy_id, extracted from _SlideImporter._next_hierarchy_id) so images and external links a layout refers to survive with remapped rIds. Port of scanny#1091 by wkpark.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP
This is merely one example.
It does not function perfectly, and only some features work as intended.
Nevertheless, if you are planning to add or edit
slide layouts, please refer to this.#1044 - apply this suggestion into this PR.
examples
... prs = Presentation() ph_list = [ PP_PLACEHOLDER.TITLE, PP_PLACEHOLDER.CENTER_TITLE PP_PLACEHOLDER.SUBTITLE, PP_PLACEHOLDER.BODY, ] ... layout= prs.slide_layouts.add_layout("My Layout %s") ... ph = layout.shapes.add_placeholder(PP_PLACEHOLDER.TITLE, "horz", "full") ph.text = "insert Title here" ...