Skip to content

Commit 407627d

Browse files
committed
ole: add _OleObjectElementCreator icon_width/height
1 parent 620bf70 commit 407627d

File tree

2 files changed

+106
-19
lines changed

2 files changed

+106
-19
lines changed

pptx/shapes/shapetree.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ def add_ole_object(
330330
width,
331331
height,
332332
icon_file,
333+
icon_width,
334+
icon_height,
333335
)
334336
self._spTree.append(graphicFrame)
335337
self._recalculate_extents()
@@ -1017,7 +1019,18 @@ class _OleObjectElementCreator(object):
10171019
"""
10181020

10191021
def __init__(
1020-
self, shapes, shape_id, ole_object_file, prog_id, x, y, cx, cy, icon_file
1022+
self,
1023+
shapes,
1024+
shape_id,
1025+
ole_object_file,
1026+
prog_id,
1027+
x,
1028+
y,
1029+
cx,
1030+
cy,
1031+
icon_file,
1032+
icon_width,
1033+
icon_height,
10211034
):
10221035
self._shapes = shapes
10231036
self._shape_id = shape_id
@@ -1028,14 +1041,37 @@ def __init__(
10281041
self._cx_arg = cx
10291042
self._cy_arg = cy
10301043
self._icon_file_arg = icon_file
1044+
self._icon_width_arg = icon_width
1045+
self._icon_height_arg = icon_height
10311046

10321047
@classmethod
10331048
def graphicFrame(
1034-
cls, shapes, shape_id, ole_object_file, prog_id, x, y, cx, cy, icon_file
1049+
cls,
1050+
shapes,
1051+
shape_id,
1052+
ole_object_file,
1053+
prog_id,
1054+
x,
1055+
y,
1056+
cx,
1057+
cy,
1058+
icon_file,
1059+
icon_width,
1060+
icon_height,
10351061
):
10361062
"""Return new `p:graphicFrame` element containing embedded `ole_object_file`."""
10371063
return cls(
1038-
shapes, shape_id, ole_object_file, prog_id, x, y, cx, cy, icon_file
1064+
shapes,
1065+
shape_id,
1066+
ole_object_file,
1067+
prog_id,
1068+
x,
1069+
y,
1070+
cx,
1071+
cy,
1072+
icon_file,
1073+
icon_width,
1074+
icon_height,
10391075
)._graphicFrame
10401076

10411077
@lazyproperty

tests/shapes/test_shapetree.py

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
)
5353
from pptx.slide import SlideLayout, SlideMaster
5454
from pptx.table import Table
55-
from pptx.util import Emu
55+
from pptx.util import Emu, Inches
5656

5757
from ..oxml.unitdata.shape import a_ph, a_pic, an_nvPr, an_nvSpPr, an_sp
5858
from ..unitutil.cxml import element, xml
@@ -375,10 +375,30 @@ def it_can_add_an_ole_object(
375375
x, y, cx, cy = 1, 2, 3, 4
376376
shapes = _BaseGroupShapes(element("p:spTree"), None)
377377

378-
shape = shapes.add_ole_object("worksheet.xlsx", PROG_ID.XLSX, x, y, cx, cy)
378+
shape = shapes.add_ole_object(
379+
"worksheet.xlsx",
380+
PROG_ID.XLSX,
381+
x,
382+
y,
383+
cx,
384+
cy,
385+
"test.xlsx",
386+
Inches(0.5),
387+
Inches(0.75),
388+
)
379389

380390
_OleObjectElementCreator_.graphicFrame.assert_called_once_with(
381-
shapes, 42, "worksheet.xlsx", PROG_ID.XLSX, x, y, cx, cy, None
391+
shapes,
392+
42,
393+
"worksheet.xlsx",
394+
PROG_ID.XLSX,
395+
x,
396+
y,
397+
cx,
398+
cy,
399+
"test.xlsx",
400+
Inches(0.5),
401+
Inches(0.75),
382402
)
383403
assert shapes._spTree[-1] is graphicFrame
384404
_recalculate_extents_.assert_called_once_with(shapes)
@@ -2093,11 +2113,32 @@ def it_provides_a_graphicFrame_interface_method(self, request, shapes_):
20932113
)
20942114

20952115
graphicFrame = _OleObjectElementCreator.graphicFrame(
2096-
shapes_, shape_id, "sheet.xlsx", PROG_ID.XLSX, x, y, cx, cy, "icon.png"
2116+
shapes_,
2117+
shape_id,
2118+
"sheet.xlsx",
2119+
PROG_ID.XLSX,
2120+
x,
2121+
y,
2122+
cx,
2123+
cy,
2124+
"icon.png",
2125+
Inches(0.5),
2126+
Inches(0.75),
20972127
)
20982128

20992129
_init_.assert_called_once_with(
2100-
ANY, shapes_, shape_id, "sheet.xlsx", PROG_ID.XLSX, x, y, cx, cy, "icon.png"
2130+
ANY,
2131+
shapes_,
2132+
shape_id,
2133+
"sheet.xlsx",
2134+
PROG_ID.XLSX,
2135+
x,
2136+
y,
2137+
cx,
2138+
cy,
2139+
"icon.png",
2140+
Inches(0.5),
2141+
Inches(0.75),
21012142
)
21022143
_graphicFrame_prop_.assert_called_once_with()
21032144
assert graphicFrame is graphicFrame_
@@ -2119,7 +2160,7 @@ def it_creates_the_graphicFrame_element(self, request):
21192160
property_mock(request, _OleObjectElementCreator, "_cx", return_value=cx)
21202161
property_mock(request, _OleObjectElementCreator, "_cy", return_value=cy)
21212162
element_creator = _OleObjectElementCreator(
2122-
None, shape_id, None, None, x, y, cx, cy, None
2163+
None, shape_id, None, None, x, y, cx, cy, None, Inches(0.5), Inches(0.75)
21232164
)
21242165

21252166
assert element_creator._graphicFrame.xml == (
@@ -2183,9 +2224,9 @@ def it_creates_the_graphicFrame_element(self, request):
21832224
(None, "Foo.Bar.6", Emu(965200)),
21842225
),
21852226
)
2186-
def it_determines_the_icon_width_to_help(self, cx_arg, prog_id, expected_value):
2227+
def it_determines_the_shape_width_to_help(self, cx_arg, prog_id, expected_value):
21872228
element_creator = _OleObjectElementCreator(
2188-
None, None, None, prog_id, None, None, cx_arg, None, None
2229+
None, None, None, prog_id, None, None, cx_arg, None, None, None, None
21892230
)
21902231
assert element_creator._cx == expected_value
21912232

@@ -2199,9 +2240,9 @@ def it_determines_the_icon_width_to_help(self, cx_arg, prog_id, expected_value):
21992240
(None, "Foo.Bar.6", Emu(609600)),
22002241
),
22012242
)
2202-
def it_determines_the_icon_height_to_help(self, cy_arg, prog_id, expected_value):
2243+
def it_determines_the_shape_height_to_help(self, cy_arg, prog_id, expected_value):
22032244
element_creator = _OleObjectElementCreator(
2204-
None, None, None, prog_id, None, None, None, cy_arg, None
2245+
None, None, None, prog_id, None, None, None, cy_arg, None, None, None
22052246
)
22062247
assert element_creator._cy == expected_value
22072248

@@ -2219,7 +2260,7 @@ def it_resolves_the_icon_image_file_to_help(
22192260
self, icon_file_arg, prog_id, expected_value
22202261
):
22212262
element_creator = _OleObjectElementCreator(
2222-
None, None, None, prog_id, None, None, None, None, icon_file_arg
2263+
None, None, None, prog_id, None, None, None, None, icon_file_arg, None, None
22232264
)
22242265
assert element_creator._icon_image_file.endswith(expected_value)
22252266

@@ -2235,7 +2276,7 @@ def it_adds_and_relates_the_icon_image_part_to_help(
22352276
slide_part_.get_or_add_image_part.return_value = None, "rId16"
22362277
_slide_part_prop_.return_value = slide_part_
22372278
element_creator = _OleObjectElementCreator(
2238-
None, None, None, None, None, None, None, None, None
2279+
None, None, None, None, None, None, None, None, None, None, None
22392280
)
22402281

22412282
rId = element_creator._icon_rId
@@ -2250,7 +2291,17 @@ def it_adds_and_relates_the_ole_object_part_to_help(
22502291
slide_part_.add_embedded_ole_object_part.return_value = "rId14"
22512292
_slide_part_prop_.return_value = slide_part_
22522293
element_creator = _OleObjectElementCreator(
2253-
None, None, ole_object_file, PROG_ID.DOCX, None, None, None, None, None
2294+
None,
2295+
None,
2296+
ole_object_file,
2297+
PROG_ID.DOCX,
2298+
None,
2299+
None,
2300+
None,
2301+
None,
2302+
None,
2303+
None,
2304+
None,
22542305
)
22552306

22562307
rId = element_creator._ole_object_rId
@@ -2271,21 +2322,21 @@ def it_adds_and_relates_the_ole_object_part_to_help(
22712322
)
22722323
def it_resolves_the_progId_str_to_help(self, prog_id_arg, expected_value):
22732324
element_creator = _OleObjectElementCreator(
2274-
None, None, None, prog_id_arg, None, None, None, None, None
2325+
None, None, None, prog_id_arg, None, None, None, None, None, None, None
22752326
)
22762327
assert element_creator._progId == expected_value
22772328

22782329
def it_computes_the_shape_name_to_help(self):
22792330
shape_id = 42
22802331
element_creator = _OleObjectElementCreator(
2281-
None, shape_id, None, None, None, None, None, None, None
2332+
None, shape_id, None, None, None, None, None, None, None, None, None
22822333
)
22832334
assert element_creator._shape_name == "Object 41"
22842335

22852336
def it_provides_access_to_the_slide_part_to_help(self, shapes_, slide_part_):
22862337
shapes_.part = slide_part_
22872338
element_creator = _OleObjectElementCreator(
2288-
shapes_, None, None, None, None, None, None, None, None
2339+
shapes_, None, None, None, None, None, None, None, None, None, None
22892340
)
22902341

22912342
assert element_creator._slide_part is slide_part_

0 commit comments

Comments
 (0)