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
pptx2/oxml/dml/fill.py ADDED
@@ -0,0 +1,316 @@
1
+ """lxml custom element classes for DrawingML-related XML elements."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pptx2.enum.dml import MSO_PATTERN_TYPE
6
+ from pptx2.oxml import parse_xml
7
+ from pptx2.oxml.ns import nsdecls
8
+ from pptx2.oxml.simpletypes import (
9
+ ST_FixedPercentage,
10
+ ST_Percentage,
11
+ ST_PositiveFixedAngle,
12
+ ST_PositiveFixedPercentage,
13
+ ST_RelationshipId,
14
+ )
15
+ from pptx2.oxml.xmlchemy import (
16
+ BaseOxmlElement,
17
+ Choice,
18
+ OneOrMore,
19
+ OptionalAttribute,
20
+ RequiredAttribute,
21
+ ZeroOrOne,
22
+ ZeroOrOneChoice,
23
+ )
24
+
25
+
26
+ class CT_Blip(BaseOxmlElement):
27
+ """`<a:blip>` element — image reference plus optional per-image effects."""
28
+
29
+ # Child tag order follows the OOXML CT_Blip content model.
30
+ _tag_seq = (
31
+ "a:alphaBiLevel",
32
+ "a:alphaCeiling",
33
+ "a:alphaFloor",
34
+ "a:alphaInv",
35
+ "a:alphaMod",
36
+ "a:alphaModFix",
37
+ "a:alphaRepl",
38
+ "a:biLevel",
39
+ "a:blur",
40
+ "a:clrChange",
41
+ "a:clrRepl",
42
+ "a:duotone",
43
+ "a:fillOverlay",
44
+ "a:grayscl",
45
+ "a:hsl",
46
+ "a:lum",
47
+ "a:tint",
48
+ "a:extLst",
49
+ )
50
+ alphaModFix: CT_AlphaModFixEffect | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
51
+ "a:alphaModFix", successors=_tag_seq[6:]
52
+ )
53
+ biLevel: CT_BiLevelEffect | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
54
+ "a:biLevel", successors=_tag_seq[8:]
55
+ )
56
+ duotone: CT_DuotoneEffect | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
57
+ "a:duotone", successors=_tag_seq[12:]
58
+ )
59
+ grayscl: CT_GrayscaleEffect | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
60
+ "a:grayscl", successors=_tag_seq[14:]
61
+ )
62
+ lum: CT_LuminanceEffect | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
63
+ "a:lum", successors=_tag_seq[16:]
64
+ )
65
+ del _tag_seq
66
+
67
+ rEmbed = OptionalAttribute("r:embed", ST_RelationshipId)
68
+
69
+
70
+ class CT_BlipFillProperties(BaseOxmlElement):
71
+ """
72
+ Custom element class for <a:blipFill> element.
73
+ """
74
+
75
+ _tag_seq = ("a:blip", "a:srcRect", "a:tile", "a:stretch")
76
+ blip = ZeroOrOne("a:blip", successors=_tag_seq[1:])
77
+ srcRect = ZeroOrOne("a:srcRect", successors=_tag_seq[2:])
78
+ del _tag_seq
79
+
80
+ def crop(self, cropping):
81
+ """
82
+ Set `a:srcRect` child to crop according to *cropping* values.
83
+ """
84
+ srcRect = self._add_srcRect()
85
+ srcRect.l, srcRect.t, srcRect.r, srcRect.b = cropping
86
+
87
+
88
+ class CT_GradientFillProperties(BaseOxmlElement):
89
+ """`a:gradFill` custom element class."""
90
+
91
+ _tag_seq = ("a:gsLst", "a:lin", "a:path", "a:tileRect")
92
+ gsLst = ZeroOrOne("a:gsLst", successors=_tag_seq[1:])
93
+ lin = ZeroOrOne("a:lin", successors=_tag_seq[2:])
94
+ path = ZeroOrOne("a:path", successors=_tag_seq[3:])
95
+ del _tag_seq
96
+
97
+ @classmethod
98
+ def new_gradFill(cls):
99
+ """Return newly-created "loose" default gradient subtree."""
100
+ return parse_xml(
101
+ '<a:gradFill %s rotWithShape="1">\n'
102
+ " <a:gsLst>\n"
103
+ ' <a:gs pos="0">\n'
104
+ ' <a:schemeClr val="accent1">\n'
105
+ ' <a:tint val="100000"/>\n'
106
+ ' <a:shade val="100000"/>\n'
107
+ ' <a:satMod val="130000"/>\n'
108
+ " </a:schemeClr>\n"
109
+ " </a:gs>\n"
110
+ ' <a:gs pos="100000">\n'
111
+ ' <a:schemeClr val="accent1">\n'
112
+ ' <a:tint val="50000"/>\n'
113
+ ' <a:shade val="100000"/>\n'
114
+ ' <a:satMod val="350000"/>\n'
115
+ " </a:schemeClr>\n"
116
+ " </a:gs>\n"
117
+ " </a:gsLst>\n"
118
+ ' <a:lin scaled="0"/>\n'
119
+ "</a:gradFill>\n" % nsdecls("a")
120
+ )
121
+
122
+ def change_to_kind(self, kind):
123
+ """Switch the gradient between linear and the non-linear path kinds.
124
+
125
+ `kind` is one of ``"linear" | "radial" | "rectangular" | "shape"``.
126
+ Removes whichever of `<a:lin>`/`<a:path>` is currently present and
127
+ adds the appropriate child. Returns the newly-added element so
128
+ callers can set additional attributes on it.
129
+ """
130
+ if kind == "linear":
131
+ self._remove_path()
132
+ self._remove_lin()
133
+ return self._add_lin()
134
+ path_attr = {"radial": "circle", "rectangular": "rect", "shape": "shape"}.get(kind)
135
+ if path_attr is None:
136
+ raise ValueError(
137
+ "gradient kind must be one of 'linear', 'radial', "
138
+ "'rectangular', 'shape'; got %r" % kind
139
+ )
140
+ self._remove_lin()
141
+ self._remove_path()
142
+ path_elm = self._add_path()
143
+ path_elm.path = path_attr
144
+ return path_elm
145
+
146
+ def _new_gsLst(self):
147
+ """Override default to add minimum subtree."""
148
+ return CT_GradientStopList.new_gsLst()
149
+
150
+
151
+ class CT_GradientStop(BaseOxmlElement):
152
+ """`a:gs` custom element class."""
153
+
154
+ eg_colorChoice = ZeroOrOneChoice(
155
+ (
156
+ Choice("a:scrgbClr"),
157
+ Choice("a:srgbClr"),
158
+ Choice("a:hslClr"),
159
+ Choice("a:sysClr"),
160
+ Choice("a:schemeClr"),
161
+ Choice("a:prstClr"),
162
+ ),
163
+ successors=(),
164
+ )
165
+ pos = RequiredAttribute("pos", ST_PositiveFixedPercentage)
166
+
167
+
168
+ class CT_GradientStopList(BaseOxmlElement):
169
+ """`a:gsLst` custom element class."""
170
+
171
+ gs = OneOrMore("a:gs")
172
+
173
+ @classmethod
174
+ def new_gsLst(cls):
175
+ """Return newly-created "loose" default stop-list subtree.
176
+
177
+ An `a:gsLst` element must have at least two `a:gs` children. These
178
+ are the default from the PowerPoint built-in "White" template.
179
+ """
180
+ return parse_xml(
181
+ "<a:gsLst %s>\n"
182
+ ' <a:gs pos="0">\n'
183
+ ' <a:schemeClr val="accent1">\n'
184
+ ' <a:tint val="100000"/>\n'
185
+ ' <a:shade val="100000"/>\n'
186
+ ' <a:satMod val="130000"/>\n'
187
+ " </a:schemeClr>\n"
188
+ " </a:gs>\n"
189
+ ' <a:gs pos="100000">\n'
190
+ ' <a:schemeClr val="accent1">\n'
191
+ ' <a:tint val="50000"/>\n'
192
+ ' <a:shade val="100000"/>\n'
193
+ ' <a:satMod val="350000"/>\n'
194
+ " </a:schemeClr>\n"
195
+ " </a:gs>\n"
196
+ "</a:gsLst>\n" % nsdecls("a")
197
+ )
198
+
199
+
200
+ class CT_GroupFillProperties(BaseOxmlElement):
201
+ """`a:grpFill` custom element class"""
202
+
203
+
204
+ class CT_LinearShadeProperties(BaseOxmlElement):
205
+ """`a:lin` custom element class"""
206
+
207
+ ang = OptionalAttribute("ang", ST_PositiveFixedAngle)
208
+
209
+
210
+ class CT_NoFillProperties(BaseOxmlElement):
211
+ """`a:noFill` custom element class"""
212
+
213
+
214
+ class CT_PatternFillProperties(BaseOxmlElement):
215
+ """`a:pattFill` custom element class"""
216
+
217
+ _tag_seq = ("a:fgClr", "a:bgClr")
218
+ fgClr = ZeroOrOne("a:fgClr", successors=_tag_seq[1:])
219
+ bgClr = ZeroOrOne("a:bgClr", successors=_tag_seq[2:])
220
+ del _tag_seq
221
+ prst = OptionalAttribute("prst", MSO_PATTERN_TYPE)
222
+
223
+ def _new_bgClr(self):
224
+ """Override default to add minimum subtree."""
225
+ xml = ("<a:bgClr %s>\n" ' <a:srgbClr val="FFFFFF"/>\n' "</a:bgClr>\n") % nsdecls("a")
226
+ bgClr = parse_xml(xml)
227
+ return bgClr
228
+
229
+ def _new_fgClr(self):
230
+ """Override default to add minimum subtree."""
231
+ xml = ("<a:fgClr %s>\n" ' <a:srgbClr val="000000"/>\n' "</a:fgClr>\n") % nsdecls("a")
232
+ fgClr = parse_xml(xml)
233
+ return fgClr
234
+
235
+
236
+ class CT_RelativeRect(BaseOxmlElement):
237
+ """`a:srcRect` element and perhaps others."""
238
+
239
+ l = OptionalAttribute("l", ST_Percentage, default=0.0) # noqa
240
+ t = OptionalAttribute("t", ST_Percentage, default=0.0)
241
+ r = OptionalAttribute("r", ST_Percentage, default=0.0)
242
+ b = OptionalAttribute("b", ST_Percentage, default=0.0)
243
+
244
+
245
+ class CT_AlphaModFixEffect(BaseOxmlElement):
246
+ """`<a:alphaModFix>` element — scales the alpha (opacity) of an image.
247
+
248
+ `amt` is a `ST_PositiveFixedPercentage` where ``1.0`` (100%) means fully
249
+ opaque and ``0.0`` means fully transparent. When absent, the element is
250
+ treated as 100% opaque by PowerPoint.
251
+ """
252
+
253
+ amt = OptionalAttribute("amt", ST_PositiveFixedPercentage, default=1.0)
254
+
255
+
256
+ class CT_BiLevelEffect(BaseOxmlElement):
257
+ """`<a:biLevel>` element — converts the image to a two-color (black/white) palette.
258
+
259
+ `thresh` is the luminance threshold: pixels darker than this become black,
260
+ brighter ones become white. ``0.5`` (50%) approximates PowerPoint's "Washout" preset.
261
+
262
+ `thresh` is **required** by ``CT_BiLevelEffect`` in ISO/IEC 29500. It must be
263
+ a ``RequiredAttribute``: as an ``OptionalAttribute`` with ``default=0.5``,
264
+ assigning the (common) value ``0.5`` made the serializer omit the attribute,
265
+ producing a schema-invalid ``<a:biLevel/>`` that PowerPoint repairs.
266
+ """
267
+
268
+ thresh = RequiredAttribute("thresh", ST_PositiveFixedPercentage)
269
+
270
+
271
+ _DUOTONE_COLOR_CHOICES = (
272
+ Choice("a:scrgbClr"),
273
+ Choice("a:srgbClr"),
274
+ Choice("a:hslClr"),
275
+ Choice("a:sysClr"),
276
+ Choice("a:schemeClr"),
277
+ Choice("a:prstClr"),
278
+ )
279
+
280
+
281
+ class CT_DuotoneEffect(BaseOxmlElement):
282
+ """`<a:duotone>` element — maps the image to two-color tone.
283
+
284
+ Contains exactly two color-choice child elements (dark tone and light tone).
285
+ """
286
+
287
+
288
+ class CT_GrayscaleEffect(BaseOxmlElement):
289
+ """`<a:grayscl>` element — converts the image to grayscale. No attributes."""
290
+
291
+
292
+ class CT_LuminanceEffect(BaseOxmlElement):
293
+ """`<a:lum>` element — adjusts the brightness and contrast of an image.
294
+
295
+ Both `bright` and `contrast` are `ST_Percentage` floats in the range
296
+ ``[-1.0, 1.0]`` where ``0.0`` means no change.
297
+ """
298
+
299
+ bright = OptionalAttribute("bright", ST_FixedPercentage, default=0.0)
300
+ contrast = OptionalAttribute("contrast", ST_FixedPercentage, default=0.0)
301
+
302
+
303
+ class CT_SolidColorFillProperties(BaseOxmlElement):
304
+ """`a:solidFill` custom element class."""
305
+
306
+ eg_colorChoice = ZeroOrOneChoice(
307
+ (
308
+ Choice("a:scrgbClr"),
309
+ Choice("a:srgbClr"),
310
+ Choice("a:hslClr"),
311
+ Choice("a:sysClr"),
312
+ Choice("a:schemeClr"),
313
+ Choice("a:prstClr"),
314
+ ),
315
+ successors=(),
316
+ )
pptx2/oxml/dml/line.py ADDED
@@ -0,0 +1,12 @@
1
+ """lxml custom element classes for DrawingML line-related XML elements."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pptx2.enum.dml import MSO_LINE_DASH_STYLE
6
+ from pptx2.oxml.xmlchemy import BaseOxmlElement, OptionalAttribute
7
+
8
+
9
+ class CT_PresetLineDashProperties(BaseOxmlElement):
10
+ """`a:prstDash` custom element class"""
11
+
12
+ val = OptionalAttribute("val", MSO_LINE_DASH_STYLE)
@@ -0,0 +1,110 @@
1
+ """lxml custom element classes for DrawingML 3-D shape elements."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pptx2.enum.dml import BevelPreset, PresetMaterial
6
+ from pptx2.oxml.simpletypes import ST_PositiveCoordinate, XsdString
7
+ from pptx2.oxml.xmlchemy import (
8
+ BaseOxmlElement,
9
+ Choice,
10
+ OptionalAttribute,
11
+ RequiredAttribute,
12
+ ZeroOrOne,
13
+ ZeroOrOneChoice,
14
+ )
15
+
16
+ _COLOR_CHOICES = (
17
+ Choice("a:scrgbClr"),
18
+ Choice("a:srgbClr"),
19
+ Choice("a:hslClr"),
20
+ Choice("a:sysClr"),
21
+ Choice("a:schemeClr"),
22
+ Choice("a:prstClr"),
23
+ )
24
+
25
+
26
+ class CT_Bevel(BaseOxmlElement):
27
+ """`<a:bevelT>` / `<a:bevelB>` element — describes a top or bottom bevel on a 3-D shape.
28
+
29
+ The ``prst`` attribute selects from a set of preset bevel profiles. ``w`` and ``h`` control
30
+ the bevel width and height in EMU.
31
+ """
32
+
33
+ w = OptionalAttribute("w", ST_PositiveCoordinate)
34
+ h = OptionalAttribute("h", ST_PositiveCoordinate)
35
+ prst = OptionalAttribute("prst", BevelPreset)
36
+
37
+
38
+ class CT_Shape3D(BaseOxmlElement):
39
+ """`<a:sp3d>` element — describes 3-D properties for a single shape.
40
+
41
+ Contains optional top and bottom bevel elements, extrusion and contour colour children,
42
+ and several sizing / material attributes.
43
+ """
44
+
45
+ _tag_seq = (
46
+ "a:bevelT",
47
+ "a:bevelB",
48
+ "a:extrusionClr",
49
+ "a:contourClr",
50
+ "a:extLst",
51
+ )
52
+ bevelT = ZeroOrOne("a:bevelT", successors=_tag_seq[1:])
53
+ bevelB = ZeroOrOne("a:bevelB", successors=_tag_seq[2:])
54
+ extrusionClr = ZeroOrOne("a:extrusionClr", successors=_tag_seq[3:])
55
+ contourClr = ZeroOrOne("a:contourClr", successors=_tag_seq[4:])
56
+ del _tag_seq
57
+
58
+ extrusionH = OptionalAttribute("extrusionH", ST_PositiveCoordinate)
59
+ contourW = OptionalAttribute("contourW", ST_PositiveCoordinate)
60
+ prstMaterial = OptionalAttribute("prstMaterial", PresetMaterial)
61
+
62
+
63
+ class CT_ExtrusionColor(BaseOxmlElement):
64
+ """`<a:extrusionClr>` element — colour of the 3-D extrusion."""
65
+
66
+ eg_colorChoice = ZeroOrOneChoice(_COLOR_CHOICES, successors=())
67
+
68
+
69
+ class CT_ContourColor(BaseOxmlElement):
70
+ """`<a:contourClr>` element — colour of the 3-D contour (edge)."""
71
+
72
+ eg_colorChoice = ZeroOrOneChoice(_COLOR_CHOICES, successors=())
73
+
74
+
75
+ class CT_Camera(BaseOxmlElement):
76
+ """`<a:camera>` element — the scene camera within `<a:scene3d>`.
77
+
78
+ The ``prst`` attribute (preset camera type, e.g. ``orthographicFront``) is ``use="required"``
79
+ in the OOXML schema (``CT_Camera``), so it is modelled as a ``RequiredAttribute`` — a plain
80
+ string so callers / defaults can write any preset name without an exhaustive enum.
81
+ """
82
+
83
+ prst = RequiredAttribute("prst", XsdString)
84
+
85
+
86
+ class CT_LightRig(BaseOxmlElement):
87
+ """`<a:lightRig>` element — the scene light rig within `<a:scene3d>`.
88
+
89
+ Both ``rig`` (e.g. ``threePt``) and ``dir`` (e.g. ``t``) are ``use="required"`` in the OOXML
90
+ schema (``CT_LightRig``), so they are modelled as ``RequiredAttribute`` for the same reason as
91
+ :class:`CT_Camera`.
92
+ """
93
+
94
+ rig = RequiredAttribute("rig", XsdString)
95
+ dir = RequiredAttribute("dir", XsdString)
96
+
97
+
98
+ class CT_Scene3D(BaseOxmlElement):
99
+ """`<a:scene3d>` element — scene-level 3-D rendering settings.
100
+
101
+ Contains a required ``<a:camera>`` and ``<a:lightRig>`` child (in that order). PowerPoint
102
+ rejects a deck whose ``<a:scene3d>`` is empty while a sibling ``<a:sp3d>`` is present, so the
103
+ creating path (:meth:`pptx2.dml.three_d.ThreeDFormat._get_or_add_sp3d`) always populates
104
+ both children with safe defaults.
105
+ """
106
+
107
+ _tag_seq = ("a:camera", "a:lightRig", "a:extLst")
108
+ camera = ZeroOrOne("a:camera", successors=_tag_seq[1:])
109
+ lightRig = ZeroOrOne("a:lightRig", successors=_tag_seq[2:])
110
+ del _tag_seq
pptx2/oxml/ns.py ADDED
@@ -0,0 +1,135 @@
1
+ """Namespace related objects."""
2
+
3
+ from __future__ import annotations
4
+
5
+
6
+ # -- Maps namespace prefix to namespace name for all known PowerPoint XML namespaces --
7
+ _nsmap = {
8
+ "a": "http://schemas.openxmlformats.org/drawingml/2006/main",
9
+ "a14": "http://schemas.microsoft.com/office/drawing/2010/main",
10
+ "asvg": "http://schemas.microsoft.com/office/drawing/2016/SVG/main",
11
+ "c": "http://schemas.openxmlformats.org/drawingml/2006/chart",
12
+ "cp": "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
13
+ "ct": "http://schemas.openxmlformats.org/package/2006/content-types",
14
+ "dc": "http://purl.org/dc/elements/1.1/",
15
+ "dcmitype": "http://purl.org/dc/dcmitype/",
16
+ "dcterms": "http://purl.org/dc/terms/",
17
+ "dgm": "http://schemas.openxmlformats.org/drawingml/2006/diagram",
18
+ "ep": "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties",
19
+ "i": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
20
+ "m": "http://schemas.openxmlformats.org/officeDocument/2006/math",
21
+ "mo": "http://schemas.microsoft.com/office/mac/office/2008/main",
22
+ "mv": "urn:schemas-microsoft-com:mac:vml",
23
+ "o": "urn:schemas-microsoft-com:office:office",
24
+ "p": "http://schemas.openxmlformats.org/presentationml/2006/main",
25
+ "p14": "http://schemas.microsoft.com/office/powerpoint/2010/main",
26
+ "p15": "http://schemas.microsoft.com/office/powerpoint/2012/main",
27
+ "p159": "http://schemas.microsoft.com/office/powerpoint/2015/09/main",
28
+ "pd": "http://schemas.openxmlformats.org/drawingml/2006/presentationDrawing",
29
+ "pic": "http://schemas.openxmlformats.org/drawingml/2006/picture",
30
+ "pr": "http://schemas.openxmlformats.org/package/2006/relationships",
31
+ "r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
32
+ "sl": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout",
33
+ "v": "urn:schemas-microsoft-com:vml",
34
+ "ve": "http://schemas.openxmlformats.org/markup-compatibility/2006",
35
+ "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
36
+ "w10": "urn:schemas-microsoft-com:office:word",
37
+ "wne": "http://schemas.microsoft.com/office/word/2006/wordml",
38
+ "wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
39
+ "xsi": "http://www.w3.org/2001/XMLSchema-instance",
40
+ }
41
+
42
+ pfxmap = {value: key for key, value in _nsmap.items()}
43
+
44
+
45
+ class NamespacePrefixedTag(str):
46
+ """Value object that knows the semantics of an XML tag having a namespace prefix."""
47
+
48
+ def __new__(cls, nstag: str):
49
+ return super(NamespacePrefixedTag, cls).__new__(cls, nstag)
50
+
51
+ def __init__(self, nstag: str):
52
+ self._pfx, self._local_part = nstag.split(":")
53
+ self._ns_uri = _nsmap[self._pfx]
54
+
55
+ @classmethod
56
+ def from_clark_name(cls, clark_name: str) -> NamespacePrefixedTag:
57
+ nsuri, local_name = clark_name[1:].split("}")
58
+ nstag = "%s:%s" % (pfxmap[nsuri], local_name)
59
+ return cls(nstag)
60
+
61
+ @property
62
+ def clark_name(self):
63
+ return "{%s}%s" % (self._ns_uri, self._local_part)
64
+
65
+ @property
66
+ def local_part(self):
67
+ """
68
+ Return the local part of the tag as a string. E.g. 'foobar' is
69
+ returned for tag 'f:foobar'.
70
+ """
71
+ return self._local_part
72
+
73
+ @property
74
+ def nsmap(self):
75
+ """
76
+ Return a dict having a single member, mapping the namespace prefix of
77
+ this tag to it's namespace name (e.g. {'f': 'http://foo/bar'}). This
78
+ is handy for passing to xpath calls and other uses.
79
+ """
80
+ return {self._pfx: self._ns_uri}
81
+
82
+ @property
83
+ def nspfx(self):
84
+ """
85
+ Return the string namespace prefix for the tag, e.g. 'f' is returned
86
+ for tag 'f:foobar'.
87
+ """
88
+ return self._pfx
89
+
90
+ @property
91
+ def nsuri(self):
92
+ """
93
+ Return the namespace URI for the tag, e.g. 'http://foo/bar' would be
94
+ returned for tag 'f:foobar' if the 'f' prefix maps to
95
+ 'http://foo/bar' in _nsmap.
96
+ """
97
+ return self._ns_uri
98
+
99
+
100
+ def namespaces(*prefixes: str):
101
+ """Return a dict containing the subset namespace prefix mappings specified by *prefixes*.
102
+
103
+ Any number of namespace prefixes can be supplied, e.g. namespaces('a', 'r', 'p').
104
+ """
105
+ return {pfx: _nsmap[pfx] for pfx in prefixes}
106
+
107
+
108
+ nsmap = namespaces # alias for more compact use with Element()
109
+
110
+
111
+ def nsdecls(*prefixes: str):
112
+ return " ".join(['xmlns:%s="%s"' % (pfx, _nsmap[pfx]) for pfx in prefixes])
113
+
114
+
115
+ def nsuri(nspfx: str):
116
+ """Return the namespace URI corresponding to `nspfx`.
117
+
118
+ Example:
119
+
120
+ >>> nsuri("p")
121
+ "http://schemas.openxmlformats.org/presentationml/2006/main"
122
+ """
123
+ return _nsmap[nspfx]
124
+
125
+
126
+ def qn(namespace_prefixed_tag: str) -> str:
127
+ """Return a Clark-notation qualified tag name corresponding to `namespace_prefixed_tag`.
128
+
129
+ `namespace_prefixed_tag` is a string like 'p:body'. 'qn' stands for `qualified name`.
130
+
131
+ As an example, `qn("p:cSld")` returns:
132
+ `"{http://schemas.openxmlformats.org/drawingml/2006/main}cSld"`.
133
+ """
134
+ nsptag = NamespacePrefixedTag(namespace_prefixed_tag)
135
+ return nsptag.clark_name