python-pptx2 2.13.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. pptx2/__init__.py +152 -0
  2. pptx2/_color.py +75 -0
  3. pptx2/_slide_importer.py +597 -0
  4. pptx2/_svg.py +155 -0
  5. pptx2/_template_applier.py +292 -0
  6. pptx2/_textstyle.py +187 -0
  7. pptx2/accessibility.py +365 -0
  8. pptx2/action.py +270 -0
  9. pptx2/animation.py +2237 -0
  10. pptx2/api.py +49 -0
  11. pptx2/audit.py +258 -0
  12. pptx2/chart/__init__.py +0 -0
  13. pptx2/chart/analytics.py +381 -0
  14. pptx2/chart/axis.py +543 -0
  15. pptx2/chart/category.py +200 -0
  16. pptx2/chart/chart.py +670 -0
  17. pptx2/chart/data.py +864 -0
  18. pptx2/chart/datalabel.py +406 -0
  19. pptx2/chart/legend.py +86 -0
  20. pptx2/chart/marker.py +70 -0
  21. pptx2/chart/palettes.py +129 -0
  22. pptx2/chart/plot.py +462 -0
  23. pptx2/chart/point.py +101 -0
  24. pptx2/chart/quick_layouts.py +325 -0
  25. pptx2/chart/series.py +334 -0
  26. pptx2/chart/xlsx.py +272 -0
  27. pptx2/chart/xmlwriter.py +1845 -0
  28. pptx2/compose/__init__.py +28 -0
  29. pptx2/compose/from_spec.py +1094 -0
  30. pptx2/design/__init__.py +8 -0
  31. pptx2/design/components.py +607 -0
  32. pptx2/design/figures.py +389 -0
  33. pptx2/design/layout.py +370 -0
  34. pptx2/design/recipes.py +1967 -0
  35. pptx2/design/style.py +209 -0
  36. pptx2/design/tokens.py +915 -0
  37. pptx2/diagrams.py +754 -0
  38. pptx2/dml/__init__.py +0 -0
  39. pptx2/dml/chtfmt.py +40 -0
  40. pptx2/dml/color.py +496 -0
  41. pptx2/dml/effect.py +909 -0
  42. pptx2/dml/fill.py +691 -0
  43. pptx2/dml/line.py +287 -0
  44. pptx2/dml/picture.py +212 -0
  45. pptx2/dml/three_d.py +381 -0
  46. pptx2/enum/__init__.py +0 -0
  47. pptx2/enum/action.py +71 -0
  48. pptx2/enum/animation.py +31 -0
  49. pptx2/enum/base.py +218 -0
  50. pptx2/enum/chart.py +574 -0
  51. pptx2/enum/dml.py +740 -0
  52. pptx2/enum/lang.py +685 -0
  53. pptx2/enum/presentation.py +133 -0
  54. pptx2/enum/shapes.py +1029 -0
  55. pptx2/enum/text.py +230 -0
  56. pptx2/exc.py +42 -0
  57. pptx2/formats.py +139 -0
  58. pptx2/geometry.py +420 -0
  59. pptx2/inherit.py +109 -0
  60. pptx2/lint.py +2256 -0
  61. pptx2/math.py +177 -0
  62. pptx2/media.py +197 -0
  63. pptx2/opc/__init__.py +0 -0
  64. pptx2/opc/constants.py +332 -0
  65. pptx2/opc/oxml.py +188 -0
  66. pptx2/opc/package.py +762 -0
  67. pptx2/opc/packuri.py +109 -0
  68. pptx2/opc/serialized.py +296 -0
  69. pptx2/opc/shared.py +20 -0
  70. pptx2/opc/spec.py +45 -0
  71. pptx2/oxml/__init__.py +555 -0
  72. pptx2/oxml/action.py +53 -0
  73. pptx2/oxml/chart/__init__.py +0 -0
  74. pptx2/oxml/chart/axis.py +337 -0
  75. pptx2/oxml/chart/chart.py +481 -0
  76. pptx2/oxml/chart/datalabel.py +253 -0
  77. pptx2/oxml/chart/legend.py +72 -0
  78. pptx2/oxml/chart/marker.py +61 -0
  79. pptx2/oxml/chart/plot.py +365 -0
  80. pptx2/oxml/chart/series.py +425 -0
  81. pptx2/oxml/chart/shared.py +220 -0
  82. pptx2/oxml/coreprops.py +288 -0
  83. pptx2/oxml/dml/__init__.py +0 -0
  84. pptx2/oxml/dml/color.py +135 -0
  85. pptx2/oxml/dml/effect.py +213 -0
  86. pptx2/oxml/dml/fill.py +316 -0
  87. pptx2/oxml/dml/line.py +12 -0
  88. pptx2/oxml/dml/three_d.py +110 -0
  89. pptx2/oxml/ns.py +135 -0
  90. pptx2/oxml/presentation.py +313 -0
  91. pptx2/oxml/shapes/__init__.py +19 -0
  92. pptx2/oxml/shapes/autoshape.py +467 -0
  93. pptx2/oxml/shapes/connector.py +107 -0
  94. pptx2/oxml/shapes/graphfrm.py +347 -0
  95. pptx2/oxml/shapes/groupshape.py +329 -0
  96. pptx2/oxml/shapes/picture.py +270 -0
  97. pptx2/oxml/shapes/shared.py +577 -0
  98. pptx2/oxml/simpletypes.py +1027 -0
  99. pptx2/oxml/slide.py +563 -0
  100. pptx2/oxml/table.py +650 -0
  101. pptx2/oxml/text.py +815 -0
  102. pptx2/oxml/theme.py +36 -0
  103. pptx2/oxml/xmlchemy.py +717 -0
  104. pptx2/package.py +222 -0
  105. pptx2/parts/__init__.py +0 -0
  106. pptx2/parts/chart.py +95 -0
  107. pptx2/parts/coreprops.py +167 -0
  108. pptx2/parts/diagram.py +37 -0
  109. pptx2/parts/embeddedpackage.py +93 -0
  110. pptx2/parts/image.py +275 -0
  111. pptx2/parts/media.py +37 -0
  112. pptx2/parts/presentation.py +136 -0
  113. pptx2/parts/slide.py +371 -0
  114. pptx2/presentation.py +408 -0
  115. pptx2/py.typed +0 -0
  116. pptx2/render.py +586 -0
  117. pptx2/section.py +272 -0
  118. pptx2/shapes/__init__.py +26 -0
  119. pptx2/shapes/autoshape.py +442 -0
  120. pptx2/shapes/base.py +1078 -0
  121. pptx2/shapes/connector.py +297 -0
  122. pptx2/shapes/freeform.py +337 -0
  123. pptx2/shapes/graphfrm.py +316 -0
  124. pptx2/shapes/group.py +264 -0
  125. pptx2/shapes/picture.py +422 -0
  126. pptx2/shapes/placeholder.py +468 -0
  127. pptx2/shapes/shapetree.py +2027 -0
  128. pptx2/shared.py +82 -0
  129. pptx2/skill/SKILL.md +450 -0
  130. pptx2/skill/__init__.py +78 -0
  131. pptx2/skill/__main__.py +64 -0
  132. pptx2/skill/references/animations.md +189 -0
  133. pptx2/skill/references/basics.md +421 -0
  134. pptx2/skill/references/charts.md +254 -0
  135. pptx2/skill/references/compose.md +234 -0
  136. pptx2/skill/references/design.md +366 -0
  137. pptx2/skill/references/effects.md +249 -0
  138. pptx2/skill/references/end-to-end-deck.md +231 -0
  139. pptx2/skill/references/geometry-and-arrows.md +334 -0
  140. pptx2/skill/references/lint.md +275 -0
  141. pptx2/skill/references/math.md +86 -0
  142. pptx2/skill/references/picture-effects.md +129 -0
  143. pptx2/skill/references/render.md +151 -0
  144. pptx2/skill/references/smart-art.md +75 -0
  145. pptx2/skill/references/space-aware-authoring.md +249 -0
  146. pptx2/skill/references/tables.md +244 -0
  147. pptx2/skill/references/theme.md +127 -0
  148. pptx2/skill/references/three-d.md +109 -0
  149. pptx2/skill/references/transitions.md +100 -0
  150. pptx2/slide.py +1244 -0
  151. pptx2/smart_art.py +220 -0
  152. pptx2/spec.py +633 -0
  153. pptx2/table.py +1181 -0
  154. pptx2/table_styles.py +184 -0
  155. pptx2/templates/default.pptx +0 -0
  156. pptx2/templates/docx-icon.emf +0 -0
  157. pptx2/templates/generic-icon.emf +0 -0
  158. pptx2/templates/notes.xml +23 -0
  159. pptx2/templates/notesMaster.xml +352 -0
  160. pptx2/templates/pptx-icon.emf +0 -0
  161. pptx2/templates/theme.xml +321 -0
  162. pptx2/templates/xlsx-icon.emf +0 -0
  163. pptx2/text/__init__.py +0 -0
  164. pptx2/text/fonts.py +482 -0
  165. pptx2/text/layout.py +374 -0
  166. pptx2/text/text.py +1272 -0
  167. pptx2/theme.py +721 -0
  168. pptx2/types.py +36 -0
  169. pptx2/util.py +263 -0
  170. python_pptx2-2.13.0.dist-info/METADATA +351 -0
  171. python_pptx2-2.13.0.dist-info/RECORD +175 -0
  172. python_pptx2-2.13.0.dist-info/WHEEL +5 -0
  173. python_pptx2-2.13.0.dist-info/entry_points.txt +3 -0
  174. python_pptx2-2.13.0.dist-info/licenses/LICENSE +22 -0
  175. python_pptx2-2.13.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,313 @@
1
+ """Custom element classes for presentation-related XML elements."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import uuid
6
+ from typing import TYPE_CHECKING, Callable, cast
7
+
8
+ from pptx2.oxml.ns import nsmap, qn
9
+ from pptx2.oxml.simpletypes import ST_SlideId, ST_SlideSizeCoordinate, XsdString
10
+ from pptx2.oxml.xmlchemy import (
11
+ BaseOxmlElement,
12
+ OxmlElement,
13
+ RequiredAttribute,
14
+ ZeroOrMore,
15
+ ZeroOrOne,
16
+ )
17
+
18
+ if TYPE_CHECKING:
19
+ from pptx2.util import Length
20
+
21
+ # -- GUID identifying the PowerPoint 2010 sectionLst presentation extension. --
22
+ SECTION_EXT_URI = "{521415D9-36F7-43E2-AB2F-B90AF26B5E84}"
23
+
24
+
25
+ class CT_Presentation(BaseOxmlElement):
26
+ """`p:presentation` element, root of the Presentation part stored as `/ppt/presentation.xml`."""
27
+
28
+ get_or_add_sldSz: Callable[[], CT_SlideSize]
29
+ get_or_add_sldIdLst: Callable[[], CT_SlideIdList]
30
+ get_or_add_sldMasterIdLst: Callable[[], CT_SlideMasterIdList]
31
+ get_or_add_embeddedFontLst: Callable[[], BaseOxmlElement]
32
+ get_or_add_extLst: Callable[[], BaseOxmlElement]
33
+
34
+ sldMasterIdLst: CT_SlideMasterIdList | None = (
35
+ ZeroOrOne( # pyright: ignore[reportAssignmentType]
36
+ "p:sldMasterIdLst",
37
+ successors=(
38
+ "p:notesMasterIdLst",
39
+ "p:handoutMasterIdLst",
40
+ "p:sldIdLst",
41
+ "p:sldSz",
42
+ "p:notesSz",
43
+ ),
44
+ )
45
+ )
46
+ sldIdLst: CT_SlideIdList | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
47
+ "p:sldIdLst", successors=("p:sldSz", "p:notesSz")
48
+ )
49
+ sldSz: CT_SlideSize | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
50
+ "p:sldSz", successors=("p:notesSz",)
51
+ )
52
+ # -- `p:embeddedFontLst` follows `p:notesSz` but precedes `custShowLst`,
53
+ # -- `photoAlbum`, `custDataLst`, `kinsoku`, `defaultTextStyle`,
54
+ # -- `modifyVerifier`, and `extLst` in the CT_Presentation sequence.
55
+ # -- Every default template already carries a `defaultTextStyle`, so a bare
56
+ # -- append would place the font list *after* it and produce a
57
+ # -- presentation.xml PowerPoint reports as broken. --
58
+ embeddedFontLst: BaseOxmlElement | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
59
+ "p:embeddedFontLst",
60
+ successors=(
61
+ "p:custShowLst",
62
+ "p:photoAlbum",
63
+ "p:custDataLst",
64
+ "p:kinsoku",
65
+ "p:defaultTextStyle",
66
+ "p:modifyVerifier",
67
+ "p:extLst",
68
+ ),
69
+ )
70
+ # -- `p:extLst` is the final child of `p:presentation` (no successors). --
71
+ extLst: BaseOxmlElement | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
72
+ "p:extLst"
73
+ )
74
+
75
+ @property
76
+ def sectionLst(self) -> CT_SectionList | None:
77
+ """The `p14:sectionLst` element, or |None| if not present.
78
+
79
+ Reaches through `p:extLst/p:ext[@uri='{...}']` to find the
80
+ PowerPoint-2010 section-list extension.
81
+ """
82
+ ext = self._section_ext
83
+ if ext is None:
84
+ return None
85
+ return cast("CT_SectionList | None", ext.find(qn("p14:sectionLst")))
86
+
87
+ def get_or_add_sectionLst(self) -> CT_SectionList:
88
+ """Return the `p14:sectionLst` element, newly created if not present.
89
+
90
+ The wrapping `p:extLst/p:ext` are created as needed.
91
+ """
92
+ sectionLst = self.sectionLst
93
+ if sectionLst is not None:
94
+ return sectionLst
95
+ ext = self._get_or_add_section_ext()
96
+ sectionLst = cast("CT_SectionList", OxmlElement("p14:sectionLst", nsmap=nsmap("p14")))
97
+ ext.append(sectionLst)
98
+ return sectionLst
99
+
100
+ @property
101
+ def _section_ext(self) -> BaseOxmlElement | None:
102
+ """The `p:ext` element carrying the section-list extension, or |None|."""
103
+ extLst = self.extLst
104
+ if extLst is None:
105
+ return None
106
+ for ext in extLst.findall(qn("p:ext")):
107
+ if ext.get("uri") == SECTION_EXT_URI:
108
+ return cast("BaseOxmlElement", ext)
109
+ return None
110
+
111
+ def _get_or_add_section_ext(self) -> BaseOxmlElement:
112
+ """Return the section-list `p:ext`, newly created if not present."""
113
+ ext = self._section_ext
114
+ if ext is not None:
115
+ return ext
116
+ extLst = self.get_or_add_extLst()
117
+ ext = OxmlElement("p:ext")
118
+ ext.set("uri", SECTION_EXT_URI)
119
+ extLst.append(ext)
120
+ return ext
121
+
122
+
123
+ class CT_SlideId(BaseOxmlElement):
124
+ """`p:sldId` element.
125
+
126
+ Direct child of `p:sldIdLst` that contains an `rId` reference to a slide in the presentation.
127
+ """
128
+
129
+ id: int = RequiredAttribute("id", ST_SlideId) # pyright: ignore[reportAssignmentType]
130
+ rId: str = RequiredAttribute("r:id", XsdString) # pyright: ignore[reportAssignmentType]
131
+
132
+
133
+ class CT_SlideIdList(BaseOxmlElement):
134
+ """`p:sldIdLst` element.
135
+
136
+ Direct child of <p:presentation> that contains a list of the slide parts in the presentation.
137
+ """
138
+
139
+ sldId_lst: list[CT_SlideId]
140
+
141
+ _add_sldId: Callable[..., CT_SlideId]
142
+ sldId = ZeroOrMore("p:sldId")
143
+
144
+ def add_sldId(self, rId: str) -> CT_SlideId:
145
+ """Create and return a reference to a new `p:sldId` child element.
146
+
147
+ The new `p:sldId` element has its r:id attribute set to `rId`.
148
+ """
149
+ return self._add_sldId(id=self._next_id, rId=rId)
150
+
151
+ @property
152
+ def _next_id(self) -> int:
153
+ """The next available slide ID as an `int`.
154
+
155
+ Valid slide IDs start at 256. The next integer value greater than the max value in use is
156
+ chosen, which minimizes that chance of reusing the id of a deleted slide.
157
+ """
158
+ MIN_SLIDE_ID = 256
159
+ MAX_SLIDE_ID = 2147483647
160
+
161
+ used_ids = [int(s) for s in cast("list[str]", self.xpath("./p:sldId/@id"))]
162
+ simple_next = max([MIN_SLIDE_ID - 1] + used_ids) + 1
163
+ if simple_next <= MAX_SLIDE_ID:
164
+ return simple_next
165
+
166
+ # -- fall back to search for next unused from bottom --
167
+ valid_used_ids = sorted(id for id in used_ids if (MIN_SLIDE_ID <= id <= MAX_SLIDE_ID))
168
+ return (
169
+ next(
170
+ candidate_id
171
+ for candidate_id, used_id in enumerate(valid_used_ids, start=MIN_SLIDE_ID)
172
+ if candidate_id != used_id
173
+ )
174
+ if valid_used_ids
175
+ else 256
176
+ )
177
+
178
+
179
+ class CT_SlideMasterIdList(BaseOxmlElement):
180
+ """`p:sldMasterIdLst` element.
181
+
182
+ Child of `p:presentation` containing references to the slide masters that belong to the
183
+ presentation.
184
+ """
185
+
186
+ sldMasterId_lst: list[CT_SlideMasterIdListEntry]
187
+
188
+ sldMasterId = ZeroOrMore("p:sldMasterId")
189
+
190
+
191
+ class CT_SlideMasterIdListEntry(BaseOxmlElement):
192
+ """
193
+ ``<p:sldMasterId>`` element, child of ``<p:sldMasterIdLst>`` containing
194
+ a reference to a slide master.
195
+ """
196
+
197
+ rId: str = RequiredAttribute("r:id", XsdString) # pyright: ignore[reportAssignmentType]
198
+
199
+
200
+ class CT_SlideSize(BaseOxmlElement):
201
+ """`p:sldSz` element.
202
+
203
+ Direct child of <p:presentation> that contains the width and height of slides in the
204
+ presentation.
205
+ """
206
+
207
+ cx: Length = RequiredAttribute( # pyright: ignore[reportAssignmentType]
208
+ "cx", ST_SlideSizeCoordinate
209
+ )
210
+ cy: Length = RequiredAttribute( # pyright: ignore[reportAssignmentType]
211
+ "cy", ST_SlideSizeCoordinate
212
+ )
213
+
214
+
215
+ # ===========================================================================
216
+ # PowerPoint 2010 section extension (`p14:sectionLst`).
217
+ #
218
+ # Stored inside `p:presentation/p:extLst/p:ext[@uri="{521415D9-...}"]`. These
219
+ # `p14:*` classes are registered at module-import time (see bottom of file) so
220
+ # the off-limits `pptx2.oxml.__init__` does not need editing.
221
+ # ===========================================================================
222
+
223
+
224
+ class CT_SectionList(BaseOxmlElement):
225
+ """`p14:sectionLst` element, container for the deck's `p14:section` children."""
226
+
227
+ section_lst: list[CT_Section]
228
+
229
+ _add_section: Callable[..., CT_Section]
230
+ section = ZeroOrMore("p14:section")
231
+
232
+ def add_section(self, name: str, section_id: str | None = None) -> CT_Section:
233
+ """Create, append, and return a new `p14:section` element.
234
+
235
+ `name` is the user-visible section label. `section_id`, when supplied,
236
+ is the brace-wrapped GUID used as the section's `id`; a random one is
237
+ generated when omitted.
238
+ """
239
+ if section_id is None:
240
+ section_id = "{%s}" % str(uuid.uuid4()).upper()
241
+ section = self._add_section()
242
+ section.name = name
243
+ section.id = section_id
244
+ # -- `p14:sldIdLst` is a required child (MS-PPTX 2.5.17 CT_Section,
245
+ # -- minOccurs=1); PowerPoint writes it even for an empty section. --
246
+ section.get_or_add_sldIdLst()
247
+ return section
248
+
249
+
250
+ class CT_Section(BaseOxmlElement):
251
+ """`p14:section` element, a single named section referencing member slides."""
252
+
253
+ get_or_add_sldIdLst: Callable[[], CT_SectionSlideIdList]
254
+
255
+ name: str = RequiredAttribute("name", XsdString) # pyright: ignore[reportAssignmentType]
256
+ id: str = RequiredAttribute("id", XsdString) # pyright: ignore[reportAssignmentType]
257
+
258
+ sldIdLst: CT_SectionSlideIdList | None = (
259
+ ZeroOrOne( # pyright: ignore[reportAssignmentType]
260
+ "p14:sldIdLst"
261
+ )
262
+ )
263
+
264
+ @property
265
+ def sldId_lst(self) -> list[CT_SectionSlideId]:
266
+ """List of `p14:sldId` member references (possibly empty)."""
267
+ sldIdLst = self.sldIdLst
268
+ if sldIdLst is None:
269
+ return []
270
+ return sldIdLst.sldId_lst
271
+
272
+ def add_sldId(self, id: int) -> CT_SectionSlideId:
273
+ """Append a `p14:sldId` referencing the slide whose numeric id is `id`."""
274
+ sldIdLst = self.get_or_add_sldIdLst()
275
+ return sldIdLst.add_sldId(id)
276
+
277
+ def remove_sldId(self, id: int) -> None:
278
+ """Remove the `p14:sldId` member referencing `id`, if present."""
279
+ for sldId in list(self.sldId_lst):
280
+ if sldId.id == id:
281
+ sldId.getparent().remove(sldId)
282
+
283
+
284
+ class CT_SectionSlideIdList(BaseOxmlElement):
285
+ """`p14:sldIdLst` element, child of `p14:section` listing member slide ids."""
286
+
287
+ sldId_lst: list[CT_SectionSlideId]
288
+
289
+ _add_sldId: Callable[..., CT_SectionSlideId]
290
+ sldId = ZeroOrMore("p14:sldId")
291
+
292
+ def add_sldId(self, id: int) -> CT_SectionSlideId:
293
+ """Create and return a new `p14:sldId` child with its `id` set to `id`."""
294
+ return self._add_sldId(id=id)
295
+
296
+
297
+ class CT_SectionSlideId(BaseOxmlElement):
298
+ """`p14:sldId` element, references a slide by its numeric `p:sldId/@id` value."""
299
+
300
+ id: int = RequiredAttribute("id", ST_SlideId) # pyright: ignore[reportAssignmentType]
301
+
302
+
303
+ # -- Register the `p14:*` section element classes so the lxml parser maps these
304
+ # -- tags to the custom classes above. Done here (not in `oxml.__init__`) via
305
+ # -- the public `register_element_cls` hook. Imported at module bottom (E402)
306
+ # -- to avoid the partial-import cycle with `pptx2.oxml.__init__`, which
307
+ # -- imports this module while it is still initializing.
308
+ from pptx2.oxml import register_element_cls # noqa: E402
309
+
310
+ register_element_cls("p14:sectionLst", CT_SectionList)
311
+ register_element_cls("p14:section", CT_Section)
312
+ register_element_cls("p14:sldIdLst", CT_SectionSlideIdList)
313
+ register_element_cls("p14:sldId", CT_SectionSlideId)
@@ -0,0 +1,19 @@
1
+ """Base shape-related objects such as BaseShape."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING
6
+
7
+ if TYPE_CHECKING:
8
+ from typing_extensions import TypeAlias
9
+
10
+ from pptx2.oxml.shapes.autoshape import CT_Shape
11
+ from pptx2.oxml.shapes.connector import CT_Connector
12
+ from pptx2.oxml.shapes.graphfrm import CT_GraphicalObjectFrame
13
+ from pptx2.oxml.shapes.groupshape import CT_GroupShape
14
+ from pptx2.oxml.shapes.picture import CT_Picture
15
+
16
+
17
+ ShapeElement: TypeAlias = (
18
+ "CT_Connector | CT_GraphicalObjectFrame | CT_GroupShape | CT_Picture | CT_Shape"
19
+ )