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 add_cxnSp( self, id_: int, name: str, type_member: MSO_CONNECTOR_TYPE, x: int, y: int, cx: int, cy: int, flipH: bool, flipV: bool, ) -> CT_Connector: """Return new `p:cxnSp` appended to the group/shapetree with the specified attribues.""" prst = MSO_CONNECTOR_TYPE.to_xml(type_member) cxnSp = CT_Connector.new_cxnSp(id_, name, prst, x, y, cx, cy, flipH, flipV) self.insert_element_before(cxnSp, "p:extLst") return cxnSp
Return new `p:cxnSp` appended to the group/shapetree with the specified attribues.
add_cxnSp
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def add_freeform_sp(self, x: int, y: int, cx: int, cy: int) -> CT_Shape: """Append a new freeform `p:sp` with specified position and size.""" shape_id = self._next_shape_id name = "Freeform %d" % (shape_id - 1,) sp = CT_Shape.new_freeform_sp(shape_id, name, x, y, cx, cy) self.insert_element_before(sp, "p:extLst") return sp
Append a new freeform `p:sp` with specified position and size.
add_freeform_sp
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def add_grpSp(self) -> CT_GroupShape: """Return `p:grpSp` element newly appended to this shape tree. The element contains no sub-shapes, is positioned at (0, 0), and has width and height of zero. """ shape_id = self._next_shape_id name = "Group %d" % (shape_id - 1,) grpSp = CT_GroupShape.new_grpSp(shape_id, name) self.insert_element_before(grpSp, "p:extLst") return grpSp
Return `p:grpSp` element newly appended to this shape tree. The element contains no sub-shapes, is positioned at (0, 0), and has width and height of zero.
add_grpSp
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def add_pic( self, id_: int, name: str, desc: str, rId: str, x: int, y: int, cx: int, cy: int ) -> CT_Picture: """Append a `p:pic` shape to the group/shapetree having properties as specified in call.""" pic = CT_Picture.new_pic(id_, name, desc, rId, x, y, cx, cy) self.insert_element_before(pic, "p:extLst") return pic
Append a `p:pic` shape to the group/shapetree having properties as specified in call.
add_pic
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def add_placeholder( self, id_: int, name: str, ph_type: PP_PLACEHOLDER, orient: str, sz: str, idx: int ) -> CT_Shape: """Append a newly-created placeholder `p:sp` shape having the specified properties.""" sp = CT_Shape.new_placeholder_sp(id_, name, ph_type, orient, sz, idx) self.insert_element_before(sp, "p:extLst") return sp
Append a newly-created placeholder `p:sp` shape having the specified properties.
add_placeholder
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def add_table( self, id_: int, name: str, rows: int, cols: int, x: int, y: int, cx: int, cy: int ) -> CT_GraphicalObjectFrame: """Append a `p:graphicFrame` shape containing a table as specified in call.""" graphicFrame = CT_GraphicalObjectFrame.new_table_graphicFrame( id_, name, rows, cols, x, y, cx, cy ) self.insert_element_before(graphicFrame, "p:extLst") return graphicFrame
Append a `p:graphicFrame` shape containing a table as specified in call.
add_table
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def add_textbox(self, id_: int, name: str, x: int, y: int, cx: int, cy: int) -> CT_Shape: """Append a newly-created textbox `p:sp` shape having the specified position and size.""" sp = CT_Shape.new_textbox_sp(id_, name, x, y, cx, cy) self.insert_element_before(sp, "p:extLst") return sp
Append a newly-created textbox `p:sp` shape having the specified position and size.
add_textbox
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def iter_ph_elms(self): """Generate each placeholder shape child element in document order.""" for e in self.iter_shape_elms(): if e.has_ph_elm: yield e
Generate each placeholder shape child element in document order.
iter_ph_elms
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def iter_shape_elms(self) -> Iterator[ShapeElement]: """Generate each child of this `p:spTree` element that corresponds to a shape. Items appear in XML document order. """ for elm in self.iterchildren(): if elm.tag in self._shape_tags: yield elm
Generate each child of this `p:spTree` element that corresponds to a shape. Items appear in XML document order.
iter_shape_elms
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def max_shape_id(self) -> int: """Maximum int value assigned as @id in this slide. This is generally a shape-id, but ids can be assigned to other objects so we just check all @id values anywhere in the document (XML id-values have document scope). In practice, its minimum value is 1 because the spTree element itself is always assigned id="1". """ id_str_lst = self.xpath("//@id") used_ids = [int(id_str) for id_str in id_str_lst if id_str.isdigit()] return max(used_ids) if used_ids else 0
Maximum int value assigned as @id in this slide. This is generally a shape-id, but ids can be assigned to other objects so we just check all @id values anywhere in the document (XML id-values have document scope). In practice, its minimum value is 1 because the spTree element itself is always assigned id="1".
max_shape_id
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def new_grpSp(cls, id_: int, name: str) -> CT_GroupShape: """Return new "loose" `p:grpSp` element having `id_` and `name`.""" xml = ( "<p:grpSp %s>\n" " <p:nvGrpSpPr>\n" ' <p:cNvPr id="%%d" name="%%s"/>\n' " <p:cNvGrpSpPr/>\n" " <p:nvPr/>\n" " </p:nvGrpSpPr>\n" " <p:grpSpPr>\n" " <a:xfrm>\n" ' <a:off x="0" y="0"/>\n' ' <a:ext cx="0" cy="0"/>\n' ' <a:chOff x="0" y="0"/>\n' ' <a:chExt cx="0" cy="0"/>\n' " </a:xfrm>\n" " </p:grpSpPr>\n" "</p:grpSp>" % nsdecls("a", "p", "r") ) % (id_, name) grpSp = parse_xml(xml) return grpSp
Return new "loose" `p:grpSp` element having `id_` and `name`.
new_grpSp
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def recalculate_extents(self) -> None: """Adjust x, y, cx, and cy to incorporate all contained shapes. This would typically be called when a contained shape is added, removed, or its position or size updated. This method is recursive "upwards" since a change in a group shape can change the position and size of its containing group. """ if not self.tag == qn("p:grpSp"): return x, y, cx, cy = self._child_extents self.chOff.x = self.x = x self.chOff.y = self.y = y self.chExt.cx = self.cx = cx self.chExt.cy = self.cy = cy self.getparent().recalculate_extents()
Adjust x, y, cx, and cy to incorporate all contained shapes. This would typically be called when a contained shape is added, removed, or its position or size updated. This method is recursive "upwards" since a change in a group shape can change the position and size of its containing group.
recalculate_extents
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def _child_extents(self) -> tuple[int, int, int, int]: """(x, y, cx, cy) tuple representing net position and size. The values are formed as a composite of the contained child shapes. """ child_shape_elms = list(self.iter_shape_elms()) if not child_shape_elms: return Emu(0), Emu(0), Emu(0), Emu(0) min_x = min([xSp.x for xSp in child_shape_elms]) min_y = min([xSp.y for xSp in child_shape_elms]) max_x = max([(xSp.x + xSp.cx) for xSp in child_shape_elms]) max_y = max([(xSp.y + xSp.cy) for xSp in child_shape_elms]) x = min_x y = min_y cx = max_x - min_x cy = max_y - min_y return x, y, cx, cy
(x, y, cx, cy) tuple representing net position and size. The values are formed as a composite of the contained child shapes.
_child_extents
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def _next_shape_id(self) -> int: """Return unique shape id suitable for use with a new shape element. The returned id is the next available positive integer drawing object id in shape tree, starting from 1 and making use of any gaps in numbering. In practice, the minimum id is 2 because the spTree element itself is always assigned id="1". """ id_str_lst = self.xpath("//@id") used_ids = [int(id_str) for id_str in id_str_lst if id_str.isdigit()] for n in range(1, len(used_ids) + 2): if n not in used_ids: return n
Return unique shape id suitable for use with a new shape element. The returned id is the next available positive integer drawing object id in shape tree, starting from 1 and making use of any gaps in numbering. In practice, the minimum id is 2 because the spTree element itself is always assigned id="1".
_next_shape_id
python
scanny/python-pptx
src/pptx/oxml/shapes/groupshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/groupshape.py
MIT
def blip_rId(self) -> str | None: """Value of `p:blipFill/a:blip/@r:embed`. Returns |None| if not present. """ blip = self.blipFill.blip if blip is not None and blip.rEmbed is not None: return blip.rEmbed return None
Value of `p:blipFill/a:blip/@r:embed`. Returns |None| if not present.
blip_rId
python
scanny/python-pptx
src/pptx/oxml/shapes/picture.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/picture.py
MIT
def new_video_pic( cls, shape_id: int, shape_name: str, video_rId: str, media_rId: str, poster_frame_rId: str, x: Length, y: Length, cx: Length, cy: Length, ) -> CT_Picture: """Return a new `p:pic` populated with the specified video.""" return cast( CT_Picture, parse_xml( cls._pic_video_tmpl() % ( shape_id, shape_name, video_rId, media_rId, poster_frame_rId, x, y, cx, cy, ) ), )
Return a new `p:pic` populated with the specified video.
new_video_pic
python
scanny/python-pptx
src/pptx/oxml/shapes/picture.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/picture.py
MIT
def _fill_cropping(self, image_size, view_size): """ Return a (left, top, right, bottom) 4-tuple containing the cropping values required to display an image of *image_size* in *view_size* when stretched proportionately. Each value is a percentage expressed as a fraction of 1.0, e.g. 0.425 represents 42.5%. *image_size* and *view_size* are each (width, height) pairs. """ def aspect_ratio(width, height): return width / height ar_view = aspect_ratio(*view_size) ar_image = aspect_ratio(*image_size) if ar_view < ar_image: # image too wide crop = (1.0 - (ar_view / ar_image)) / 2.0 return (crop, 0.0, crop, 0.0) if ar_view > ar_image: # image too tall crop = (1.0 - (ar_image / ar_view)) / 2.0 return (0.0, crop, 0.0, crop) return (0.0, 0.0, 0.0, 0.0)
Return a (left, top, right, bottom) 4-tuple containing the cropping values required to display an image of *image_size* in *view_size* when stretched proportionately. Each value is a percentage expressed as a fraction of 1.0, e.g. 0.425 represents 42.5%. *image_size* and *view_size* are each (width, height) pairs.
_fill_cropping
python
scanny/python-pptx
src/pptx/oxml/shapes/picture.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/picture.py
MIT
def _srcRect_x(self, attr_name): """ Value of `p:blipFill/a:srcRect/@{attr_name}` or 0.0 if not present. """ srcRect = self.blipFill.srcRect if srcRect is None: return 0.0 return getattr(srcRect, attr_name)
Value of `p:blipFill/a:srcRect/@{attr_name}` or 0.0 if not present.
_srcRect_x
python
scanny/python-pptx
src/pptx/oxml/shapes/picture.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/picture.py
MIT
def ph(self) -> CT_Placeholder | None: """The `p:ph` descendant element if there is one, None otherwise.""" ph_elms = self.xpath("./*[1]/p:nvPr/p:ph") if len(ph_elms) == 0: return None return ph_elms[0]
The `p:ph` descendant element if there is one, None otherwise.
ph
python
scanny/python-pptx
src/pptx/oxml/shapes/shared.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/shared.py
MIT
def ph_idx(self) -> int: """Integer value of placeholder idx attribute. Raises |ValueError| if shape is not a placeholder. """ ph = self.ph if ph is None: raise ValueError("not a placeholder shape") return ph.idx
Integer value of placeholder idx attribute. Raises |ValueError| if shape is not a placeholder.
ph_idx
python
scanny/python-pptx
src/pptx/oxml/shapes/shared.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/shared.py
MIT
def ph_orient(self) -> str: """Placeholder orientation, e.g. 'vert'. Raises |ValueError| if shape is not a placeholder. """ ph = self.ph if ph is None: raise ValueError("not a placeholder shape") return ph.orient
Placeholder orientation, e.g. 'vert'. Raises |ValueError| if shape is not a placeholder.
ph_orient
python
scanny/python-pptx
src/pptx/oxml/shapes/shared.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/shared.py
MIT
def ph_sz(self) -> str: """Placeholder size, e.g. ST_PlaceholderSize.HALF. Raises `ValueError` if shape is not a placeholder. """ ph = self.ph if ph is None: raise ValueError("not a placeholder shape") return ph.sz
Placeholder size, e.g. ST_PlaceholderSize.HALF. Raises `ValueError` if shape is not a placeholder.
ph_sz
python
scanny/python-pptx
src/pptx/oxml/shapes/shared.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/shared.py
MIT
def ph_type(self): """Placeholder type, e.g. ST_PlaceholderType.TITLE ('title'). Raises `ValueError` if shape is not a placeholder. """ ph = self.ph if ph is None: raise ValueError("not a placeholder shape") return ph.type
Placeholder type, e.g. ST_PlaceholderType.TITLE ('title'). Raises `ValueError` if shape is not a placeholder.
ph_type
python
scanny/python-pptx
src/pptx/oxml/shapes/shared.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/shared.py
MIT
def rot(self) -> float: """Float representing degrees this shape is rotated clockwise.""" xfrm = self.xfrm if xfrm is None or xfrm.rot is None: return 0.0 return xfrm.rot
Float representing degrees this shape is rotated clockwise.
rot
python
scanny/python-pptx
src/pptx/oxml/shapes/shared.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/shared.py
MIT
def prstDash_val(self): """Return value of `val` attribute of `a:prstDash` child. Return |None| if not present. """ prstDash = self.prstDash if prstDash is None: return None return prstDash.val
Return value of `val` attribute of `a:prstDash` child. Return |None| if not present.
prstDash_val
python
scanny/python-pptx
src/pptx/oxml/shapes/shared.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/shared.py
MIT
def cx(self): """ Shape width as an instance of Emu, or None if not present. """ cx_str_lst = self.xpath("./a:xfrm/a:ext/@cx") if not cx_str_lst: return None return Emu(cx_str_lst[0])
Shape width as an instance of Emu, or None if not present.
cx
python
scanny/python-pptx
src/pptx/oxml/shapes/shared.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/shared.py
MIT
def cy(self): """ Shape height as an instance of Emu, or None if not present. """ cy_str_lst = self.xpath("./a:xfrm/a:ext/@cy") if not cy_str_lst: return None return Emu(cy_str_lst[0])
Shape height as an instance of Emu, or None if not present.
cy
python
scanny/python-pptx
src/pptx/oxml/shapes/shared.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/shared.py
MIT
def x(self) -> Length | None: """Distance between the left edge of the slide and left edge of the shape. 0 if not present. """ x_str_lst = self.xpath("./a:xfrm/a:off/@x") if not x_str_lst: return None return Emu(x_str_lst[0])
Distance between the left edge of the slide and left edge of the shape. 0 if not present.
x
python
scanny/python-pptx
src/pptx/oxml/shapes/shared.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/shared.py
MIT
def y(self): """ The offset of the top of the shape from the top of the slide, as an instance of Emu. None if not present. """ y_str_lst = self.xpath("./a:xfrm/a:off/@y") if not y_str_lst: return None return Emu(y_str_lst[0])
The offset of the top of the shape from the top of the slide, as an instance of Emu. None if not present.
y
python
scanny/python-pptx
src/pptx/oxml/shapes/shared.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/oxml/shapes/shared.py
MIT
def new(cls, chart_type: XL_CHART_TYPE, chart_data: ChartData, package: Package): """Return new |ChartPart| instance added to `package`. Returned chart-part contains a chart of `chart_type` depicting `chart_data`. """ chart_part = cls.load( package.next_partname(cls.partname_template), CT.DML_CHART, package, chart_data.xml_bytes(chart_type), ) chart_part.chart_workbook.update_from_xlsx_blob(chart_data.xlsx_blob) return chart_part
Return new |ChartPart| instance added to `package`. Returned chart-part contains a chart of `chart_type` depicting `chart_data`.
new
python
scanny/python-pptx
src/pptx/parts/chart.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/chart.py
MIT
def update_from_xlsx_blob(self, xlsx_blob): """ Replace the Excel spreadsheet in the related |EmbeddedXlsxPart| with the Excel binary in *xlsx_blob*, adding a new |EmbeddedXlsxPart| if there isn't one. """ xlsx_part = self.xlsx_part if xlsx_part is None: self.xlsx_part = EmbeddedXlsxPart.new(xlsx_blob, self._chart_part.package) return xlsx_part.blob = xlsx_blob
Replace the Excel spreadsheet in the related |EmbeddedXlsxPart| with the Excel binary in *xlsx_blob*, adding a new |EmbeddedXlsxPart| if there isn't one.
update_from_xlsx_blob
python
scanny/python-pptx
src/pptx/parts/chart.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/chart.py
MIT
def xlsx_part(self): """Optional |EmbeddedXlsxPart| object containing data for this chart. This related part has its rId at `c:chartSpace/c:externalData/@rId`. This value is |None| if there is no `<c:externalData>` element. """ xlsx_part_rId = self._chartSpace.xlsx_part_rId return None if xlsx_part_rId is None else self._chart_part.related_part(xlsx_part_rId)
Optional |EmbeddedXlsxPart| object containing data for this chart. This related part has its rId at `c:chartSpace/c:externalData/@rId`. This value is |None| if there is no `<c:externalData>` element.
xlsx_part
python
scanny/python-pptx
src/pptx/parts/chart.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/chart.py
MIT
def xlsx_part(self, xlsx_part): """ Set the related |EmbeddedXlsxPart| to *xlsx_part*. Assume one does not already exist. """ rId = self._chart_part.relate_to(xlsx_part, RT.PACKAGE) externalData = self._chartSpace.get_or_add_externalData() externalData.rId = rId
Set the related |EmbeddedXlsxPart| to *xlsx_part*. Assume one does not already exist.
xlsx_part
python
scanny/python-pptx
src/pptx/parts/chart.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/chart.py
MIT
def default(cls, package: Package): """Return default new |CorePropertiesPart| instance suitable as starting point. This provides a base for adding core-properties to a package that doesn't yet have any. """ core_props = cls._new(package) core_props.title = "PowerPoint Presentation" core_props.last_modified_by = "python-pptx" core_props.revision = 1 core_props.modified = dt.datetime.now(dt.timezone.utc).replace(tzinfo=None) return core_props
Return default new |CorePropertiesPart| instance suitable as starting point. This provides a base for adding core-properties to a package that doesn't yet have any.
default
python
scanny/python-pptx
src/pptx/parts/coreprops.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/coreprops.py
MIT
def factory(cls, prog_id: PROG_ID | str, object_blob: bytes, package: Package): """Return a new |EmbeddedPackagePart| subclass instance added to *package*. The subclass is determined by `prog_id` which corresponds to the "application" used to open the "file-type" of `object_blob`. The returned part contains the bytes of `object_blob` and has the content-type also determined by `prog_id`. """ # --- a generic OLE object has no subclass --- if not isinstance(prog_id, PROG_ID): return cls( package.next_partname("/ppt/embeddings/oleObject%d.bin"), CT.OFC_OLE_OBJECT, package, object_blob, ) # --- A Microsoft Office file-type is a distinguished package object --- EmbeddedPartCls = { PROG_ID.DOCX: EmbeddedDocxPart, PROG_ID.PPTX: EmbeddedPptxPart, PROG_ID.XLSX: EmbeddedXlsxPart, }[prog_id] return EmbeddedPartCls.new(object_blob, package)
Return a new |EmbeddedPackagePart| subclass instance added to *package*. The subclass is determined by `prog_id` which corresponds to the "application" used to open the "file-type" of `object_blob`. The returned part contains the bytes of `object_blob` and has the content-type also determined by `prog_id`.
factory
python
scanny/python-pptx
src/pptx/parts/embeddedpackage.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/embeddedpackage.py
MIT
def new(cls, blob: bytes, package: Package): """Return new |EmbeddedPackagePart| subclass object. The returned part object contains `blob` and is added to `package`. """ return cls( package.next_partname(cls.partname_template), cls.content_type, package, blob, )
Return new |EmbeddedPackagePart| subclass object. The returned part object contains `blob` and is added to `package`.
new
python
scanny/python-pptx
src/pptx/parts/embeddedpackage.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/embeddedpackage.py
MIT
def new(cls, package: Package, image: Image) -> ImagePart: """Return new |ImagePart| instance containing `image`. `image` is an |Image| object. """ return cls( package.next_image_partname(image.ext), image.content_type, package, image.blob, image.filename, )
Return new |ImagePart| instance containing `image`. `image` is an |Image| object.
new
python
scanny/python-pptx
src/pptx/parts/image.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/image.py
MIT
def desc(self) -> str: """The filename associated with this image. Either the filename of the original image or a generic name of the form `image.ext` where `ext` is appropriate to the image file format, e.g. `'jpg'`. An image created using a path will have that filename; one created with a file-like object will have a generic name. """ # -- return generic filename if original filename is unknown -- if self._filename is None: return f"image.{self.ext}" return self._filename
The filename associated with this image. Either the filename of the original image or a generic name of the form `image.ext` where `ext` is appropriate to the image file format, e.g. `'jpg'`. An image created using a path will have that filename; one created with a file-like object will have a generic name.
desc
python
scanny/python-pptx
src/pptx/parts/image.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/image.py
MIT
def scale(self, scaled_cx: int | None, scaled_cy: int | None) -> tuple[int, int]: """Return scaled image dimensions in EMU based on the combination of parameters supplied. If `scaled_cx` and `scaled_cy` are both |None|, the native image size is returned. If neither `scaled_cx` nor `scaled_cy` is |None|, their values are returned unchanged. If a value is provided for either `scaled_cx` or `scaled_cy` and the other is |None|, the missing value is calculated such that the image's aspect ratio is preserved. """ image_cx, image_cy = self._native_size if scaled_cx and scaled_cy: return scaled_cx, scaled_cy if scaled_cx and not scaled_cy: scaling_factor = float(scaled_cx) / float(image_cx) scaled_cy = int(round(image_cy * scaling_factor)) return scaled_cx, scaled_cy if not scaled_cx and scaled_cy: scaling_factor = float(scaled_cy) / float(image_cy) scaled_cx = int(round(image_cx * scaling_factor)) return scaled_cx, scaled_cy # -- only remaining case is both `scaled_cx` and `scaled_cy` are `None` -- return image_cx, image_cy
Return scaled image dimensions in EMU based on the combination of parameters supplied. If `scaled_cx` and `scaled_cy` are both |None|, the native image size is returned. If neither `scaled_cx` nor `scaled_cy` is |None|, their values are returned unchanged. If a value is provided for either `scaled_cx` or `scaled_cy` and the other is |None|, the missing value is calculated such that the image's aspect ratio is preserved.
scale
python
scanny/python-pptx
src/pptx/parts/image.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/image.py
MIT
def _native_size(self) -> tuple[Length, Length]: """A (width, height) 2-tuple representing the native dimensions of the image in EMU. Calculated based on the image DPI value, if present, assuming 72 dpi as a default. """ EMU_PER_INCH = 914400 horz_dpi, vert_dpi = self._dpi width_px, height_px = self._px_size width = EMU_PER_INCH * width_px / horz_dpi height = EMU_PER_INCH * height_px / vert_dpi return Emu(int(width)), Emu(int(height))
A (width, height) 2-tuple representing the native dimensions of the image in EMU. Calculated based on the image DPI value, if present, assuming 72 dpi as a default.
_native_size
python
scanny/python-pptx
src/pptx/parts/image.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/image.py
MIT
def from_file(cls, image_file: str | IO[bytes]) -> Image: """Return a new |Image| object loaded from `image_file`. `image_file` can be either a path (str) or a file-like object. """ if isinstance(image_file, str): # treat image_file as a path with open(image_file, "rb") as f: blob = f.read() filename = os.path.basename(image_file) else: # assume image_file is a file-like object # ---reposition file cursor if it has one--- if callable(getattr(image_file, "seek")): image_file.seek(0) blob = image_file.read() filename = None return cls.from_blob(blob, filename)
Return a new |Image| object loaded from `image_file`. `image_file` can be either a path (str) or a file-like object.
from_file
python
scanny/python-pptx
src/pptx/parts/image.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/image.py
MIT
def dpi(self) -> tuple[int, int]: """A (horz_dpi, vert_dpi) 2-tuple specifying the dots-per-inch resolution of this image. A default value of (72, 72) is used if the dpi is not specified in the image file. """ def int_dpi(dpi: Any): """Return an integer dots-per-inch value corresponding to `dpi`. If `dpi` is |None|, a non-numeric type, less than 1 or greater than 2048, 72 is returned. """ try: int_dpi = int(round(float(dpi))) if int_dpi < 1 or int_dpi > 2048: int_dpi = 72 except (TypeError, ValueError): int_dpi = 72 return int_dpi def normalize_pil_dpi(pil_dpi: tuple[int, int] | None): """Return a (horz_dpi, vert_dpi) 2-tuple corresponding to `pil_dpi`. The value for the 'dpi' key in the `info` dict of a PIL image. If the 'dpi' key is not present or contains an invalid value, `(72, 72)` is returned. """ if isinstance(pil_dpi, tuple): return (int_dpi(pil_dpi[0]), int_dpi(pil_dpi[1])) return (72, 72) return normalize_pil_dpi(self._pil_props[2])
A (horz_dpi, vert_dpi) 2-tuple specifying the dots-per-inch resolution of this image. A default value of (72, 72) is used if the dpi is not specified in the image file.
dpi
python
scanny/python-pptx
src/pptx/parts/image.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/image.py
MIT
def int_dpi(dpi: Any): """Return an integer dots-per-inch value corresponding to `dpi`. If `dpi` is |None|, a non-numeric type, less than 1 or greater than 2048, 72 is returned. """ try: int_dpi = int(round(float(dpi))) if int_dpi < 1 or int_dpi > 2048: int_dpi = 72 except (TypeError, ValueError): int_dpi = 72 return int_dpi
Return an integer dots-per-inch value corresponding to `dpi`. If `dpi` is |None|, a non-numeric type, less than 1 or greater than 2048, 72 is returned.
int_dpi
python
scanny/python-pptx
src/pptx/parts/image.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/image.py
MIT
def normalize_pil_dpi(pil_dpi: tuple[int, int] | None): """Return a (horz_dpi, vert_dpi) 2-tuple corresponding to `pil_dpi`. The value for the 'dpi' key in the `info` dict of a PIL image. If the 'dpi' key is not present or contains an invalid value, `(72, 72)` is returned. """ if isinstance(pil_dpi, tuple): return (int_dpi(pil_dpi[0]), int_dpi(pil_dpi[1])) return (72, 72)
Return a (horz_dpi, vert_dpi) 2-tuple corresponding to `pil_dpi`. The value for the 'dpi' key in the `info` dict of a PIL image. If the 'dpi' key is not present or contains an invalid value, `(72, 72)` is returned.
normalize_pil_dpi
python
scanny/python-pptx
src/pptx/parts/image.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/image.py
MIT
def ext(self) -> str: """Canonical file extension for this image e.g. `'png'`. The returned extension is all lowercase and is the canonical extension for the content type of this image, regardless of what extension may have been used in its filename, if any. """ ext_map = { "BMP": "bmp", "GIF": "gif", "JPEG": "jpg", "PNG": "png", "TIFF": "tiff", "WMF": "wmf", } format = self._format if format not in ext_map: tmpl = "unsupported image format, expected one of: %s, got '%s'" raise ValueError(tmpl % (ext_map.keys(), format)) return ext_map[format]
Canonical file extension for this image e.g. `'png'`. The returned extension is all lowercase and is the canonical extension for the content type of this image, regardless of what extension may have been used in its filename, if any.
ext
python
scanny/python-pptx
src/pptx/parts/image.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/image.py
MIT
def _pil_props(self) -> tuple[str | None, tuple[int, int], tuple[int, int] | None]: """tuple of image properties extracted from this image using Pillow.""" stream = io.BytesIO(self._blob) pil_image = PIL_Image.open(stream) # pyright: ignore[reportUnknownMemberType] format = pil_image.format width_px, height_px = pil_image.size dpi = cast( "tuple[int, int] | None", pil_image.info.get("dpi"), # pyright: ignore[reportUnknownMemberType] ) stream.close() return (format, (width_px, height_px), dpi)
tuple of image properties extracted from this image using Pillow.
_pil_props
python
scanny/python-pptx
src/pptx/parts/image.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/image.py
MIT
def new(cls, package, media): """Return new |MediaPart| instance containing `media`. `media` must be a |Media| object. """ return cls( package.next_media_partname(media.ext), media.content_type, package, media.blob, )
Return new |MediaPart| instance containing `media`. `media` must be a |Media| object.
new
python
scanny/python-pptx
src/pptx/parts/media.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/media.py
MIT
def add_slide(self, slide_layout: SlideLayout): """Return (rId, slide) pair of a newly created blank slide. New slide inherits appearance from `slide_layout`. """ partname = self._next_slide_partname slide_layout_part = slide_layout.part slide_part = SlidePart.new(partname, self.package, slide_layout_part) rId = self.relate_to(slide_part, RT.SLIDE) return rId, slide_part.slide
Return (rId, slide) pair of a newly created blank slide. New slide inherits appearance from `slide_layout`.
add_slide
python
scanny/python-pptx
src/pptx/parts/presentation.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/presentation.py
MIT
def get_slide(self, slide_id: int) -> Slide | None: """Return optional related |Slide| object identified by `slide_id`. Returns |None| if no slide with `slide_id` is related to this presentation. """ for sldId in self._element.sldIdLst: if sldId.id == slide_id: return self.related_part(sldId.rId).slide return None
Return optional related |Slide| object identified by `slide_id`. Returns |None| if no slide with `slide_id` is related to this presentation.
get_slide
python
scanny/python-pptx
src/pptx/parts/presentation.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/presentation.py
MIT
def notes_master_part(self) -> NotesMasterPart: """Return the |NotesMasterPart| object for this presentation. If the presentation does not have a notes master, one is created from a default template. The same single instance is returned on each call. """ try: return self.part_related_by(RT.NOTES_MASTER) except KeyError: notes_master_part = NotesMasterPart.create_default(self.package) self.relate_to(notes_master_part, RT.NOTES_MASTER) return notes_master_part
Return the |NotesMasterPart| object for this presentation. If the presentation does not have a notes master, one is created from a default template. The same single instance is returned on each call.
notes_master_part
python
scanny/python-pptx
src/pptx/parts/presentation.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/presentation.py
MIT
def rename_slide_parts(self, rIds: Iterable[str]): """Assign incrementing partnames to the slide parts identified by `rIds`. Partnames are like `/ppt/slides/slide9.xml` and are assigned in the order their id appears in the `rIds` sequence. The name portion is always `slide`. The number part forms a continuous sequence starting at 1 (e.g. 1, 2, ... 10, ...). The extension is always `.xml`. """ for idx, rId in enumerate(rIds): slide_part = self.related_part(rId) slide_part.partname = PackURI("/ppt/slides/slide%d.xml" % (idx + 1))
Assign incrementing partnames to the slide parts identified by `rIds`. Partnames are like `/ppt/slides/slide9.xml` and are assigned in the order their id appears in the `rIds` sequence. The name portion is always `slide`. The number part forms a continuous sequence starting at 1 (e.g. 1, 2, ... 10, ...). The extension is always `.xml`.
rename_slide_parts
python
scanny/python-pptx
src/pptx/parts/presentation.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/presentation.py
MIT
def slide_id(self, slide_part): """Return the slide-id associated with `slide_part`.""" for sldId in self._element.sldIdLst: if self.related_part(sldId.rId) is slide_part: return sldId.id raise ValueError("matching slide_part not found")
Return the slide-id associated with `slide_part`.
slide_id
python
scanny/python-pptx
src/pptx/parts/presentation.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/presentation.py
MIT
def _next_slide_partname(self): """Return |PackURI| instance containing next available slide partname.""" sldIdLst = self._element.get_or_add_sldIdLst() partname_str = "/ppt/slides/slide%d.xml" % (len(sldIdLst) + 1) return PackURI(partname_str)
Return |PackURI| instance containing next available slide partname.
_next_slide_partname
python
scanny/python-pptx
src/pptx/parts/presentation.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/presentation.py
MIT
def get_or_add_image_part(self, image_file: str | IO[bytes]): """Return `(image_part, rId)` pair corresponding to `image_file`. The returned |ImagePart| object contains the image in `image_file` and is related to this slide with the key `rId`. If either the image part or relationship already exists, they are reused, otherwise they are newly created. """ image_part = self._package.get_or_add_image_part(image_file) rId = self.relate_to(image_part, RT.IMAGE) return image_part, rId
Return `(image_part, rId)` pair corresponding to `image_file`. The returned |ImagePart| object contains the image in `image_file` and is related to this slide with the key `rId`. If either the image part or relationship already exists, they are reused, otherwise they are newly created.
get_or_add_image_part
python
scanny/python-pptx
src/pptx/parts/slide.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/slide.py
MIT
def create_default(cls, package): """ Create and return a default notes master part, including creating the new theme it requires. """ notes_master_part = cls._new(package) theme_part = cls._new_theme_part(package) notes_master_part.relate_to(theme_part, RT.THEME) return notes_master_part
Create and return a default notes master part, including creating the new theme it requires.
create_default
python
scanny/python-pptx
src/pptx/parts/slide.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/slide.py
MIT
def _new(cls, package): """ Create and return a standalone, default notes master part based on the built-in template (without any related parts, such as theme). """ return NotesMasterPart( PackURI("/ppt/notesMasters/notesMaster1.xml"), CT.PML_NOTES_MASTER, package, CT_NotesMaster.new_default(), )
Create and return a standalone, default notes master part based on the built-in template (without any related parts, such as theme).
_new
python
scanny/python-pptx
src/pptx/parts/slide.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/slide.py
MIT
def _new_theme_part(cls, package): """Return new default theme-part suitable for use with a notes master.""" return XmlPart( package.next_partname("/ppt/theme/theme%d.xml"), CT.OFC_THEME, package, CT_OfficeStyleSheet.new_default(), )
Return new default theme-part suitable for use with a notes master.
_new_theme_part
python
scanny/python-pptx
src/pptx/parts/slide.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/slide.py
MIT
def new(cls, package, slide_part): """Return new |NotesSlidePart| for the slide in `slide_part`. The new notes-slide part is based on the (singleton) notes master and related to both the notes-master part and `slide_part`. If no notes-master is present, one is created based on the default template. """ notes_master_part = package.presentation_part.notes_master_part notes_slide_part = cls._add_notes_slide_part(package, slide_part, notes_master_part) notes_slide = notes_slide_part.notes_slide notes_slide.clone_master_placeholders(notes_master_part.notes_master) return notes_slide_part
Return new |NotesSlidePart| for the slide in `slide_part`. The new notes-slide part is based on the (singleton) notes master and related to both the notes-master part and `slide_part`. If no notes-master is present, one is created based on the default template.
new
python
scanny/python-pptx
src/pptx/parts/slide.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/slide.py
MIT
def _add_notes_slide_part(cls, package, slide_part, notes_master_part): """Create and return a new notes-slide part. The return part is fully related, but has no shape content (i.e. placeholders not cloned). """ notes_slide_part = NotesSlidePart( package.next_partname("/ppt/notesSlides/notesSlide%d.xml"), CT.PML_NOTES_SLIDE, package, CT_NotesSlide.new(), ) notes_slide_part.relate_to(notes_master_part, RT.NOTES_MASTER) notes_slide_part.relate_to(slide_part, RT.SLIDE) return notes_slide_part
Create and return a new notes-slide part. The return part is fully related, but has no shape content (i.e. placeholders not cloned).
_add_notes_slide_part
python
scanny/python-pptx
src/pptx/parts/slide.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/slide.py
MIT
def new(cls, partname, package, slide_layout_part): """Return newly-created blank slide part. The new slide-part has `partname` and a relationship to `slide_layout_part`. """ slide_part = cls(partname, CT.PML_SLIDE, package, CT_Slide.new()) slide_part.relate_to(slide_layout_part, RT.SLIDE_LAYOUT) return slide_part
Return newly-created blank slide part. The new slide-part has `partname` and a relationship to `slide_layout_part`.
new
python
scanny/python-pptx
src/pptx/parts/slide.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/slide.py
MIT
def add_embedded_ole_object_part( self, prog_id: PROG_ID | str, ole_object_file: str | IO[bytes] ): """Return rId of newly-added OLE-object part formed from `ole_object_file`.""" relationship_type = RT.PACKAGE if isinstance(prog_id, PROG_ID) else RT.OLE_OBJECT return self.relate_to( EmbeddedPackagePart.factory( prog_id, self._blob_from_file(ole_object_file), self._package ), relationship_type, )
Return rId of newly-added OLE-object part formed from `ole_object_file`.
add_embedded_ole_object_part
python
scanny/python-pptx
src/pptx/parts/slide.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/slide.py
MIT
def get_or_add_video_media_part(self, video: Video) -> tuple[str, str]: """Return rIds for media and video relationships to media part. A new |MediaPart| object is created if it does not already exist (such as would occur if the same video appeared more than once in a presentation). Two relationships to the media part are created, one each with MEDIA and VIDEO relationship types. The need for two appears to be for legacy support for an earlier (pre-Office 2010) PowerPoint media embedding strategy. """ media_part = self._package.get_or_add_media_part(video) media_rId = self.relate_to(media_part, RT.MEDIA) video_rId = self.relate_to(media_part, RT.VIDEO) return media_rId, video_rId
Return rIds for media and video relationships to media part. A new |MediaPart| object is created if it does not already exist (such as would occur if the same video appeared more than once in a presentation). Two relationships to the media part are created, one each with MEDIA and VIDEO relationship types. The need for two appears to be for legacy support for an earlier (pre-Office 2010) PowerPoint media embedding strategy.
get_or_add_video_media_part
python
scanny/python-pptx
src/pptx/parts/slide.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/slide.py
MIT
def has_notes_slide(self): """ Return True if this slide has a notes slide, False otherwise. A notes slide is created by the :attr:`notes_slide` property when one doesn't exist; use this property to test for a notes slide without the possible side-effect of creating one. """ try: self.part_related_by(RT.NOTES_SLIDE) except KeyError: return False return True
Return True if this slide has a notes slide, False otherwise. A notes slide is created by the :attr:`notes_slide` property when one doesn't exist; use this property to test for a notes slide without the possible side-effect of creating one.
has_notes_slide
python
scanny/python-pptx
src/pptx/parts/slide.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/slide.py
MIT
def notes_slide(self) -> NotesSlide: """The |NotesSlide| instance associated with this slide. If the slide does not have a notes slide, a new one is created. The same single instance is returned on each call. """ try: notes_slide_part = self.part_related_by(RT.NOTES_SLIDE) except KeyError: notes_slide_part = self._add_notes_slide_part() return notes_slide_part.notes_slide
The |NotesSlide| instance associated with this slide. If the slide does not have a notes slide, a new one is created. The same single instance is returned on each call.
notes_slide
python
scanny/python-pptx
src/pptx/parts/slide.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/slide.py
MIT
def _add_notes_slide_part(self): """ Return a newly created |NotesSlidePart| object related to this slide part. Caller is responsible for ensuring this slide doesn't already have a notes slide part. """ notes_slide_part = NotesSlidePart.new(self.package, self) self.relate_to(notes_slide_part, RT.NOTES_SLIDE) return notes_slide_part
Return a newly created |NotesSlidePart| object related to this slide part. Caller is responsible for ensuring this slide doesn't already have a notes slide part.
_add_notes_slide_part
python
scanny/python-pptx
src/pptx/parts/slide.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/parts/slide.py
MIT
def _initialized_adjustments(self, prstGeom: CT_PresetGeometry2D | None) -> list[Adjustment]: """Return an initialized list of adjustment values based on the contents of `prstGeom`.""" if prstGeom is None: return [] davs = AutoShapeType.default_adjustment_values(prstGeom.prst) adjustments = [Adjustment(name, def_val) for name, def_val in davs] self._update_adjustments_with_actuals(adjustments, prstGeom.gd_lst) return adjustments
Return an initialized list of adjustment values based on the contents of `prstGeom`.
_initialized_adjustments
python
scanny/python-pptx
src/pptx/shapes/autoshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/autoshape.py
MIT
def _update_adjustments_with_actuals( adjustments: Iterable[Adjustment], guides: Iterable[CT_GeomGuide] ): """Update |Adjustment| instances in `adjustments` with actual values held in `guides`. `guides` is a list of `a:gd` elements. Guides with a name that does not match an adjustment object are skipped. """ adjustments_by_name = dict((adj.name, adj) for adj in adjustments) for gd in guides: name = gd.name actual = int(gd.fmla[4:]) try: adjustment = adjustments_by_name[name] except KeyError: continue adjustment.actual = actual return
Update |Adjustment| instances in `adjustments` with actual values held in `guides`. `guides` is a list of `a:gd` elements. Guides with a name that does not match an adjustment object are skipped.
_update_adjustments_with_actuals
python
scanny/python-pptx
src/pptx/shapes/autoshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/autoshape.py
MIT
def __new__(cls, autoshape_type_id: MSO_AUTO_SHAPE_TYPE) -> AutoShapeType: """Only create new instance on first call for content_type. After that, use cached instance. """ # -- if there's not a matching instance in the cache, create one -- if autoshape_type_id not in cls._instances: inst = super(AutoShapeType, cls).__new__(cls) cls._instances[autoshape_type_id] = inst # -- return the instance; note that __init__() gets called either way -- return cls._instances[autoshape_type_id]
Only create new instance on first call for content_type. After that, use cached instance.
__new__
python
scanny/python-pptx
src/pptx/shapes/autoshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/autoshape.py
MIT
def __init__(self, autoshape_type_id: MSO_AUTO_SHAPE_TYPE): """Initialize attributes from constant values in `pptx.spec`.""" # -- skip loading if this instance is from the cache -- if hasattr(self, "_loaded"): return # -- raise on bad autoshape_type_id -- if autoshape_type_id not in autoshape_types: raise KeyError( "no autoshape type with id '%s' in pptx.spec.autoshape_types" % autoshape_type_id ) # -- otherwise initialize new instance -- autoshape_type = autoshape_types[autoshape_type_id] self._autoshape_type_id = autoshape_type_id self._basename = autoshape_type["basename"] self._loaded = True
Initialize attributes from constant values in `pptx.spec`.
__init__
python
scanny/python-pptx
src/pptx/shapes/autoshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/autoshape.py
MIT
def auto_shape_type(self): """Enumeration value identifying the type of this auto shape. Like `MSO_SHAPE.ROUNDED_RECTANGLE`. Raises |ValueError| if this shape is not an auto shape. """ if not self._sp.is_autoshape: raise ValueError("shape is not an auto shape") return self._sp.prst
Enumeration value identifying the type of this auto shape. Like `MSO_SHAPE.ROUNDED_RECTANGLE`. Raises |ValueError| if this shape is not an auto shape.
auto_shape_type
python
scanny/python-pptx
src/pptx/shapes/autoshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/autoshape.py
MIT
def shape_type(self) -> MSO_SHAPE_TYPE: """Unique integer identifying the type of this shape, like `MSO_SHAPE_TYPE.TEXT_BOX`.""" if self.is_placeholder: return MSO_SHAPE_TYPE.PLACEHOLDER if self._sp.has_custom_geometry: return MSO_SHAPE_TYPE.FREEFORM if self._sp.is_autoshape: return MSO_SHAPE_TYPE.AUTO_SHAPE if self._sp.is_textbox: return MSO_SHAPE_TYPE.TEXT_BOX raise NotImplementedError("Shape instance of unrecognized shape type")
Unique integer identifying the type of this shape, like `MSO_SHAPE_TYPE.TEXT_BOX`.
shape_type
python
scanny/python-pptx
src/pptx/shapes/autoshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/autoshape.py
MIT
def text_frame(self): """|TextFrame| instance for this shape. Contains the text of the shape and provides access to text formatting properties. """ txBody = self._sp.get_or_add_txBody() return TextFrame(txBody, self)
|TextFrame| instance for this shape. Contains the text of the shape and provides access to text formatting properties.
text_frame
python
scanny/python-pptx
src/pptx/shapes/autoshape.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/autoshape.py
MIT
def __eq__(self, other: object) -> bool: """|True| if this shape object proxies the same element as *other*. Equality for proxy objects is defined as referring to the same XML element, whether or not they are the same proxy object instance. """ if not isinstance(other, BaseShape): return False return self._element is other._element
|True| if this shape object proxies the same element as *other*. Equality for proxy objects is defined as referring to the same XML element, whether or not they are the same proxy object instance.
__eq__
python
scanny/python-pptx
src/pptx/shapes/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/base.py
MIT
def click_action(self) -> ActionSetting: """|ActionSetting| instance providing access to click behaviors. Click behaviors are hyperlink-like behaviors including jumping to a hyperlink (web page) or to another slide in the presentation. The click action is that defined on the overall shape, not a run of text within the shape. An |ActionSetting| object is always returned, even when no click behavior is defined on the shape. """ cNvPr = self._element._nvXxPr.cNvPr # pyright: ignore[reportPrivateUsage] return ActionSetting(cNvPr, self)
|ActionSetting| instance providing access to click behaviors. Click behaviors are hyperlink-like behaviors including jumping to a hyperlink (web page) or to another slide in the presentation. The click action is that defined on the overall shape, not a run of text within the shape. An |ActionSetting| object is always returned, even when no click behavior is defined on the shape.
click_action
python
scanny/python-pptx
src/pptx/shapes/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/base.py
MIT
def has_chart(self) -> bool: """|True| if this shape is a graphic frame containing a chart object. |False| otherwise. When |True|, the chart object can be accessed using the ``.chart`` property. """ # This implementation is unconditionally False, the True version is # on GraphicFrame subclass. return False
|True| if this shape is a graphic frame containing a chart object. |False| otherwise. When |True|, the chart object can be accessed using the ``.chart`` property.
has_chart
python
scanny/python-pptx
src/pptx/shapes/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/base.py
MIT
def has_table(self) -> bool: """|True| if this shape is a graphic frame containing a table object. |False| otherwise. When |True|, the table object can be accessed using the ``.table`` property. """ # This implementation is unconditionally False, the True version is # on GraphicFrame subclass. return False
|True| if this shape is a graphic frame containing a table object. |False| otherwise. When |True|, the table object can be accessed using the ``.table`` property.
has_table
python
scanny/python-pptx
src/pptx/shapes/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/base.py
MIT
def placeholder_format(self) -> _PlaceholderFormat: """Provides access to placeholder-specific properties such as placeholder type. Raises |ValueError| on access if the shape is not a placeholder. """ ph = self._element.ph if ph is None: raise ValueError("shape is not a placeholder") return _PlaceholderFormat(ph)
Provides access to placeholder-specific properties such as placeholder type. Raises |ValueError| on access if the shape is not a placeholder.
placeholder_format
python
scanny/python-pptx
src/pptx/shapes/base.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/base.py
MIT
def begin_x(self): """ Return the X-position of the begin point of this connector, in English Metric Units (as a |Length| object). """ cxnSp = self._element x, cx, flipH = cxnSp.x, cxnSp.cx, cxnSp.flipH begin_x = x + cx if flipH else x return Emu(begin_x)
Return the X-position of the begin point of this connector, in English Metric Units (as a |Length| object).
begin_x
python
scanny/python-pptx
src/pptx/shapes/connector.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/connector.py
MIT
def begin_y(self): """ Return the Y-position of the begin point of this connector, in English Metric Units (as a |Length| object). """ cxnSp = self._element y, cy, flipV = cxnSp.y, cxnSp.cy, cxnSp.flipV begin_y = y + cy if flipV else y return Emu(begin_y)
Return the Y-position of the begin point of this connector, in English Metric Units (as a |Length| object).
begin_y
python
scanny/python-pptx
src/pptx/shapes/connector.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/connector.py
MIT
def end_x(self): """ Return the X-position of the end point of this connector, in English Metric Units (as a |Length| object). """ cxnSp = self._element x, cx, flipH = cxnSp.x, cxnSp.cx, cxnSp.flipH end_x = x if flipH else x + cx return Emu(end_x)
Return the X-position of the end point of this connector, in English Metric Units (as a |Length| object).
end_x
python
scanny/python-pptx
src/pptx/shapes/connector.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/connector.py
MIT
def end_y(self): """ Return the Y-position of the end point of this connector, in English Metric Units (as a |Length| object). """ cxnSp = self._element y, cy, flipV = cxnSp.y, cxnSp.cy, cxnSp.flipV end_y = y if flipV else y + cy return Emu(end_y)
Return the Y-position of the end point of this connector, in English Metric Units (as a |Length| object).
end_y
python
scanny/python-pptx
src/pptx/shapes/connector.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/connector.py
MIT
def _connect_begin_to(self, shape, cxn_pt_idx): """ Add or update a stCxn element for this connector that connects its begin point to the connection point of *shape* specified by *cxn_pt_idx*. """ cNvCxnSpPr = self._element.nvCxnSpPr.cNvCxnSpPr stCxn = cNvCxnSpPr.get_or_add_stCxn() stCxn.id = shape.shape_id stCxn.idx = cxn_pt_idx
Add or update a stCxn element for this connector that connects its begin point to the connection point of *shape* specified by *cxn_pt_idx*.
_connect_begin_to
python
scanny/python-pptx
src/pptx/shapes/connector.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/connector.py
MIT
def _connect_end_to(self, shape, cxn_pt_idx): """ Add or update an endCxn element for this connector that connects its end point to the connection point of *shape* specified by *cxn_pt_idx*. """ cNvCxnSpPr = self._element.nvCxnSpPr.cNvCxnSpPr endCxn = cNvCxnSpPr.get_or_add_endCxn() endCxn.id = shape.shape_id endCxn.idx = cxn_pt_idx
Add or update an endCxn element for this connector that connects its end point to the connection point of *shape* specified by *cxn_pt_idx*.
_connect_end_to
python
scanny/python-pptx
src/pptx/shapes/connector.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/connector.py
MIT
def _move_begin_to_cxn(self, shape, cxn_pt_idx): """ Move the begin point of this connector to coordinates of the connection point of *shape* specified by *cxn_pt_idx*. """ x, y, cx, cy = shape.left, shape.top, shape.width, shape.height self.begin_x, self.begin_y = { 0: (int(x + cx / 2), y), 1: (x, int(y + cy / 2)), 2: (int(x + cx / 2), y + cy), 3: (x + cx, int(y + cy / 2)), }[cxn_pt_idx]
Move the begin point of this connector to coordinates of the connection point of *shape* specified by *cxn_pt_idx*.
_move_begin_to_cxn
python
scanny/python-pptx
src/pptx/shapes/connector.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/connector.py
MIT
def _move_end_to_cxn(self, shape, cxn_pt_idx): """ Move the end point of this connector to the coordinates of the connection point of *shape* specified by *cxn_pt_idx*. """ x, y, cx, cy = shape.left, shape.top, shape.width, shape.height self.end_x, self.end_y = { 0: (int(x + cx / 2), y), 1: (x, int(y + cy / 2)), 2: (int(x + cx / 2), y + cy), 3: (x + cx, int(y + cy / 2)), }[cxn_pt_idx]
Move the end point of this connector to the coordinates of the connection point of *shape* specified by *cxn_pt_idx*.
_move_end_to_cxn
python
scanny/python-pptx
src/pptx/shapes/connector.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/connector.py
MIT
def new( cls, shapes: _BaseGroupShapes, start_x: float, start_y: float, x_scale: float, y_scale: float, ): """Return a new |FreeformBuilder| object. The initial pen location is specified (in local coordinates) by (`start_x`, `start_y`). """ return cls(shapes, Emu(int(round(start_x))), Emu(int(round(start_y))), x_scale, y_scale)
Return a new |FreeformBuilder| object. The initial pen location is specified (in local coordinates) by (`start_x`, `start_y`).
new
python
scanny/python-pptx
src/pptx/shapes/freeform.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/freeform.py
MIT
def add_line_segments(self, vertices: Iterable[tuple[float, float]], close: bool = True): """Add a straight line segment to each point in `vertices`. `vertices` must be an iterable of (x, y) pairs (2-tuples). Each x and y value is rounded to the nearest integer before use. The optional `close` parameter determines whether the resulting contour is `closed` or left `open`. Returns this |FreeformBuilder| object so it can be used in chained calls. """ for x, y in vertices: self._add_line_segment(x, y) if close: self._add_close() return self
Add a straight line segment to each point in `vertices`. `vertices` must be an iterable of (x, y) pairs (2-tuples). Each x and y value is rounded to the nearest integer before use. The optional `close` parameter determines whether the resulting contour is `closed` or left `open`. Returns this |FreeformBuilder| object so it can be used in chained calls.
add_line_segments
python
scanny/python-pptx
src/pptx/shapes/freeform.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/freeform.py
MIT
def convert_to_shape(self, origin_x: Length = Emu(0), origin_y: Length = Emu(0)): """Return new freeform shape positioned relative to specified offset. `origin_x` and `origin_y` locate the origin of the local coordinate system in slide coordinates (EMU), perhaps most conveniently by use of a |Length| object. Note that this method may be called more than once to add multiple shapes of the same geometry in different locations on the slide. """ sp = self._add_freeform_sp(origin_x, origin_y) path = self._start_path(sp) for drawing_operation in self: drawing_operation.apply_operation_to(path) return self._shapes._shape_factory(sp) # pyright: ignore[reportPrivateUsage]
Return new freeform shape positioned relative to specified offset. `origin_x` and `origin_y` locate the origin of the local coordinate system in slide coordinates (EMU), perhaps most conveniently by use of a |Length| object. Note that this method may be called more than once to add multiple shapes of the same geometry in different locations on the slide.
convert_to_shape
python
scanny/python-pptx
src/pptx/shapes/freeform.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/freeform.py
MIT
def shape_offset_x(self) -> Length: """Return x distance of shape origin from local coordinate origin. The returned integer represents the leftmost extent of the freeform shape, in local coordinates. Note that the bounding box of the shape need not start at the local origin. """ min_x = self._start_x for drawing_operation in self: if isinstance(drawing_operation, _Close): continue min_x = min(min_x, drawing_operation.x) return Emu(min_x)
Return x distance of shape origin from local coordinate origin. The returned integer represents the leftmost extent of the freeform shape, in local coordinates. Note that the bounding box of the shape need not start at the local origin.
shape_offset_x
python
scanny/python-pptx
src/pptx/shapes/freeform.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/freeform.py
MIT
def shape_offset_y(self) -> Length: """Return y distance of shape origin from local coordinate origin. The returned integer represents the topmost extent of the freeform shape, in local coordinates. Note that the bounding box of the shape need not start at the local origin. """ min_y = self._start_y for drawing_operation in self: if isinstance(drawing_operation, _Close): continue min_y = min(min_y, drawing_operation.y) return Emu(min_y)
Return y distance of shape origin from local coordinate origin. The returned integer represents the topmost extent of the freeform shape, in local coordinates. Note that the bounding box of the shape need not start at the local origin.
shape_offset_y
python
scanny/python-pptx
src/pptx/shapes/freeform.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/freeform.py
MIT
def _add_freeform_sp(self, origin_x: Length, origin_y: Length): """Add a freeform `p:sp` element having no drawing elements. `origin_x` and `origin_y` are specified in slide coordinates, and represent the location of the local coordinates origin on the slide. """ spTree = self._shapes._spTree # pyright: ignore[reportPrivateUsage] return spTree.add_freeform_sp( origin_x + self._left, origin_y + self._top, self._width, self._height )
Add a freeform `p:sp` element having no drawing elements. `origin_x` and `origin_y` are specified in slide coordinates, and represent the location of the local coordinates origin on the slide.
_add_freeform_sp
python
scanny/python-pptx
src/pptx/shapes/freeform.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/freeform.py
MIT
def _dx(self) -> Length: """Return width of this shape's path in local units.""" min_x = max_x = self._start_x for drawing_operation in self: if isinstance(drawing_operation, _Close): continue min_x = min(min_x, drawing_operation.x) max_x = max(max_x, drawing_operation.x) return Emu(max_x - min_x)
Return width of this shape's path in local units.
_dx
python
scanny/python-pptx
src/pptx/shapes/freeform.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/freeform.py
MIT
def _dy(self) -> Length: """Return integer height of this shape's path in local units.""" min_y = max_y = self._start_y for drawing_operation in self: if isinstance(drawing_operation, _Close): continue min_y = min(min_y, drawing_operation.y) max_y = max(max_y, drawing_operation.y) return Emu(max_y - min_y)
Return integer height of this shape's path in local units.
_dy
python
scanny/python-pptx
src/pptx/shapes/freeform.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/freeform.py
MIT
def _start_path(self, sp: CT_Shape) -> CT_Path2D: """Return a newly created `a:path` element added to `sp`. The returned `a:path` element has an `a:moveTo` element representing the shape starting point as its only child. """ path = sp.add_path(w=self._dx, h=self._dy) path.add_moveTo(*self._local_to_shape(self._start_x, self._start_y)) return path
Return a newly created `a:path` element added to `sp`. The returned `a:path` element has an `a:moveTo` element representing the shape starting point as its only child.
_start_path
python
scanny/python-pptx
src/pptx/shapes/freeform.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/freeform.py
MIT
def apply_operation_to(self, path: CT_Path2D) -> CT_Path2DLineTo: """Add `a:lnTo` element to `path` for this line segment. Returns the `a:lnTo` element newly added to the path. """ return path.add_lnTo( Emu(self._x - self._freeform_builder.shape_offset_x), Emu(self._y - self._freeform_builder.shape_offset_y), )
Add `a:lnTo` element to `path` for this line segment. Returns the `a:lnTo` element newly added to the path.
apply_operation_to
python
scanny/python-pptx
src/pptx/shapes/freeform.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/freeform.py
MIT
def apply_operation_to(self, path: CT_Path2D) -> CT_Path2DMoveTo: """Add `a:moveTo` element to `path` for this line segment.""" return path.add_moveTo( Emu(self._x - self._freeform_builder.shape_offset_x), Emu(self._y - self._freeform_builder.shape_offset_y), )
Add `a:moveTo` element to `path` for this line segment.
apply_operation_to
python
scanny/python-pptx
src/pptx/shapes/freeform.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/freeform.py
MIT
def chart(self) -> Chart: """The |Chart| object containing the chart in this graphic frame. Raises |ValueError| if this graphic frame does not contain a chart. """ if not self.has_chart: raise ValueError("shape does not contain a chart") return self.chart_part.chart
The |Chart| object containing the chart in this graphic frame. Raises |ValueError| if this graphic frame does not contain a chart.
chart
python
scanny/python-pptx
src/pptx/shapes/graphfrm.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/graphfrm.py
MIT
def chart_part(self) -> ChartPart: """The |ChartPart| object containing the chart in this graphic frame.""" chart_rId = self._graphicFrame.chart_rId if chart_rId is None: raise ValueError("this graphic frame does not contain a chart") return cast("ChartPart", self.part.related_part(chart_rId))
The |ChartPart| object containing the chart in this graphic frame.
chart_part
python
scanny/python-pptx
src/pptx/shapes/graphfrm.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/graphfrm.py
MIT
def ole_format(self) -> _OleFormat: """_OleFormat object for this graphic-frame shape. Raises `ValueError` on a GraphicFrame instance that does not contain an OLE object. An shape that contains an OLE object will have `.shape_type` of either `EMBEDDED_OLE_OBJECT` or `LINKED_OLE_OBJECT`. """ if not self._graphicFrame.has_oleobj: raise ValueError("not an OLE-object shape") return _OleFormat(self._graphicFrame.graphicData, self._parent)
_OleFormat object for this graphic-frame shape. Raises `ValueError` on a GraphicFrame instance that does not contain an OLE object. An shape that contains an OLE object will have `.shape_type` of either `EMBEDDED_OLE_OBJECT` or `LINKED_OLE_OBJECT`.
ole_format
python
scanny/python-pptx
src/pptx/shapes/graphfrm.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/graphfrm.py
MIT
def shape_type(self) -> MSO_SHAPE_TYPE: """Optional member of `MSO_SHAPE_TYPE` identifying the type of this shape. Possible values are `MSO_SHAPE_TYPE.CHART`, `MSO_SHAPE_TYPE.TABLE`, `MSO_SHAPE_TYPE.EMBEDDED_OLE_OBJECT`, `MSO_SHAPE_TYPE.LINKED_OLE_OBJECT`. This value is `None` when none of these four types apply, for example when the shape contains SmartArt. """ graphicData_uri = self._graphicFrame.graphicData_uri if graphicData_uri == GRAPHIC_DATA_URI_CHART: return MSO_SHAPE_TYPE.CHART elif graphicData_uri == GRAPHIC_DATA_URI_TABLE: return MSO_SHAPE_TYPE.TABLE elif graphicData_uri == GRAPHIC_DATA_URI_OLEOBJ: return ( MSO_SHAPE_TYPE.EMBEDDED_OLE_OBJECT if self._graphicFrame.is_embedded_ole_obj else MSO_SHAPE_TYPE.LINKED_OLE_OBJECT ) else: return None # pyright: ignore[reportReturnType]
Optional member of `MSO_SHAPE_TYPE` identifying the type of this shape. Possible values are `MSO_SHAPE_TYPE.CHART`, `MSO_SHAPE_TYPE.TABLE`, `MSO_SHAPE_TYPE.EMBEDDED_OLE_OBJECT`, `MSO_SHAPE_TYPE.LINKED_OLE_OBJECT`. This value is `None` when none of these four types apply, for example when the shape contains SmartArt.
shape_type
python
scanny/python-pptx
src/pptx/shapes/graphfrm.py
https://github.com/scanny/python-pptx/blob/master/src/pptx/shapes/graphfrm.py
MIT