Skip to content
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
9 changes: 9 additions & 0 deletions docs/api/placeholders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,12 @@ _PlaceholderFormat objects
:members:
:inherited-members:
:undoc-members:


ContentPlaceholder objects
------------------------

.. autoclass:: pptx.shapes.placeholder.ContentPlaceholder()
:members:
:inherited-members:
:undoc-members:
28 changes: 28 additions & 0 deletions features/ph-insert-shape.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ Feature: Insert a shape into a placeholder
| monty-truth.png | top and bottom | 0.23715 |
| python-powered.png | left and right | 0.23333 |

Scenario Outline: Insert an image into an content placeholder
Given an unpopulated content placeholder shape
When I call placeholder.insert_picture('<filename>')
Then the return value is a PlaceholderPicture object
And the placeholder contains the image
And the <sides> crop is <value>

Examples: Images inserted into a picture placeholder
| filename | sides | value |
| monty-truth.png | top and bottom | 0.23715 |
| python-powered.png | left and right | 0.23333 |


Scenario: Insert a table into a table placeholder
Given an unpopulated table placeholder shape
Expand All @@ -25,9 +37,25 @@ Feature: Insert a shape into a placeholder
And the table has 2 rows and 3 columns


Scenario: Insert a table into a content placeholder
Given an unpopulated content placeholder shape
When I call placeholder.insert_table(rows=2, cols=3)
Then the return value is a PlaceholderGraphicFrame object
And the placeholder contains the table
And the table has 2 rows and 3 columns


Scenario: Insert a chart into a chart placeholder
Given an unpopulated chart placeholder shape
When I call placeholder.insert_chart(XL_CHART_TYPE.PIE, chart_data)
Then the return value is a PlaceholderGraphicFrame object
And the placeholder contains the chart
And the chart is a pie chart


Scenario: Insert a chart into a content placeholder
Given an unpopulated content placeholder shape
When I call placeholder.insert_chart(XL_CHART_TYPE.PIE, chart_data)
Then the return value is a PlaceholderGraphicFrame object
And the placeholder contains the chart
And the chart is a pie chart
4 changes: 2 additions & 2 deletions features/shp-shapes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ Feature: Access a shape on a slide
Scenario: SlidePlaceholders is a sequence
Given a SlidePlaceholders object of length 2 as shapes
Then len(shapes) == 2
And shapes[10] is a SlidePlaceholder object
And iterating shapes produces 2 objects of type SlidePlaceholder
And shapes[0] is a SlidePlaceholder object
And shapes[10] is a ContentPlaceholder object


Scenario Outline: Access unpopulated placeholder shape
Expand Down
9 changes: 8 additions & 1 deletion pptx/shapes/placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def _base_placeholder(self):

class TablePlaceholder(_BaseSlidePlaceholder):
"""
Placeholder shape that can only accept a picture.
Placeholder shape that can only accept a table.
"""

def insert_table(self, rows, cols):
Expand Down Expand Up @@ -412,3 +412,10 @@ def _new_placeholder_table(self, rows, cols):
return CT_GraphicalObjectFrame.new_table_graphicFrame(
shape_id, name, rows, cols, self.left, self.top, self.width, height
)


class ContentPlaceholder(SlidePlaceholder, ChartPlaceholder, PicturePlaceholder, TablePlaceholder):
"""
Placeholder shape that accept all objects.
"""

2 changes: 2 additions & 0 deletions pptx/shapes/shapetree.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
PlaceholderPicture,
SlidePlaceholder,
TablePlaceholder,
ContentPlaceholder
)
from pptx.shared import ParentedElementProxy
from pptx.util import lazyproperty
Expand Down Expand Up @@ -811,6 +812,7 @@ def _SlidePlaceholderFactory(shape_elm, parent):
PP_PLACEHOLDER.CHART: ChartPlaceholder,
PP_PLACEHOLDER.PICTURE: PicturePlaceholder,
PP_PLACEHOLDER.TABLE: TablePlaceholder,
PP_PLACEHOLDER.OBJECT: ContentPlaceholder
}.get(shape_elm.ph_type, SlidePlaceholder)
elif tag == qn("p:graphicFrame"):
Constructor = PlaceholderGraphicFrame
Expand Down
1 change: 1 addition & 0 deletions tests/shapes/test_placeholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
PlaceholderGraphicFrame,
PlaceholderPicture,
TablePlaceholder,
ContentPlaceholder
)
from pptx.shapes.shapetree import NotesSlidePlaceholders
from pptx.slide import NotesMaster, SlideLayout, SlideMaster
Expand Down