|
13 | 13 | from pptx.shared import ParentedElementProxy |
14 | 14 | from pptx.spec import ( |
15 | 15 | GRAPHIC_DATA_URI_CHART, |
| 16 | + GRAPHIC_DATA_URI_DIAGRAM, |
16 | 17 | GRAPHIC_DATA_URI_OLEOBJ, |
17 | 18 | GRAPHIC_DATA_URI_TABLE, |
18 | 19 | ) |
|
24 | 25 | from pptx.dml.effect import ShadowFormat |
25 | 26 | from pptx.oxml.shapes.graphfrm import CT_GraphicalObjectData, CT_GraphicalObjectFrame |
26 | 27 | from pptx.parts.chart import ChartPart |
| 28 | + from pptx.parts.diagram import DiagramDataPart |
27 | 29 | from pptx.parts.slide import BaseSlidePart |
| 30 | + from pptx.shapes.smartart import SmartArt |
28 | 31 | from pptx.types import ProvidesPart |
29 | 32 |
|
30 | 33 |
|
@@ -64,6 +67,14 @@ def has_chart(self) -> bool: |
64 | 67 | """ |
65 | 68 | return self._graphicFrame.graphicData_uri == GRAPHIC_DATA_URI_CHART |
66 | 69 |
|
| 70 | + @property |
| 71 | + def has_smartart(self) -> bool: |
| 72 | + """|True| if this graphic frame contains SmartArt, |False| otherwise. |
| 73 | +
|
| 74 | + When |True|, the SmartArt object can be accessed using the `.smartart` property. |
| 75 | + """ |
| 76 | + return self._graphicFrame.graphicData_uri == GRAPHIC_DATA_URI_DIAGRAM |
| 77 | + |
67 | 78 | @property |
68 | 79 | def has_table(self) -> bool: |
69 | 80 | """|True| if this graphic frame contains a table object, |False| otherwise. |
@@ -94,21 +105,41 @@ def shadow(self) -> ShadowFormat: |
94 | 105 | """ |
95 | 106 | raise NotImplementedError("shadow property on GraphicFrame not yet supported") |
96 | 107 |
|
| 108 | + @property |
| 109 | + def smartart(self) -> SmartArt: |
| 110 | + """The |SmartArt| object contained in this graphic frame. |
| 111 | +
|
| 112 | + Raises |ValueError| if this graphic frame does not contain SmartArt. |
| 113 | + """ |
| 114 | + if not self.has_smartart: |
| 115 | + raise ValueError("shape does not contain SmartArt") |
| 116 | + |
| 117 | + from pptx.shapes.smartart import SmartArt |
| 118 | + |
| 119 | + data_rId = self._graphicFrame.diagram_data_rId |
| 120 | + if data_rId is None: |
| 121 | + raise ValueError("SmartArt data relationship not found") |
| 122 | + |
| 123 | + data_part = cast("DiagramDataPart", self.part.related_part(data_rId)) |
| 124 | + return SmartArt(data_part, self) |
| 125 | + |
97 | 126 | @property |
98 | 127 | def shape_type(self) -> MSO_SHAPE_TYPE: |
99 | 128 | """Optional member of `MSO_SHAPE_TYPE` identifying the type of this shape. |
100 | 129 |
|
101 | 130 | Possible values are `MSO_SHAPE_TYPE.CHART`, `MSO_SHAPE_TYPE.TABLE`, |
102 | | - `MSO_SHAPE_TYPE.EMBEDDED_OLE_OBJECT`, `MSO_SHAPE_TYPE.LINKED_OLE_OBJECT`. |
| 131 | + `MSO_SHAPE_TYPE.SMART_ART`, `MSO_SHAPE_TYPE.EMBEDDED_OLE_OBJECT`, |
| 132 | + `MSO_SHAPE_TYPE.LINKED_OLE_OBJECT`. |
103 | 133 |
|
104 | | - This value is `None` when none of these four types apply, for example when the shape |
105 | | - contains SmartArt. |
| 134 | + This value is `None` when none of these types apply. |
106 | 135 | """ |
107 | 136 | graphicData_uri = self._graphicFrame.graphicData_uri |
108 | 137 | if graphicData_uri == GRAPHIC_DATA_URI_CHART: |
109 | 138 | return MSO_SHAPE_TYPE.CHART |
110 | 139 | elif graphicData_uri == GRAPHIC_DATA_URI_TABLE: |
111 | 140 | return MSO_SHAPE_TYPE.TABLE |
| 141 | + elif graphicData_uri == GRAPHIC_DATA_URI_DIAGRAM: |
| 142 | + return MSO_SHAPE_TYPE.SMART_ART |
112 | 143 | elif graphicData_uri == GRAPHIC_DATA_URI_OLEOBJ: |
113 | 144 | return ( |
114 | 145 | MSO_SHAPE_TYPE.EMBEDDED_OLE_OBJECT |
|
0 commit comments