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

Feature Request: support applying saved theme to individual slides? #146

Closed
linzhong opened this issue Feb 20, 2015 · 6 comments
Closed

Comments

@linzhong
Copy link

No description provided.

@scanny
Copy link
Owner

scanny commented Feb 20, 2015

Hi @linzhong, can you describe your use case for us?

@linzhong
Copy link
Author

Sure,

I would like to create a powerpoint file using your libraray. We have some
format themes already defined, so instead of recreate all the format in the
code, I would like to apply the corresponding theme settings to the slides
that I produce. (Just like in the powerpoint application, choose the
corresponding theme and apply to the selected slide)

Ideally, I would like to be able to create some template slides and just
insert certain data into the slide templates, I don't see this is supported
from what I learned in the document so far. The template support may be too
much to ask. But if I can apply the theme to the generated slides, it will
work in my scenario as well.

Thanks,
Lin

On Fri, Feb 20, 2015 at 1:49 PM, Steve Canny notifications@github.com
wrote:

Hi @linzhong https://github.com/linzhong, can you describe your use
case for us?


Reply to this email directly or view it on GitHub
#146 (comment).

*Lin Zhong *


Applause gets ​​Three Straight Years as one of Forbes’ Most Promising
Companies http://www.applause.com/awards

@scanny
Copy link
Owner

scanny commented Feb 21, 2015

As far as the themes go, the approach would be to create a starting .pptx file, a "template" of sorts, that you use as the starting point for the presentation you generate.
http://python-pptx.readthedocs.org/en/latest/user/presentations.html

In that starting .pptx file you would include your customized themes. You can do this by creating a presentation that uses all the themes you would like to have available and then deleting all the slides (but not the slide masters or slide layouts). You will be left with an empty presentation having multiple slide masters, each of which has its own set of slide layouts.

Then you pick the particular layout you want to generate each slide, perhaps something like this:

from pptx import Presentation
prs = Presentation('my-template.pptx')
slide_layout = prs.slide_masters[2].slide_layouts[3]
slide = prs.slides.add_slide(slide_layout)

You'll need to know in advance what the (master_idx, layout_idx) combination is to get the theme/layout combination you're after as they are only accessible by index at the moment.

Does that give you what you need?

@linzhong
Copy link
Author

Thanks a lot, Steve.

This indeed serve the need, I read the page you refer to earlier and knew
that I can open existing slide. But I didn't realize that I can retrieve
the layout of existing one to create the new one. Thanks a lot for pointing
it out. This is great! :)

Lin

On Fri, Feb 20, 2015 at 4:03 PM, Steve Canny notifications@github.com
wrote:

As far as the themes go, the approach would be to create a starting .pptx
file, a "template" of sorts, that you use as the starting point for the
presentation you generate.
http://python-pptx.readthedocs.org/en/latest/user/presentations.html

In that starting .pptx file you would include your customized themes. You
can do this by creating a presentation that uses all the themes you would
like to have available and then deleting all the slides (but not the slide
masters or slide layouts). You will be left with an empty presentation
having multiple slide masters, each of which has its own set of slide
layouts.

Then you pick the particular layout you want to generate each slide,
perhaps something like this:

from pptx import Presentation
prs = Presentation('my-template.pptx')
slide_layout = prs.slide_masters[2].slide_layouts[3]
slide = prs.slides.add_slide(slide_layout)

You'll need to know in advance what the (master_idx, layout_idx)
combination is to get the theme/layout combination you're after as they are
only accessible by index at the moment.

Does that give you what you need?


Reply to this email directly or view it on GitHub
#146 (comment).

*Lin Zhong *


Applause gets ​​Three Straight Years as one of Forbes’ Most Promising
Companies http://www.applause.com/awards

@scanny
Copy link
Owner

scanny commented Feb 24, 2015

Yes. The key thing here is what slide masters and slide layouts you have available to you at run time.

When you add the slides having a different theme, their slide master and slide layouts are automatically added to the file too. You just don't see them unless you go looking for them in the Slide Master view. Once that's done, you get rid of the slides you added so you can start with an empty presentation. Deleting the slides does not remove the new masters and layouts. Once they're in they're there to stay unless you delete them manually. All this is done "by hand" using PowerPoint, just to get your template file configured correctly.

There are other ways to do it--any method that gets the masters and layouts in there is fine--but this way is probably the quickest.

What you're really looking for is how the starting presentation looks in Slide Master view. In regular Slide view mode, it should be empty when you're done. Slide Master view is also where you can figure out what the index of a particular master or layout is; just remember to start counting at 0 instead of 1.

Note there is at least one other part involved, the theme{n}.xml files. Those specify the palette and fonts used by the master and layouts for that theme, and perhaps a few other details. Those get added automatically by this process. I just mention them here for anyone who might take a more direct approach :)

@scanny scanny closed this as completed Feb 24, 2015
@linzhong
Copy link
Author

This are awesome tips. Thanks!

On Mon, Feb 23, 2015 at 4:34 PM, Steve Canny notifications@github.com
wrote:

Yes. The key thing here is what slide masters and slide layouts you have
available to you at run time.

When you add the slides having a different theme, their slide master and
slide layouts are automatically added to the file too. You just don't see
them unless you go looking for them in the Slide Master view. Once that's
done, you get rid of the slides you added so you can start with an empty
presentation. Deleting the slides does not remove the new masters and
layouts. Once they're in they're there to stay unless you delete them
manually. All this is done "by hand" using PowerPoint, just to get your
template file configured correctly.

There are other ways to do it--any method that gets the masters and
layouts in there is fine--but this way is probably the quickest.

What you're really looking for is how the starting presentation looks in
Slide Master view. In regular Slide view mode, it should be empty when
you're done. Slide Master view is also where you can figure out what the
index of a particular master or layout is; just remember to start counting
at 0 instead of 1.

Note there is at least one other part involved, the theme{n}.xml files.
Those specify the palette and fonts used by the master and layouts for that
theme, and perhaps a few other details. Those get added automatically by
this process. I just mention them here for anyone who might take a more
direct approach :)


Reply to this email directly or view it on GitHub
#146 (comment).

*Lin Zhong *


Applause gets ​​Three Straight Years as one of Forbes’ Most Promising
Companies http://www.applause.com/awards

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

No branches or pull requests

2 participants