Turn slide layouts names to attributes#292
Conversation
This will add slide layouts names as attributes to `SlideLayouts` instance.
All layouts names will be converted to CamelCase without spaces.
If the converted name is a valid identifier and is not used already by `slide_layouts` instance it will be assigned as an attribute to `slide_layouts`.
Also all available layouts will be available (as seen in PowerPoint) as a list accessible with attribute `slide_layouts.available_layouts`
After that - using available layouts is as easy as accessing any other attribute.
For example with the standard template available with `pptx`:
pres = Presentation()
print(pres.slide_layouts.available_layouts)
Will produce:
['Title Slide', 'Title and Content', 'Section Header', 'Two Content', 'Comparison', 'Title Only', 'Blank', 'Content with Caption', 'Picture with Caption', 'Title and Vertical Text', 'Vertical Title and Text']
And using `Title Slide` is then as easy as:
pres.slide_layouts.TitleSlide
Turn slide layouts names to attributes
Fix name should be string error
|
Currently tests partially fail due to absence of |
|
Hi wikiped, unfortunately we're not going to merge this feature, although anyone interested in it is welcome to pick it up from here. In general, we advise being in touch before starting work on a new feature, to make sure the proposed feature is consistent with the existing API and so forth. This saves situations like this where we have to decline to merge and can yield a somewhat different approach that produces a mergeable feature. In this case, we might be interested in a feature that allows getting a layout by name, but not by using that name as an attribute (dotted notation). The layout names are completely free-form, so there's no inherent consistency between layout names from one presentation to the next. |
|
Thanks for the feedback. Any way, name based access was the next thing on my wish-list and I hope suggested implementation will be acceptable. |
…e_layouts['Layout Name']) and as attribute (e.g. slide_layouts.LayoutName)
|
Note that all submissions must include tests and documentation as a prerequisite to merging. Best practice is to start with an enhancement proposal (analysis page) like this one: This minimizes the amount of changes required to qualify for merge, saving committer (my) time. |
where idx can be either index or name of placeholder. added placeholders.ids_names property to return tuples of (idx, placeholder_name) This access applies to both slide_layout.placeholders and slide.placeholders.
# Conflicts: # HISTORY.rst # docs/dev/analysis/index.rst # features/shp-shapes-methods.feature # features/steps/shape.py # features/steps/test_files/just-two-mice.mp4 # pptx/__init__.py # pptx/shapes/placeholder.py # pptx/shapes/shapetree.py # tests/shapes/test_shapetree.py
# Conflicts: # pptx/slide.py
# Conflicts: # pptx/oxml/shapes/picture.py # pptx/shapes/shapetree.py
This will add slide layouts names as attributes to
SlideLayoutsinstance.All layouts names will be converted to CamelCase without spaces.
If the converted name is a valid identifier and is not used already by
slide_layoutsinstance it will be assigned as an attribute toslide_layouts.Also all available layouts will be available (as seen in PowerPoint) as a list accessible with attribute
slide_layouts.available_layoutsAfter that - using available layouts is as easy as accessing any other attribute.
For example with the standard template available with
pptx:Will produce:
And using
Title Slideis then as easy as: