Skip to content

Commit 620bf70

Browse files
committed
ole: add icon_width/height to .add_ole_object()
The caller will need to specify the icon height and width when providing their own custom icon image. Add optional parameters to `.add_ole_object()` suitable for that purpose and update the documentation.
1 parent 368373c commit 620bf70

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

pptx/shapes/shapetree.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,16 @@ def add_group_shape(self, shapes=[]):
279279
return self._shape_factory(grpSp)
280280

281281
def add_ole_object(
282-
self, object_file, prog_id, left, top, width=None, height=None, icon_file=None
282+
self,
283+
object_file,
284+
prog_id,
285+
left,
286+
top,
287+
width=None,
288+
height=None,
289+
icon_file=None,
290+
icon_width=None,
291+
icon_height=None,
283292
):
284293
"""Return newly-created GraphicFrame shape embedding `object_file`.
285294
@@ -289,8 +298,9 @@ def add_ole_object(
289298
which case the default icon size is used. This is advised for best appearance
290299
where applicable because it avoids an icon with a "stretched" appearance.
291300
292-
`object_file` may either be a str path to the file or a file-like
293-
object (such as `io.BytesIO`) containing the bytes of the object file.
301+
`object_file` may either be a str path to a file or file-like object (such as
302+
`io.BytesIO`) containing the bytes of the object to be embedded (such as an
303+
Excel file).
294304
295305
`prog_id` can be either a member of `pptx.enum.shapes.PROG_ID` or a str value
296306
like `"Adobe.Exchange.7"` determined by inspecting the XML generated by
@@ -302,6 +312,13 @@ def add_ole_object(
302312
operating-system limitations). The image file can be any supported image file.
303313
Those produced by PowerPoint itself are generally EMF and can be harvested from
304314
a PPTX package that embeds such an object. PNG and JPG also work fine.
315+
316+
`icon_width` and `icon_height` are `Length` values (e.g. Emu() or Inches()) that
317+
describe the size of the icon image within the shape. These should be omitted
318+
unless a custom `icon_file` is provided. The dimensions must be discovered by
319+
inspecting the XML. Automatic resizing of the OLE-object shape can occur when
320+
the icon is double-clicked if these values are not as set by PowerPoint. This
321+
behavior may only manifest in the Windows version of PowerPoint.
305322
"""
306323
graphicFrame = _OleObjectElementCreator.graphicFrame(
307324
self,

0 commit comments

Comments
 (0)