Skip to content

Turn slide layouts names to attributes#292

Open
wikiped wants to merge 22 commits into
scanny:masterfrom
wikiped:master
Open

Turn slide layouts names to attributes#292
wikiped wants to merge 22 commits into
scanny:masterfrom
wikiped:master

Conversation

@wikiped
Copy link
Copy Markdown

@wikiped wikiped commented May 27, 2017

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

wikiped and others added 6 commits May 26, 2017 19:20
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
@wikiped
Copy link
Copy Markdown
Author

wikiped commented May 27, 2017

Currently tests partially fail due to absence of isidentifier method in 2.6-2.7. This is relatively easy to fix if the proposed change (layout_names to attributes) is acceptable.

@scanny
Copy link
Copy Markdown
Owner

scanny commented May 27, 2017

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.

@wikiped
Copy link
Copy Markdown
Author

wikiped commented May 28, 2017

Thanks for the feedback.
I understand reluctance to have dot based access to slide layouts, although do not share the view that their free form should be preventing from enabling this access where possible (like this is done on other libraries where there are dynamically generated attributes, e.g. pandas).

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)
@scanny
Copy link
Copy Markdown
Owner

scanny commented May 28, 2017

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:
https://github.com/scanny/python-pptx/blob/master/docs/dev/analysis/sld-notes-slide.rst

This minimizes the amount of changes required to qualify for merge, saving committer (my) time.

wikiped added 14 commits May 29, 2017 10:36
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/oxml/shapes/picture.py
#	pptx/shapes/shapetree.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants