code
stringlengths 66
870k
| docstring
stringlengths 19
26.7k
| func_name
stringlengths 1
138
| language
stringclasses 1
value | repo
stringlengths 7
68
| path
stringlengths 5
324
| url
stringlengths 46
389
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def table(self) -> Table:
"""The |Table| object contained in this graphic frame.
Raises |ValueError| if this graphic frame does not contain a table.
"""
if not self.has_table:
raise ValueError("shape does not contain a table")
tbl = self._graphicFrame.graphic.graphicData.tbl
return Table(tbl, self)
|
The |Table| object contained in this graphic frame.
Raises |ValueError| if this graphic frame does not contain a table.
|
table
|
python
|
scanny/python-pptx
|
src/pptx/shapes/graphfrm.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/graphfrm.py
|
MIT
|
def blob(self) -> bytes | None:
"""Optional bytes of OLE object, suitable for loading or saving as a file.
This value is `None` if the embedded object does not represent a "file".
"""
blob_rId = self._graphicData.blob_rId
if blob_rId is None:
return None
return self.part.related_part(blob_rId).blob
|
Optional bytes of OLE object, suitable for loading or saving as a file.
This value is `None` if the embedded object does not represent a "file".
|
blob
|
python
|
scanny/python-pptx
|
src/pptx/shapes/graphfrm.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/graphfrm.py
|
MIT
|
def shapes(self) -> GroupShapes:
"""|GroupShapes| object for this group.
The |GroupShapes| object provides access to the group's member shapes and provides methods
for adding new ones.
"""
from pptx.shapes.shapetree import GroupShapes
return GroupShapes(self._element, self)
|
|GroupShapes| object for this group.
The |GroupShapes| object provides access to the group's member shapes and provides methods
for adding new ones.
|
shapes
|
python
|
scanny/python-pptx
|
src/pptx/shapes/group.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/group.py
|
MIT
|
def poster_frame(self):
"""Return |Image| object containing poster frame for this movie.
Returns |None| if this movie has no poster frame (uncommon).
"""
slide_part, rId = self.part, self._pic.blip_rId
if rId is None:
return None
return slide_part.get_image(rId)
|
Return |Image| object containing poster frame for this movie.
Returns |None| if this movie has no poster frame (uncommon).
|
poster_frame
|
python
|
scanny/python-pptx
|
src/pptx/shapes/picture.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/picture.py
|
MIT
|
def auto_shape_type(self) -> MSO_SHAPE | None:
"""Member of MSO_SHAPE indicating masking shape.
A picture can be masked by any of the so-called "auto-shapes" available in PowerPoint,
such as an ellipse or triangle. When a picture is masked by a shape, the shape assumes the
same dimensions as the picture and the portion of the picture outside the shape boundaries
does not appear. Note the default value for a newly-inserted picture is
`MSO_AUTO_SHAPE_TYPE.RECTANGLE`, which performs no cropping because the extents of the
rectangle exactly correspond to the extents of the picture.
The available shapes correspond to the members of :ref:`MsoAutoShapeType`.
The return value can also be |None|, indicating the picture either has no geometry (not
expected) or has custom geometry, like a freeform shape. A picture with no geometry will
have no visible representation on the slide, although it can be selected. This is because
without geometry, there is no "inside-the-shape" for it to appear in.
"""
prstGeom = self._pic.spPr.prstGeom
if prstGeom is None: # ---generally means cropped with freeform---
return None
return prstGeom.prst
|
Member of MSO_SHAPE indicating masking shape.
A picture can be masked by any of the so-called "auto-shapes" available in PowerPoint,
such as an ellipse or triangle. When a picture is masked by a shape, the shape assumes the
same dimensions as the picture and the portion of the picture outside the shape boundaries
does not appear. Note the default value for a newly-inserted picture is
`MSO_AUTO_SHAPE_TYPE.RECTANGLE`, which performs no cropping because the extents of the
rectangle exactly correspond to the extents of the picture.
The available shapes correspond to the members of :ref:`MsoAutoShapeType`.
The return value can also be |None|, indicating the picture either has no geometry (not
expected) or has custom geometry, like a freeform shape. A picture with no geometry will
have no visible representation on the slide, although it can be selected. This is because
without geometry, there is no "inside-the-shape" for it to appear in.
|
auto_shape_type
|
python
|
scanny/python-pptx
|
src/pptx/shapes/picture.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/picture.py
|
MIT
|
def image(self):
"""The |Image| object for this picture.
Provides access to the properties and bytes of the image in this picture shape.
"""
slide_part, rId = self.part, self._pic.blip_rId
if rId is None:
raise ValueError("no embedded image")
return slide_part.get_image(rId)
|
The |Image| object for this picture.
Provides access to the properties and bytes of the image in this picture shape.
|
image
|
python
|
scanny/python-pptx
|
src/pptx/shapes/picture.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/picture.py
|
MIT
|
def _effective_value(self, attr_name):
"""
The effective value of *attr_name* on this placeholder shape; its
directly-applied value if it has one, otherwise the value on the
layout placeholder it inherits from.
"""
directly_applied_value = getattr(super(_InheritsDimensions, self), attr_name)
if directly_applied_value is not None:
return directly_applied_value
return self._inherited_value(attr_name)
|
The effective value of *attr_name* on this placeholder shape; its
directly-applied value if it has one, otherwise the value on the
layout placeholder it inherits from.
|
_effective_value
|
python
|
scanny/python-pptx
|
src/pptx/shapes/placeholder.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/placeholder.py
|
MIT
|
def _inherited_value(self, attr_name):
"""
Return the attribute value, e.g. 'width' of the base placeholder this
placeholder inherits from.
"""
base_placeholder = self._base_placeholder
if base_placeholder is None:
return None
inherited_value = getattr(base_placeholder, attr_name)
return inherited_value
|
Return the attribute value, e.g. 'width' of the base placeholder this
placeholder inherits from.
|
_inherited_value
|
python
|
scanny/python-pptx
|
src/pptx/shapes/placeholder.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/placeholder.py
|
MIT
|
def _replace_placeholder_with(self, element):
"""
Substitute *element* for this placeholder element in the shapetree.
This placeholder's `._element` attribute is set to |None| and its
original element is free for garbage collection. Any attribute access
(including a method call) on this placeholder after this call raises
|AttributeError|.
"""
element._nvXxPr.nvPr._insert_ph(self._element.ph)
self._element.addprevious(element)
self._element.getparent().remove(self._element)
self._element = None
|
Substitute *element* for this placeholder element in the shapetree.
This placeholder's `._element` attribute is set to |None| and its
original element is free for garbage collection. Any attribute access
(including a method call) on this placeholder after this call raises
|AttributeError|.
|
_replace_placeholder_with
|
python
|
scanny/python-pptx
|
src/pptx/shapes/placeholder.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/placeholder.py
|
MIT
|
def _base_placeholder(self):
"""
Return the master placeholder this layout placeholder inherits from.
"""
base_ph_type = {
PP_PLACEHOLDER.BODY: PP_PLACEHOLDER.BODY,
PP_PLACEHOLDER.CHART: PP_PLACEHOLDER.BODY,
PP_PLACEHOLDER.BITMAP: PP_PLACEHOLDER.BODY,
PP_PLACEHOLDER.CENTER_TITLE: PP_PLACEHOLDER.TITLE,
PP_PLACEHOLDER.ORG_CHART: PP_PLACEHOLDER.BODY,
PP_PLACEHOLDER.DATE: PP_PLACEHOLDER.DATE,
PP_PLACEHOLDER.FOOTER: PP_PLACEHOLDER.FOOTER,
PP_PLACEHOLDER.MEDIA_CLIP: PP_PLACEHOLDER.BODY,
PP_PLACEHOLDER.OBJECT: PP_PLACEHOLDER.BODY,
PP_PLACEHOLDER.PICTURE: PP_PLACEHOLDER.BODY,
PP_PLACEHOLDER.SLIDE_NUMBER: PP_PLACEHOLDER.SLIDE_NUMBER,
PP_PLACEHOLDER.SUBTITLE: PP_PLACEHOLDER.BODY,
PP_PLACEHOLDER.TABLE: PP_PLACEHOLDER.BODY,
PP_PLACEHOLDER.TITLE: PP_PLACEHOLDER.TITLE,
}[self._element.ph_type]
slide_master = self.part.slide_master
return slide_master.placeholders.get(base_ph_type, None)
|
Return the master placeholder this layout placeholder inherits from.
|
_base_placeholder
|
python
|
scanny/python-pptx
|
src/pptx/shapes/placeholder.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/placeholder.py
|
MIT
|
def _base_placeholder(self):
"""
Return the notes master placeholder this notes slide placeholder
inherits from, or |None| if no placeholder of the matching type is
present.
"""
notes_master = self.part.notes_master
ph_type = self.element.ph_type
return notes_master.placeholders.get(ph_type=ph_type)
|
Return the notes master placeholder this notes slide placeholder
inherits from, or |None| if no placeholder of the matching type is
present.
|
_base_placeholder
|
python
|
scanny/python-pptx
|
src/pptx/shapes/placeholder.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/placeholder.py
|
MIT
|
def insert_chart(self, chart_type, chart_data):
"""
Return a |PlaceholderGraphicFrame| object containing a new chart of
*chart_type* depicting *chart_data* and having the same position and
size as this placeholder. *chart_type* is one of the
:ref:`XlChartType` enumeration values. *chart_data* is a |ChartData|
object populated with the categories and series values for the chart.
Note that the new |Chart| object is not returned directly. The chart
object may be accessed using the
:attr:`~.PlaceholderGraphicFrame.chart` property of the returned
|PlaceholderGraphicFrame| object.
"""
rId = self.part.add_chart_part(chart_type, chart_data)
graphicFrame = self._new_chart_graphicFrame(
rId, self.left, self.top, self.width, self.height
)
self._replace_placeholder_with(graphicFrame)
return PlaceholderGraphicFrame(graphicFrame, self._parent)
|
Return a |PlaceholderGraphicFrame| object containing a new chart of
*chart_type* depicting *chart_data* and having the same position and
size as this placeholder. *chart_type* is one of the
:ref:`XlChartType` enumeration values. *chart_data* is a |ChartData|
object populated with the categories and series values for the chart.
Note that the new |Chart| object is not returned directly. The chart
object may be accessed using the
:attr:`~.PlaceholderGraphicFrame.chart` property of the returned
|PlaceholderGraphicFrame| object.
|
insert_chart
|
python
|
scanny/python-pptx
|
src/pptx/shapes/placeholder.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/placeholder.py
|
MIT
|
def _new_chart_graphicFrame(self, rId, x, y, cx, cy):
"""
Return a newly created `p:graphicFrame` element having the specified
position and size and containing the chart identified by *rId*.
"""
id_, name = self.shape_id, self.name
return CT_GraphicalObjectFrame.new_chart_graphicFrame(id_, name, rId, x, y, cx, cy)
|
Return a newly created `p:graphicFrame` element having the specified
position and size and containing the chart identified by *rId*.
|
_new_chart_graphicFrame
|
python
|
scanny/python-pptx
|
src/pptx/shapes/placeholder.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/placeholder.py
|
MIT
|
def insert_picture(self, image_file):
"""Return a |PlaceholderPicture| object depicting the image in `image_file`.
`image_file` may be either a path (string) or a file-like object. The image is
cropped to fill the entire space of the placeholder. A |PlaceholderPicture|
object has all the properties and methods of a |Picture| shape except that the
value of its :attr:`~._BaseSlidePlaceholder.shape_type` property is
`MSO_SHAPE_TYPE.PLACEHOLDER` instead of `MSO_SHAPE_TYPE.PICTURE`.
"""
pic = self._new_placeholder_pic(image_file)
self._replace_placeholder_with(pic)
return PlaceholderPicture(pic, self._parent)
|
Return a |PlaceholderPicture| object depicting the image in `image_file`.
`image_file` may be either a path (string) or a file-like object. The image is
cropped to fill the entire space of the placeholder. A |PlaceholderPicture|
object has all the properties and methods of a |Picture| shape except that the
value of its :attr:`~._BaseSlidePlaceholder.shape_type` property is
`MSO_SHAPE_TYPE.PLACEHOLDER` instead of `MSO_SHAPE_TYPE.PICTURE`.
|
insert_picture
|
python
|
scanny/python-pptx
|
src/pptx/shapes/placeholder.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/placeholder.py
|
MIT
|
def _new_placeholder_pic(self, image_file):
"""
Return a new `p:pic` element depicting the image in *image_file*,
suitable for use as a placeholder. In particular this means not
having an `a:xfrm` element, allowing its extents to be inherited from
its layout placeholder.
"""
rId, desc, image_size = self._get_or_add_image(image_file)
shape_id, name = self.shape_id, self.name
pic = CT_Picture.new_ph_pic(shape_id, name, desc, rId)
pic.crop_to_fit(image_size, (self.width, self.height))
return pic
|
Return a new `p:pic` element depicting the image in *image_file*,
suitable for use as a placeholder. In particular this means not
having an `a:xfrm` element, allowing its extents to be inherited from
its layout placeholder.
|
_new_placeholder_pic
|
python
|
scanny/python-pptx
|
src/pptx/shapes/placeholder.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/placeholder.py
|
MIT
|
def _get_or_add_image(self, image_file):
"""
Return an (rId, description, image_size) 3-tuple identifying the
related image part containing *image_file* and describing the image.
"""
image_part, rId = self.part.get_or_add_image_part(image_file)
desc, image_size = image_part.desc, image_part._px_size
return rId, desc, image_size
|
Return an (rId, description, image_size) 3-tuple identifying the
related image part containing *image_file* and describing the image.
|
_get_or_add_image
|
python
|
scanny/python-pptx
|
src/pptx/shapes/placeholder.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/placeholder.py
|
MIT
|
def insert_table(self, rows, cols):
"""Return |PlaceholderGraphicFrame| object containing a `rows` by `cols` table.
The position and width of the table are those of the placeholder and its height
is proportional to the number of rows. A |PlaceholderGraphicFrame| object has
all the properties and methods of a |GraphicFrame| shape except that the value
of its :attr:`~._BaseSlidePlaceholder.shape_type` property is unconditionally
`MSO_SHAPE_TYPE.PLACEHOLDER`. Note that the return value is not the new table
but rather *contains* the new table. The table can be accessed using the
:attr:`~.PlaceholderGraphicFrame.table` property of the returned
|PlaceholderGraphicFrame| object.
"""
graphicFrame = self._new_placeholder_table(rows, cols)
self._replace_placeholder_with(graphicFrame)
return PlaceholderGraphicFrame(graphicFrame, self._parent)
|
Return |PlaceholderGraphicFrame| object containing a `rows` by `cols` table.
The position and width of the table are those of the placeholder and its height
is proportional to the number of rows. A |PlaceholderGraphicFrame| object has
all the properties and methods of a |GraphicFrame| shape except that the value
of its :attr:`~._BaseSlidePlaceholder.shape_type` property is unconditionally
`MSO_SHAPE_TYPE.PLACEHOLDER`. Note that the return value is not the new table
but rather *contains* the new table. The table can be accessed using the
:attr:`~.PlaceholderGraphicFrame.table` property of the returned
|PlaceholderGraphicFrame| object.
|
insert_table
|
python
|
scanny/python-pptx
|
src/pptx/shapes/placeholder.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/placeholder.py
|
MIT
|
def _new_placeholder_table(self, rows, cols):
"""
Return a newly added `p:graphicFrame` element containing an empty
table with *rows* rows and *cols* columns, positioned at the location
of this placeholder and having its same width. The table's height is
determined by the number of rows.
"""
shape_id, name, height = self.shape_id, self.name, Emu(rows * 370840)
return CT_GraphicalObjectFrame.new_table_graphicFrame(
shape_id, name, rows, cols, self.left, self.top, self.width, height
)
|
Return a newly added `p:graphicFrame` element containing an empty
table with *rows* rows and *cols* columns, positioned at the location
of this placeholder and having its same width. The table's height is
determined by the number of rows.
|
_new_placeholder_table
|
python
|
scanny/python-pptx
|
src/pptx/shapes/placeholder.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/placeholder.py
|
MIT
|
def __getitem__(self, idx: int) -> BaseShape:
"""Return shape at `idx` in sequence, e.g. `shapes[2]`."""
shape_elms = list(self._iter_member_elms())
try:
shape_elm = shape_elms[idx]
except IndexError:
raise IndexError("shape index out of range")
return self._shape_factory(shape_elm)
|
Return shape at `idx` in sequence, e.g. `shapes[2]`.
|
__getitem__
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def clone_placeholder(self, placeholder: LayoutPlaceholder) -> None:
"""Add a new placeholder shape based on `placeholder`."""
sp = placeholder.element
ph_type, orient, sz, idx = (sp.ph_type, sp.ph_orient, sp.ph_sz, sp.ph_idx)
id_ = self._next_shape_id
name = self._next_ph_name(ph_type, id_, orient)
self._spTree.add_placeholder(id_, name, ph_type, orient, sz, idx)
|
Add a new placeholder shape based on `placeholder`.
|
clone_placeholder
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def ph_basename(self, ph_type: PP_PLACEHOLDER) -> str:
"""Return the base name for a placeholder of `ph_type` in this shape collection.
There is some variance between slide types, for example a notes slide uses a different
name for the body placeholder, so this method can be overriden by subclasses.
"""
return {
PP_PLACEHOLDER.BITMAP: "ClipArt Placeholder",
PP_PLACEHOLDER.BODY: "Text Placeholder",
PP_PLACEHOLDER.CENTER_TITLE: "Title",
PP_PLACEHOLDER.CHART: "Chart Placeholder",
PP_PLACEHOLDER.DATE: "Date Placeholder",
PP_PLACEHOLDER.FOOTER: "Footer Placeholder",
PP_PLACEHOLDER.HEADER: "Header Placeholder",
PP_PLACEHOLDER.MEDIA_CLIP: "Media Placeholder",
PP_PLACEHOLDER.OBJECT: "Content Placeholder",
PP_PLACEHOLDER.ORG_CHART: "SmartArt Placeholder",
PP_PLACEHOLDER.PICTURE: "Picture Placeholder",
PP_PLACEHOLDER.SLIDE_NUMBER: "Slide Number Placeholder",
PP_PLACEHOLDER.SUBTITLE: "Subtitle",
PP_PLACEHOLDER.TABLE: "Table Placeholder",
PP_PLACEHOLDER.TITLE: "Title",
}[ph_type]
|
Return the base name for a placeholder of `ph_type` in this shape collection.
There is some variance between slide types, for example a notes slide uses a different
name for the body placeholder, so this method can be overriden by subclasses.
|
ph_basename
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _iter_member_elms(self) -> Iterator[ShapeElement]:
"""Generate each child of the `p:spTree` element that corresponds to a shape.
Items appear in XML document order.
"""
for shape_elm in self._spTree.iter_shape_elms():
if self._is_member_elm(shape_elm):
yield shape_elm
|
Generate each child of the `p:spTree` element that corresponds to a shape.
Items appear in XML document order.
|
_iter_member_elms
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _next_ph_name(self, ph_type: PP_PLACEHOLDER, id: int, orient: str) -> str:
"""Next unique placeholder name for placeholder shape of type `ph_type`.
Usually will be standard placeholder root name suffixed with id-1, e.g.
_next_ph_name(ST_PlaceholderType.TBL, 4, 'horz') ==> 'Table Placeholder 3'. The number is
incremented as necessary to make the name unique within the collection. If `orient` is
`'vert'`, the placeholder name is prefixed with `'Vertical '`.
"""
basename = self.ph_basename(ph_type)
# prefix rootname with 'Vertical ' if orient is 'vert'
if orient == ST_Direction.VERT:
basename = "Vertical %s" % basename
# increment numpart as necessary to make name unique
numpart = id - 1
names = self._spTree.xpath("//p:cNvPr/@name")
while True:
name = "%s %d" % (basename, numpart)
if name not in names:
break
numpart += 1
return name
|
Next unique placeholder name for placeholder shape of type `ph_type`.
Usually will be standard placeholder root name suffixed with id-1, e.g.
_next_ph_name(ST_PlaceholderType.TBL, 4, 'horz') ==> 'Table Placeholder 3'. The number is
incremented as necessary to make the name unique within the collection. If `orient` is
`'vert'`, the placeholder name is prefixed with `'Vertical '`.
|
_next_ph_name
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _next_shape_id(self) -> int:
"""Return a unique shape id suitable for use with a new shape.
The returned id is 1 greater than the maximum shape id used so far. In practice, the
minimum id is 2 because the spTree element is always assigned id="1".
"""
# ---presence of cached-max-shape-id indicates turbo mode is on---
if self._cached_max_shape_id is not None:
self._cached_max_shape_id += 1
return self._cached_max_shape_id
return self._spTree.max_shape_id + 1
|
Return a unique shape id suitable for use with a new shape.
The returned id is 1 greater than the maximum shape id used so far. In practice, the
minimum id is 2 because the spTree element is always assigned id="1".
|
_next_shape_id
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def add_chart(
self,
chart_type: XL_CHART_TYPE,
x: Length,
y: Length,
cx: Length,
cy: Length,
chart_data: ChartData,
) -> Chart:
"""Add a new chart of `chart_type` to the slide.
The chart is positioned at (`x`, `y`), has size (`cx`, `cy`), and depicts `chart_data`.
`chart_type` is one of the :ref:`XlChartType` enumeration values. `chart_data` is a
|ChartData| object populated with the categories and series values for the chart.
Note that a |GraphicFrame| shape object is returned, not the |Chart| object contained in
that graphic frame shape. The chart object may be accessed using the :attr:`chart`
property of the returned |GraphicFrame| object.
"""
rId = self.part.add_chart_part(chart_type, chart_data)
graphicFrame = self._add_chart_graphicFrame(rId, x, y, cx, cy)
self._recalculate_extents()
return cast("Chart", self._shape_factory(graphicFrame))
|
Add a new chart of `chart_type` to the slide.
The chart is positioned at (`x`, `y`), has size (`cx`, `cy`), and depicts `chart_data`.
`chart_type` is one of the :ref:`XlChartType` enumeration values. `chart_data` is a
|ChartData| object populated with the categories and series values for the chart.
Note that a |GraphicFrame| shape object is returned, not the |Chart| object contained in
that graphic frame shape. The chart object may be accessed using the :attr:`chart`
property of the returned |GraphicFrame| object.
|
add_chart
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def add_connector(
self,
connector_type: MSO_CONNECTOR_TYPE,
begin_x: Length,
begin_y: Length,
end_x: Length,
end_y: Length,
) -> Connector:
"""Add a newly created connector shape to the end of this shape tree.
`connector_type` is a member of the :ref:`MsoConnectorType` enumeration and the end-point
values are specified as EMU values. The returned connector is of type `connector_type` and
has begin and end points as specified.
"""
cxnSp = self._add_cxnSp(connector_type, begin_x, begin_y, end_x, end_y)
self._recalculate_extents()
return cast(Connector, self._shape_factory(cxnSp))
|
Add a newly created connector shape to the end of this shape tree.
`connector_type` is a member of the :ref:`MsoConnectorType` enumeration and the end-point
values are specified as EMU values. The returned connector is of type `connector_type` and
has begin and end points as specified.
|
add_connector
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def add_group_shape(self, shapes: Iterable[BaseShape] = ()) -> GroupShape:
"""Return a |GroupShape| object newly appended to this shape tree.
The group shape is empty and must be populated with shapes using methods on its shape
tree, available on its `.shapes` property. The position and extents of the group shape are
determined by the shapes it contains; its position and extents are recalculated each time
a shape is added to it.
"""
shapes = tuple(shapes)
grpSp = self._element.add_grpSp()
for shape in shapes:
grpSp.insert_element_before(
shape._element, "p:extLst" # pyright: ignore[reportPrivateUsage]
)
if shapes:
grpSp.recalculate_extents()
return cast(GroupShape, self._shape_factory(grpSp))
|
Return a |GroupShape| object newly appended to this shape tree.
The group shape is empty and must be populated with shapes using methods on its shape
tree, available on its `.shapes` property. The position and extents of the group shape are
determined by the shapes it contains; its position and extents are recalculated each time
a shape is added to it.
|
add_group_shape
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def add_picture(
self,
image_file: str | IO[bytes],
left: Length,
top: Length,
width: Length | None = None,
height: Length | None = None,
) -> Picture:
"""Add picture shape displaying image in `image_file`.
`image_file` can be either a path to a file (a string) or a file-like object. The picture
is positioned with its top-left corner at (`top`, `left`). If `width` and `height` are
both |None|, the native size of the image is used. If only one of `width` or `height` is
used, the unspecified dimension is calculated to preserve the aspect ratio of the image.
If both are specified, the picture is stretched to fit, without regard to its native
aspect ratio.
"""
image_part, rId = self.part.get_or_add_image_part(image_file)
pic = self._add_pic_from_image_part(image_part, rId, left, top, width, height)
self._recalculate_extents()
return cast(Picture, self._shape_factory(pic))
|
Add picture shape displaying image in `image_file`.
`image_file` can be either a path to a file (a string) or a file-like object. The picture
is positioned with its top-left corner at (`top`, `left`). If `width` and `height` are
both |None|, the native size of the image is used. If only one of `width` or `height` is
used, the unspecified dimension is calculated to preserve the aspect ratio of the image.
If both are specified, the picture is stretched to fit, without regard to its native
aspect ratio.
|
add_picture
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def add_shape(
self, autoshape_type_id: MSO_SHAPE, left: Length, top: Length, width: Length, height: Length
) -> Shape:
"""Return new |Shape| object appended to this shape tree.
`autoshape_type_id` is a member of :ref:`MsoAutoShapeType` e.g. `MSO_SHAPE.RECTANGLE`
specifying the type of shape to be added. The remaining arguments specify the new shape's
position and size.
"""
autoshape_type = AutoShapeType(autoshape_type_id)
sp = self._add_sp(autoshape_type, left, top, width, height)
self._recalculate_extents()
return cast(Shape, self._shape_factory(sp))
|
Return new |Shape| object appended to this shape tree.
`autoshape_type_id` is a member of :ref:`MsoAutoShapeType` e.g. `MSO_SHAPE.RECTANGLE`
specifying the type of shape to be added. The remaining arguments specify the new shape's
position and size.
|
add_shape
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def add_textbox(self, left: Length, top: Length, width: Length, height: Length) -> Shape:
"""Return newly added text box shape appended to this shape tree.
The text box is of the specified size, located at the specified position on the slide.
"""
sp = self._add_textbox_sp(left, top, width, height)
self._recalculate_extents()
return cast(Shape, self._shape_factory(sp))
|
Return newly added text box shape appended to this shape tree.
The text box is of the specified size, located at the specified position on the slide.
|
add_textbox
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def build_freeform(
self, start_x: float = 0, start_y: float = 0, scale: tuple[float, float] | float = 1.0
) -> FreeformBuilder:
"""Return |FreeformBuilder| object to specify a freeform shape.
The optional `start_x` and `start_y` arguments specify the starting pen position in local
coordinates. They will be rounded to the nearest integer before use and each default to
zero.
The optional `scale` argument specifies the size of local coordinates proportional to
slide coordinates (EMU). If the vertical scale is different than the horizontal scale
(local coordinate units are "rectangular"), a pair of numeric values can be provided as
the `scale` argument, e.g. `scale=(1.0, 2.0)`. In this case the first number is
interpreted as the horizontal (X) scale and the second as the vertical (Y) scale.
A convenient method for calculating scale is to divide a |Length| object by an equivalent
count of local coordinate units, e.g. `scale = Inches(1)/1000` for 1000 local units per
inch.
"""
x_scale, y_scale = scale if isinstance(scale, tuple) else (scale, scale)
return FreeformBuilder.new(self, start_x, start_y, x_scale, y_scale)
|
Return |FreeformBuilder| object to specify a freeform shape.
The optional `start_x` and `start_y` arguments specify the starting pen position in local
coordinates. They will be rounded to the nearest integer before use and each default to
zero.
The optional `scale` argument specifies the size of local coordinates proportional to
slide coordinates (EMU). If the vertical scale is different than the horizontal scale
(local coordinate units are "rectangular"), a pair of numeric values can be provided as
the `scale` argument, e.g. `scale=(1.0, 2.0)`. In this case the first number is
interpreted as the horizontal (X) scale and the second as the vertical (Y) scale.
A convenient method for calculating scale is to divide a |Length| object by an equivalent
count of local coordinate units, e.g. `scale = Inches(1)/1000` for 1000 local units per
inch.
|
build_freeform
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _add_chart_graphicFrame(
self, rId: str, x: Length, y: Length, cx: Length, cy: Length
) -> CT_GraphicalObjectFrame:
"""Return new `p:graphicFrame` element appended to this shape tree.
The `p:graphicFrame` element has the specified position and size and refers to the chart
part identified by `rId`.
"""
shape_id = self._next_shape_id
name = "Chart %d" % (shape_id - 1)
graphicFrame = CT_GraphicalObjectFrame.new_chart_graphicFrame(
shape_id, name, rId, x, y, cx, cy
)
self._spTree.append(graphicFrame)
return graphicFrame
|
Return new `p:graphicFrame` element appended to this shape tree.
The `p:graphicFrame` element has the specified position and size and refers to the chart
part identified by `rId`.
|
_add_chart_graphicFrame
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _add_cxnSp(
self,
connector_type: MSO_CONNECTOR_TYPE,
begin_x: Length,
begin_y: Length,
end_x: Length,
end_y: Length,
) -> CT_Connector:
"""Return a newly-added `p:cxnSp` element as specified.
The `p:cxnSp` element is for a connector of `connector_type` beginning at (`begin_x`,
`begin_y`) and extending to (`end_x`, `end_y`).
"""
id_ = self._next_shape_id
name = "Connector %d" % (id_ - 1)
flipH, flipV = begin_x > end_x, begin_y > end_y
x, y = min(begin_x, end_x), min(begin_y, end_y)
cx, cy = abs(end_x - begin_x), abs(end_y - begin_y)
return self._element.add_cxnSp(id_, name, connector_type, x, y, cx, cy, flipH, flipV)
|
Return a newly-added `p:cxnSp` element as specified.
The `p:cxnSp` element is for a connector of `connector_type` beginning at (`begin_x`,
`begin_y`) and extending to (`end_x`, `end_y`).
|
_add_cxnSp
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _add_pic_from_image_part(
self,
image_part: ImagePart,
rId: str,
x: Length,
y: Length,
cx: Length | None,
cy: Length | None,
) -> CT_Picture:
"""Return a newly appended `p:pic` element as specified.
The `p:pic` element displays the image in `image_part` with size and position specified by
`x`, `y`, `cx`, and `cy`. The element is appended to the shape tree, causing it to be
displayed first in z-order on the slide.
"""
id_ = self._next_shape_id
scaled_cx, scaled_cy = image_part.scale(cx, cy)
name = "Picture %d" % (id_ - 1)
desc = image_part.desc
pic = self._grpSp.add_pic(id_, name, desc, rId, x, y, scaled_cx, scaled_cy)
return pic
|
Return a newly appended `p:pic` element as specified.
The `p:pic` element displays the image in `image_part` with size and position specified by
`x`, `y`, `cx`, and `cy`. The element is appended to the shape tree, causing it to be
displayed first in z-order on the slide.
|
_add_pic_from_image_part
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _add_sp(
self, autoshape_type: AutoShapeType, x: Length, y: Length, cx: Length, cy: Length
) -> CT_Shape:
"""Return newly-added `p:sp` element as specified.
`p:sp` element is of `autoshape_type` at position (`x`, `y`) and of size (`cx`, `cy`).
"""
id_ = self._next_shape_id
name = "%s %d" % (autoshape_type.basename, id_ - 1)
sp = self._grpSp.add_autoshape(id_, name, autoshape_type.prst, x, y, cx, cy)
return sp
|
Return newly-added `p:sp` element as specified.
`p:sp` element is of `autoshape_type` at position (`x`, `y`) and of size (`cx`, `cy`).
|
_add_sp
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _add_textbox_sp(self, x: Length, y: Length, cx: Length, cy: Length) -> CT_Shape:
"""Return newly-appended textbox `p:sp` element.
Element has position (`x`, `y`) and size (`cx`, `cy`).
"""
id_ = self._next_shape_id
name = "TextBox %d" % (id_ - 1)
sp = self._spTree.add_textbox(id_, name, x, y, cx, cy)
return sp
|
Return newly-appended textbox `p:sp` element.
Element has position (`x`, `y`) and size (`cx`, `cy`).
|
_add_textbox_sp
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _recalculate_extents(self) -> None:
"""Adjust position and size to incorporate all contained shapes.
This would typically be called when a contained shape is added, removed, or its position
or size updated.
"""
# ---default behavior is to do nothing, GroupShapes overrides to
# produce the distinctive behavior of groups and subgroups.---
pass
|
Adjust position and size to incorporate all contained shapes.
This would typically be called when a contained shape is added, removed, or its position
or size updated.
|
_recalculate_extents
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def add_table(
self, rows: int, cols: int, left: Length, top: Length, width: Length, height: Length
) -> GraphicFrame:
"""Add a |GraphicFrame| object containing a table.
The table has the specified number of `rows` and `cols` and the specified position and
size. `width` is evenly distributed between the columns of the new table. Likewise,
`height` is evenly distributed between the rows. Note that the `.table` property on the
returned |GraphicFrame| shape must be used to access the enclosed |Table| object.
"""
graphicFrame = self._add_graphicFrame_containing_table(rows, cols, left, top, width, height)
return cast(GraphicFrame, self._shape_factory(graphicFrame))
|
Add a |GraphicFrame| object containing a table.
The table has the specified number of `rows` and `cols` and the specified position and
size. `width` is evenly distributed between the columns of the new table. Likewise,
`height` is evenly distributed between the rows. Note that the `.table` property on the
returned |GraphicFrame| shape must be used to access the enclosed |Table| object.
|
add_table
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def title(self) -> Shape | None:
"""The title placeholder shape on the slide.
|None| if the slide has no title placeholder.
"""
for elm in self._spTree.iter_ph_elms():
if elm.ph_idx == 0:
return cast(Shape, self._shape_factory(elm))
return None
|
The title placeholder shape on the slide.
|None| if the slide has no title placeholder.
|
title
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _add_graphicFrame_containing_table(
self, rows: int, cols: int, x: Length, y: Length, cx: Length, cy: Length
) -> CT_GraphicalObjectFrame:
"""Return a newly added `p:graphicFrame` element containing a table as specified."""
_id = self._next_shape_id
name = "Table %d" % (_id - 1)
graphicFrame = self._spTree.add_table(_id, name, rows, cols, x, y, cx, cy)
return graphicFrame
|
Return a newly added `p:graphicFrame` element containing a table as specified.
|
_add_graphicFrame_containing_table
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _add_video_timing(self, pic: CT_Picture) -> None:
"""Add a `p:video` element under `p:sld/p:timing`.
The element will refer to the specified `pic` element by its shape id, and cause the video
play controls to appear for that video.
"""
sld = self._spTree.xpath("/p:sld")[0]
childTnLst = sld.get_or_add_childTnLst()
childTnLst.add_video(pic.shape_id)
|
Add a `p:video` element under `p:sld/p:timing`.
The element will refer to the specified `pic` element by its shape id, and cause the video
play controls to appear for that video.
|
_add_video_timing
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def ph_basename(self, ph_type: PP_PLACEHOLDER) -> str:
"""Return the base name for a placeholder of `ph_type` in this shape collection.
A notes slide uses a different name for the body placeholder and has some unique
placeholder types, so this method overrides the default in the base class.
"""
return {
PP_PLACEHOLDER.BODY: "Notes Placeholder",
PP_PLACEHOLDER.DATE: "Date Placeholder",
PP_PLACEHOLDER.FOOTER: "Footer Placeholder",
PP_PLACEHOLDER.HEADER: "Header Placeholder",
PP_PLACEHOLDER.SLIDE_IMAGE: "Slide Image Placeholder",
PP_PLACEHOLDER.SLIDE_NUMBER: "Slide Number Placeholder",
}[ph_type]
|
Return the base name for a placeholder of `ph_type` in this shape collection.
A notes slide uses a different name for the body placeholder and has some unique
placeholder types, so this method overrides the default in the base class.
|
ph_basename
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def get(self, idx: int, default: LayoutPlaceholder | None = None) -> LayoutPlaceholder | None:
"""The first placeholder shape with matching `idx` value, or `default` if not found."""
for placeholder in self:
if placeholder.element.ph_idx == idx:
return placeholder
return default
|
The first placeholder shape with matching `idx` value, or `default` if not found.
|
get
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def get(self, ph_type: PP_PLACEHOLDER, default: MasterPlaceholder | None = None):
"""Return the first placeholder shape with type `ph_type` (e.g. 'body').
Returns `default` if no such placeholder shape is present in the collection.
"""
for placeholder in self:
if placeholder.ph_type == ph_type:
return placeholder
return default
|
Return the first placeholder shape with type `ph_type` (e.g. 'body').
Returns `default` if no such placeholder shape is present in the collection.
|
get
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _shape_factory( # pyright: ignore[reportIncompatibleMethodOverride]
self, placeholder_elm: CT_Shape
) -> MasterPlaceholder:
"""Return an instance of the appropriate shape proxy class for `shape_elm`."""
return cast(MasterPlaceholder, _MasterShapeFactory(placeholder_elm, self))
|
Return an instance of the appropriate shape proxy class for `shape_elm`.
|
_shape_factory
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _shape_factory( # pyright: ignore[reportIncompatibleMethodOverride]
self, placeholder_elm: CT_Shape
) -> NotesSlidePlaceholder:
"""Return an instance of the appropriate placeholder proxy class for `placeholder_elm`."""
return cast(NotesSlidePlaceholder, _NotesSlideShapeFactory(placeholder_elm, self))
|
Return an instance of the appropriate placeholder proxy class for `placeholder_elm`.
|
_shape_factory
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def __getitem__(self, idx: int):
"""Access placeholder shape having `idx`.
Note that while this looks like list access, idx is actually a dictionary key and will
raise |KeyError| if no placeholder with that idx value is in the collection.
"""
for e in self._element.iter_ph_elms():
if e.ph_idx == idx:
return SlideShapeFactory(e, self)
raise KeyError("no placeholder on this slide with idx == %d" % idx)
|
Access placeholder shape having `idx`.
Note that while this looks like list access, idx is actually a dictionary key and will
raise |KeyError| if no placeholder with that idx value is in the collection.
|
__getitem__
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def __iter__(self):
"""Generate placeholder shapes in `idx` order."""
ph_elms = sorted([e for e in self._element.iter_ph_elms()], key=lambda e: e.ph_idx)
return (SlideShapeFactory(e, self) for e in ph_elms)
|
Generate placeholder shapes in `idx` order.
|
__iter__
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def BaseShapeFactory(shape_elm: ShapeElement, parent: ProvidesPart) -> BaseShape:
"""Return an instance of the appropriate shape proxy class for `shape_elm`."""
tag = shape_elm.tag
if isinstance(shape_elm, CT_Picture):
videoFiles = shape_elm.xpath("./p:nvPicPr/p:nvPr/a:videoFile")
if videoFiles:
return Movie(shape_elm, parent)
return Picture(shape_elm, parent)
shape_cls = {
qn("p:cxnSp"): Connector,
qn("p:grpSp"): GroupShape,
qn("p:sp"): Shape,
qn("p:graphicFrame"): GraphicFrame,
}.get(tag, BaseShape)
return shape_cls(shape_elm, parent) # pyright: ignore[reportArgumentType]
|
Return an instance of the appropriate shape proxy class for `shape_elm`.
|
BaseShapeFactory
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _LayoutShapeFactory(shape_elm: ShapeElement, parent: ProvidesPart) -> BaseShape:
"""Return appropriate shape object for `shape_elm` on a slide layout."""
if isinstance(shape_elm, CT_Shape) and shape_elm.has_ph_elm:
return LayoutPlaceholder(shape_elm, parent)
return BaseShapeFactory(shape_elm, parent)
|
Return appropriate shape object for `shape_elm` on a slide layout.
|
_LayoutShapeFactory
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _MasterShapeFactory(shape_elm: ShapeElement, parent: ProvidesPart) -> BaseShape:
"""Return appropriate shape object for `shape_elm` on a slide master."""
if isinstance(shape_elm, CT_Shape) and shape_elm.has_ph_elm:
return MasterPlaceholder(shape_elm, parent)
return BaseShapeFactory(shape_elm, parent)
|
Return appropriate shape object for `shape_elm` on a slide master.
|
_MasterShapeFactory
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _NotesSlideShapeFactory(shape_elm: ShapeElement, parent: ProvidesPart) -> BaseShape:
"""Return appropriate shape object for `shape_elm` on a notes slide."""
if isinstance(shape_elm, CT_Shape) and shape_elm.has_ph_elm:
return NotesSlidePlaceholder(shape_elm, parent)
return BaseShapeFactory(shape_elm, parent)
|
Return appropriate shape object for `shape_elm` on a notes slide.
|
_NotesSlideShapeFactory
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _SlidePlaceholderFactory(shape_elm: ShapeElement, parent: ProvidesPart):
"""Return a placeholder shape of the appropriate type for `shape_elm`."""
tag = shape_elm.tag
if tag == qn("p:sp"):
Constructor = {
PP_PLACEHOLDER.BITMAP: PicturePlaceholder,
PP_PLACEHOLDER.CHART: ChartPlaceholder,
PP_PLACEHOLDER.PICTURE: PicturePlaceholder,
PP_PLACEHOLDER.TABLE: TablePlaceholder,
}.get(shape_elm.ph_type, SlidePlaceholder)
elif tag == qn("p:graphicFrame"):
Constructor = PlaceholderGraphicFrame
elif tag == qn("p:pic"):
Constructor = PlaceholderPicture
else:
Constructor = BaseShapeFactory
return Constructor(shape_elm, parent) # pyright: ignore[reportArgumentType]
|
Return a placeholder shape of the appropriate type for `shape_elm`.
|
_SlidePlaceholderFactory
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def SlideShapeFactory(shape_elm: ShapeElement, parent: ProvidesPart) -> BaseShape:
"""Return appropriate shape object for `shape_elm` on a slide."""
if shape_elm.has_ph_elm:
return _SlidePlaceholderFactory(shape_elm, parent)
return BaseShapeFactory(shape_elm, parent)
|
Return appropriate shape object for `shape_elm` on a slide.
|
SlideShapeFactory
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def new_movie_pic(
cls,
shapes: SlideShapes,
shape_id: int,
movie_file: str | IO[bytes],
x: Length,
y: Length,
cx: Length,
cy: Length,
poster_frame_image: str | IO[bytes] | None,
mime_type: str | None,
) -> CT_Picture:
"""Return a new `p:pic` element containing video in `movie_file`.
If `mime_type` is None, 'video/unknown' is used. If `poster_frame_file` is None, the
default "media loudspeaker" image is used.
"""
return cls(shapes, shape_id, movie_file, x, y, cx, cy, poster_frame_image, mime_type)._pic
|
Return a new `p:pic` element containing video in `movie_file`.
If `mime_type` is None, 'video/unknown' is used. If `poster_frame_file` is None, the
default "media loudspeaker" image is used.
|
new_movie_pic
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _pic(self) -> CT_Picture:
"""Return the new `p:pic` element referencing the video."""
return CT_Picture.new_video_pic(
self._shape_id,
self._shape_name,
self._video_rId,
self._media_rId,
self._poster_frame_rId,
self._x,
self._y,
self._cx,
self._cy,
)
|
Return the new `p:pic` element referencing the video.
|
_pic
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _poster_frame_image_file(self) -> str | IO[bytes]:
"""Return the image file for video placeholder image.
If no poster frame file is provided, the default "media loudspeaker" image is used.
"""
poster_frame_file = self._poster_frame_file
if poster_frame_file is None:
return io.BytesIO(SPEAKER_IMAGE_BYTES)
return poster_frame_file
|
Return the image file for video placeholder image.
If no poster frame file is provided, the default "media loudspeaker" image is used.
|
_poster_frame_image_file
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _video_part_rIds(self) -> tuple[str, str]:
"""Return the rIds for relationships to media part for video.
This is where the media part and its relationships to the slide are actually created.
"""
media_rId, video_rId = self._slide_part.get_or_add_video_media_part(self._video)
return media_rId, video_rId
|
Return the rIds for relationships to media part for video.
This is where the media part and its relationships to the slide are actually created.
|
_video_part_rIds
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def graphicFrame(
cls,
shapes: _BaseGroupShapes,
shape_id: int,
ole_object_file: str | IO[bytes],
prog_id: PROG_ID | str,
x: Length,
y: Length,
cx: Length | None,
cy: Length | None,
icon_file: str | IO[bytes] | None,
icon_width: Length | None,
icon_height: Length | None,
) -> CT_GraphicalObjectFrame:
"""Return new `p:graphicFrame` element containing embedded `ole_object_file`."""
return cls(
shapes,
shape_id,
ole_object_file,
prog_id,
x,
y,
cx,
cy,
icon_file,
icon_width,
icon_height,
)._graphicFrame
|
Return new `p:graphicFrame` element containing embedded `ole_object_file`.
|
graphicFrame
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _graphicFrame(self) -> CT_GraphicalObjectFrame:
"""Newly-created `p:graphicFrame` element referencing embedded OLE-object."""
return CT_GraphicalObjectFrame.new_ole_object_graphicFrame(
self._shape_id,
self._shape_name,
self._ole_object_rId,
self._progId,
self._icon_rId,
self._x,
self._y,
self._cx,
self._cy,
self._icon_width,
self._icon_height,
)
|
Newly-created `p:graphicFrame` element referencing embedded OLE-object.
|
_graphicFrame
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _cx(self) -> Length:
"""Emu object specifying width of "show-as-icon" image for OLE shape."""
# --- a user-specified width overrides any default ---
if self._cx_arg is not None:
return self._cx_arg
# --- the default width is specified by the PROG_ID member if prog_id is one,
# --- otherwise it gets the default icon width.
return (
Emu(self._prog_id_arg.width) if isinstance(self._prog_id_arg, PROG_ID) else Emu(965200)
)
|
Emu object specifying width of "show-as-icon" image for OLE shape.
|
_cx
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _cy(self) -> Length:
"""Emu object specifying height of "show-as-icon" image for OLE shape."""
# --- a user-specified width overrides any default ---
if self._cy_arg is not None:
return self._cy_arg
# --- the default height is specified by the PROG_ID member if prog_id is one,
# --- otherwise it gets the default icon height.
return (
Emu(self._prog_id_arg.height) if isinstance(self._prog_id_arg, PROG_ID) else Emu(609600)
)
|
Emu object specifying height of "show-as-icon" image for OLE shape.
|
_cy
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _icon_image_file(self) -> str | IO[bytes]:
"""Reference to image file containing icon to show in lieu of this object.
This can be either a str path or a file-like object (io.BytesIO typically).
"""
# --- a user-specified icon overrides any default ---
if self._icon_file_arg is not None:
return self._icon_file_arg
# --- A prog_id belonging to PROG_ID gets its icon filename from there. A
# --- user-specified (str) prog_id gets the default icon.
icon_filename = (
self._prog_id_arg.icon_filename
if isinstance(self._prog_id_arg, PROG_ID)
else "generic-icon.emf"
)
_thisdir = os.path.split(__file__)[0]
return os.path.abspath(os.path.join(_thisdir, "..", "templates", icon_filename))
|
Reference to image file containing icon to show in lieu of this object.
This can be either a str path or a file-like object (io.BytesIO typically).
|
_icon_image_file
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _ole_object_rId(self) -> str:
"""str rId like "rId6" of relationship to embedded ole_object part.
This is where the ole_object part and its relationship to the slide are actually created.
"""
return self._slide_part.add_embedded_ole_object_part(
self._prog_id_arg, self._ole_object_file
)
|
str rId like "rId6" of relationship to embedded ole_object part.
This is where the ole_object part and its relationship to the slide are actually created.
|
_ole_object_rId
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def _progId(self) -> str:
"""str like "Excel.Sheet.12" identifying program used to open object.
This value appears in the `progId` attribute of the `p:oleObj` element for the object.
"""
prog_id_arg = self._prog_id_arg
# --- member of PROG_ID enumeration knows its progId keyphrase, otherwise caller
# --- has specified it explicitly (as str)
return prog_id_arg.progId if isinstance(prog_id_arg, PROG_ID) else prog_id_arg
|
str like "Excel.Sheet.12" identifying program used to open object.
This value appears in the `progId` attribute of the `p:oleObj` element for the object.
|
_progId
|
python
|
scanny/python-pptx
|
src/pptx/shapes/shapetree.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/shapetree.py
|
MIT
|
def find(cls, family_name: str, is_bold: bool, is_italic: bool) -> str:
"""Return the absolute path to an installed OpenType font.
File is matched by `family_name` and the styles `is_bold` and `is_italic`.
"""
if cls._font_files is None:
cls._font_files = cls._installed_fonts()
return cls._font_files[(family_name, is_bold, is_italic)]
|
Return the absolute path to an installed OpenType font.
File is matched by `family_name` and the styles `is_bold` and `is_italic`.
|
find
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _installed_fonts(cls):
"""
Return a dict mapping a font descriptor to its font file path,
containing all the font files resident on the current machine. The
font descriptor is a (family_name, is_bold, is_italic) 3-tuple.
"""
fonts = {}
for d in cls._font_directories():
for key, path in cls._iter_font_files_in(d):
fonts[key] = path
return fonts
|
Return a dict mapping a font descriptor to its font file path,
containing all the font files resident on the current machine. The
font descriptor is a (family_name, is_bold, is_italic) 3-tuple.
|
_installed_fonts
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _font_directories(cls):
"""
Return a sequence of directory paths likely to contain fonts on the
current platform.
"""
if sys.platform.startswith("darwin"):
return cls._os_x_font_directories()
if sys.platform.startswith("win32"):
return cls._windows_font_directories()
raise OSError("unsupported operating system")
|
Return a sequence of directory paths likely to contain fonts on the
current platform.
|
_font_directories
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _iter_font_files_in(cls, directory):
"""
Generate the OpenType font files found in and under *directory*. Each
item is a key/value pair. The key is a (family_name, is_bold,
is_italic) 3-tuple, like ('Arial', True, False), and the value is the
absolute path to the font file.
"""
for root, dirs, files in os.walk(directory):
for filename in files:
file_ext = os.path.splitext(filename)[1]
if file_ext.lower() not in (".otf", ".ttf"):
continue
path = os.path.abspath(os.path.join(root, filename))
with _Font.open(path) as f:
yield ((f.family_name, f.is_bold, f.is_italic), path)
|
Generate the OpenType font files found in and under *directory*. Each
item is a key/value pair. The key is a (family_name, is_bold,
is_italic) 3-tuple, like ('Arial', True, False), and the value is the
absolute path to the font file.
|
_iter_font_files_in
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _os_x_font_directories(cls):
"""
Return a sequence of directory paths on a Mac in which fonts are
likely to be located.
"""
os_x_font_dirs = [
"/Library/Fonts",
"/Network/Library/Fonts",
"/System/Library/Fonts",
]
home = os.environ.get("HOME")
if home is not None:
os_x_font_dirs.extend(
[os.path.join(home, "Library", "Fonts"), os.path.join(home, ".fonts")]
)
return os_x_font_dirs
|
Return a sequence of directory paths on a Mac in which fonts are
likely to be located.
|
_os_x_font_directories
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def is_bold(self):
"""
|True| if this font is marked as a bold style of its font family.
"""
try:
return self._tables["head"].is_bold
except KeyError:
# some files don't have a head table
return False
|
|True| if this font is marked as a bold style of its font family.
|
is_bold
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def is_italic(self):
"""
|True| if this font is marked as an italic style of its font family.
"""
try:
return self._tables["head"].is_italic
except KeyError:
# some files don't have a head table
return False
|
|True| if this font is marked as an italic style of its font family.
|
is_italic
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _fields(self):
"""5-tuple containing the fields read from the font file header.
Also known as the offset table.
"""
# sfnt_version, tbl_count, search_range, entry_selector, range_shift
return self._stream.read_fields(">4sHHHH", 0)
|
5-tuple containing the fields read from the font file header.
Also known as the offset table.
|
_fields
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _iter_table_records(self):
"""
Generate a (tag, offset, length) 3-tuple for each of the tables in
this font file.
"""
count = self._table_count
bufr = self._stream.read(offset=12, length=count * 16)
tmpl = ">4sLLL"
for i in range(count):
offset = i * 16
tag, checksum, off, len_ = unpack_from(tmpl, bufr, offset)
yield tag.decode("utf-8"), off, len_
|
Generate a (tag, offset, length) 3-tuple for each of the tables in
this font file.
|
_iter_table_records
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _tables(self):
"""
A mapping of OpenType table tag, e.g. 'name', to a table object
providing access to the contents of that table.
"""
return dict(
(tag, _TableFactory(tag, self._stream, off, len_))
for tag, off, len_ in self._iter_table_records()
)
|
A mapping of OpenType table tag, e.g. 'name', to a table object
providing access to the contents of that table.
|
_tables
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def read_fields(self, template, offset=0):
"""
Return a tuple containing the C-struct fields in this stream
specified by *template* and starting at *offset*.
"""
self._file.seek(offset)
bufr = self._file.read(calcsize(template))
return unpack_from(template, bufr)
|
Return a tuple containing the C-struct fields in this stream
specified by *template* and starting at *offset*.
|
read_fields
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def family_name(self):
"""
The name of the typeface family for this font, e.g. 'Arial'.
"""
def find_first(dict_, keys, default=None):
for key in keys:
value = dict_.get(key)
if value is not None:
return value
return default
# keys for Unicode, Mac, and Windows family name, respectively
return find_first(self._names, ((0, 1), (1, 1), (3, 1)))
|
The name of the typeface family for this font, e.g. 'Arial'.
|
family_name
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _decode_name(raw_name, platform_id, encoding_id):
"""
Return the unicode name decoded from *raw_name* using the encoding
implied by the combination of *platform_id* and *encoding_id*.
"""
if platform_id == 1:
# reject non-Roman Mac font names
if encoding_id != 0:
return None
return raw_name.decode("mac-roman")
elif platform_id in (0, 3):
return raw_name.decode("utf-16-be")
else:
return None
|
Return the unicode name decoded from *raw_name* using the encoding
implied by the combination of *platform_id* and *encoding_id*.
|
_decode_name
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _iter_names(self):
"""Generate a key/value pair for each name in this table.
The key is a (platform_id, name_id) 2-tuple and the value is the unicode text
corresponding to that key.
"""
table_format, count, strings_offset = self._table_header
table_bytes = self._table_bytes
for idx in range(count):
platform_id, name_id, name = self._read_name(table_bytes, idx, strings_offset)
if name is None:
continue
yield ((platform_id, name_id), name)
|
Generate a key/value pair for each name in this table.
The key is a (platform_id, name_id) 2-tuple and the value is the unicode text
corresponding to that key.
|
_iter_names
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _name_header(bufr, idx):
"""
The (platform_id, encoding_id, language_id, name_id, length,
name_str_offset) 6-tuple encoded in each name record C-struct.
"""
name_hdr_offset = 6 + idx * 12
return unpack_from(">HHHHHH", bufr, name_hdr_offset)
|
The (platform_id, encoding_id, language_id, name_id, length,
name_str_offset) 6-tuple encoded in each name record C-struct.
|
_name_header
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _raw_name_string(bufr, strings_offset, str_offset, length):
"""
Return the *length* bytes comprising the encoded string in *bufr* at
*str_offset* in the strings area beginning at *strings_offset*.
"""
offset = strings_offset + str_offset
tmpl = "%ds" % length
return unpack_from(tmpl, bufr, offset)[0]
|
Return the *length* bytes comprising the encoded string in *bufr* at
*str_offset* in the strings area beginning at *strings_offset*.
|
_raw_name_string
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _read_name(self, bufr, idx, strings_offset):
"""Return a (platform_id, name_id, name) 3-tuple for name at `idx` in `bufr`.
The triple looks like (0, 1, 'Arial'). `strings_offset` is the for the name at
`idx` position in `bufr`. `strings_offset` is the index into `bufr` where actual
name strings begin. The returned name is a unicode string.
"""
platform_id, enc_id, lang_id, name_id, length, str_offset = self._name_header(bufr, idx)
name = self._read_name_text(bufr, platform_id, enc_id, strings_offset, str_offset, length)
return platform_id, name_id, name
|
Return a (platform_id, name_id, name) 3-tuple for name at `idx` in `bufr`.
The triple looks like (0, 1, 'Arial'). `strings_offset` is the for the name at
`idx` position in `bufr`. `strings_offset` is the index into `bufr` where actual
name strings begin. The returned name is a unicode string.
|
_read_name
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _read_name_text(
self, bufr, platform_id, encoding_id, strings_offset, name_str_offset, length
):
"""
Return the unicode name string at *name_str_offset* or |None| if
decoding its format is not supported.
"""
raw_name = self._raw_name_string(bufr, strings_offset, name_str_offset, length)
return self._decode_name(raw_name, platform_id, encoding_id)
|
Return the unicode name string at *name_str_offset* or |None| if
decoding its format is not supported.
|
_read_name_text
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def _TableFactory(tag, stream, offset, length):
"""
Return an instance of |Table| appropriate to *tag*, loaded from
*font_file* with content of *length* starting at *offset*.
"""
TableClass = {"head": _HeadTable, "name": _NameTable}.get(tag, _BaseTable)
return TableClass(tag, stream, offset, length)
|
Return an instance of |Table| appropriate to *tag*, loaded from
*font_file* with content of *length* starting at *offset*.
|
_TableFactory
|
python
|
scanny/python-pptx
|
src/pptx/text/fonts.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/fonts.py
|
MIT
|
def best_fit_font_size(
cls, text: str, extents: tuple[Length, Length], max_size: int, font_file: str
) -> int:
"""Return whole-number best fit point size less than or equal to `max_size`.
The return value is the largest whole-number point size less than or equal to
`max_size` that allows `text` to fit completely within `extents` when rendered
using font defined in `font_file`.
"""
line_source = _LineSource(text)
text_fitter = cls(line_source, extents, font_file)
return text_fitter._best_fit_font_size(max_size)
|
Return whole-number best fit point size less than or equal to `max_size`.
The return value is the largest whole-number point size less than or equal to
`max_size` that allows `text` to fit completely within `extents` when rendered
using font defined in `font_file`.
|
best_fit_font_size
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def _best_fit_font_size(self, max_size):
"""
Return the largest whole-number point size less than or equal to
*max_size* that this fitter can fit.
"""
predicate = self._fits_inside_predicate
sizes = _BinarySearchTree.from_ordered_sequence(range(1, int(max_size) + 1))
return sizes.find_max(predicate)
|
Return the largest whole-number point size less than or equal to
*max_size* that this fitter can fit.
|
_best_fit_font_size
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def _break_line(self, line_source, point_size):
"""
Return a (line, remainder) pair where *line* is the longest line in
*line_source* that will fit in this fitter's width and *remainder* is
a |_LineSource| object containing the text following the break point.
"""
lines = _BinarySearchTree.from_ordered_sequence(line_source)
predicate = self._fits_in_width_predicate(point_size)
return lines.find_max(predicate)
|
Return a (line, remainder) pair where *line* is the longest line in
*line_source* that will fit in this fitter's width and *remainder* is
a |_LineSource| object containing the text following the break point.
|
_break_line
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def _fits_in_width_predicate(self, point_size):
"""
Return a function taking a text string value and returns |True| if
that text fits in this fitter when rendered at *point_size*. Used as
predicate for _break_line()
"""
def predicate(line):
"""
Return |True| if *line* fits in this fitter when rendered at
*point_size*.
"""
cx = _rendered_size(line.text, point_size, self._font_file)[0]
return cx <= self._width
return predicate
|
Return a function taking a text string value and returns |True| if
that text fits in this fitter when rendered at *point_size*. Used as
predicate for _break_line()
|
_fits_in_width_predicate
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def predicate(line):
"""
Return |True| if *line* fits in this fitter when rendered at
*point_size*.
"""
cx = _rendered_size(line.text, point_size, self._font_file)[0]
return cx <= self._width
|
Return |True| if *line* fits in this fitter when rendered at
*point_size*.
|
predicate
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def _fits_inside_predicate(self):
"""Return function taking an integer point size argument.
The function returns |True| if the text in this fitter can be wrapped to fit
entirely within its extents when rendered at that point size.
"""
def predicate(point_size):
"""Return |True| when text in `line_source` can be wrapped to fit.
Fit means text can be broken into lines that fit entirely within `extents`
when rendered at `point_size` using the font defined in `font_file`.
"""
text_lines = self._wrap_lines(self._line_source, point_size)
cy = _rendered_size("Ty", point_size, self._font_file)[1]
return (cy * len(text_lines)) <= self._height
return predicate
|
Return function taking an integer point size argument.
The function returns |True| if the text in this fitter can be wrapped to fit
entirely within its extents when rendered at that point size.
|
_fits_inside_predicate
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def predicate(point_size):
"""Return |True| when text in `line_source` can be wrapped to fit.
Fit means text can be broken into lines that fit entirely within `extents`
when rendered at `point_size` using the font defined in `font_file`.
"""
text_lines = self._wrap_lines(self._line_source, point_size)
cy = _rendered_size("Ty", point_size, self._font_file)[1]
return (cy * len(text_lines)) <= self._height
|
Return |True| when text in `line_source` can be wrapped to fit.
Fit means text can be broken into lines that fit entirely within `extents`
when rendered at `point_size` using the font defined in `font_file`.
|
predicate
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def _wrap_lines(self, line_source, point_size):
"""
Return a sequence of str values representing the text in
*line_source* wrapped within this fitter when rendered at
*point_size*.
"""
text, remainder = self._break_line(line_source, point_size)
lines = [text]
if remainder:
lines.extend(self._wrap_lines(remainder, point_size))
return lines
|
Return a sequence of str values representing the text in
*line_source* wrapped within this fitter when rendered at
*point_size*.
|
_wrap_lines
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def find_max(self, predicate, max_=None):
"""
Return the largest item in or under this node that satisfies
*predicate*.
"""
if predicate(self.value):
max_ = self.value
next_node = self._greater
else:
next_node = self._lesser
if next_node is None:
return max_
return next_node.find_max(predicate, max_)
|
Return the largest item in or under this node that satisfies
*predicate*.
|
find_max
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def from_ordered_sequence(cls, iseq):
"""
Return the root of a balanced binary search tree populated with the
values in iterable *iseq*.
"""
seq = list(iseq)
# optimize for usually all fits by making longest first
bst = cls(seq.pop())
bst._insert_from_ordered_sequence(seq)
return bst
|
Return the root of a balanced binary search tree populated with the
values in iterable *iseq*.
|
from_ordered_sequence
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def insert(self, value):
"""
Insert a new node containing *value* into this tree such that its
structure as a binary search tree is preserved.
"""
side = "_lesser" if value < self.value else "_greater"
child = getattr(self, side)
if child is None:
setattr(self, side, _BinarySearchTree(value))
else:
child.insert(value)
|
Insert a new node containing *value* into this tree such that its
structure as a binary search tree is preserved.
|
insert
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def _bisect(seq):
"""
Return a (medial_value, greater_values, lesser_values) 3-tuple
obtained by bisecting sequence *seq*.
"""
if len(seq) == 0:
return [], None, []
mid_idx = int(len(seq) / 2)
mid = seq[mid_idx]
greater = seq[mid_idx + 1 :]
lesser = seq[:mid_idx]
return mid, greater, lesser
|
Return a (medial_value, greater_values, lesser_values) 3-tuple
obtained by bisecting sequence *seq*.
|
_bisect
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def _insert_from_ordered_sequence(self, seq):
"""
Insert the new values contained in *seq* into this tree such that
a balanced tree is produced.
"""
if len(seq) == 0:
return
mid, greater, lesser = self._bisect(seq)
self.insert(mid)
self._insert_from_ordered_sequence(greater)
self._insert_from_ordered_sequence(lesser)
|
Insert the new values contained in *seq* into this tree such that
a balanced tree is produced.
|
_insert_from_ordered_sequence
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def __iter__(self):
"""
Generate a (text, remainder) pair for each possible even-word line
break in this line source, where *text* is a str value and remainder
is a |_LineSource| value.
"""
words = self._text.split()
for idx in range(1, len(words) + 1):
line_text = " ".join(words[:idx])
remainder_text = " ".join(words[idx:])
remainder = _LineSource(remainder_text)
yield _Line(line_text, remainder)
|
Generate a (text, remainder) pair for each possible even-word line
break in this line source, where *text* is a str value and remainder
is a |_LineSource| value.
|
__iter__
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def _rendered_size(text, point_size, font_file):
"""
Return a (width, height) pair representing the size of *text* in English
Metric Units (EMU) when rendered at *point_size* in the font defined in
*font_file*.
"""
emu_per_inch = 914400
px_per_inch = 72.0
font = _Fonts.font(font_file, point_size)
try:
px_width, px_height = font.getsize(text)
except AttributeError:
left, top, right, bottom = font.getbbox(text)
px_width, px_height = right - left, bottom - top
emu_width = int(px_width / px_per_inch * emu_per_inch)
emu_height = int(px_height / px_per_inch * emu_per_inch)
return emu_width, emu_height
|
Return a (width, height) pair representing the size of *text* in English
Metric Units (EMU) when rendered at *point_size* in the font defined in
*font_file*.
|
_rendered_size
|
python
|
scanny/python-pptx
|
src/pptx/text/layout.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/layout.py
|
MIT
|
def add_paragraph(self):
"""
Return new |_Paragraph| instance appended to the sequence of
paragraphs contained in this text frame.
"""
p = self._txBody.add_p()
return _Paragraph(p, self)
|
Return new |_Paragraph| instance appended to the sequence of
paragraphs contained in this text frame.
|
add_paragraph
|
python
|
scanny/python-pptx
|
src/pptx/text/text.py
|
https://github.com/scanny/python-pptx/blob/master/src/pptx/text/text.py
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.