ps-python-pptx 1.1.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.
- pptx/__init__.py +84 -0
- pptx/action.py +270 -0
- pptx/api.py +49 -0
- pptx/chart/__init__.py +0 -0
- pptx/chart/axis.py +523 -0
- pptx/chart/category.py +200 -0
- pptx/chart/chart.py +280 -0
- pptx/chart/data.py +864 -0
- pptx/chart/datalabel.py +288 -0
- pptx/chart/legend.py +79 -0
- pptx/chart/marker.py +70 -0
- pptx/chart/plot.py +412 -0
- pptx/chart/point.py +101 -0
- pptx/chart/series.py +258 -0
- pptx/chart/xlsx.py +272 -0
- pptx/chart/xmlwriter.py +1840 -0
- pptx/dml/__init__.py +0 -0
- pptx/dml/chtfmt.py +40 -0
- pptx/dml/color.py +301 -0
- pptx/dml/effect.py +41 -0
- pptx/dml/fill.py +468 -0
- pptx/dml/line.py +100 -0
- pptx/enum/__init__.py +0 -0
- pptx/enum/action.py +71 -0
- pptx/enum/base.py +175 -0
- pptx/enum/chart.py +492 -0
- pptx/enum/dml.py +405 -0
- pptx/enum/lang.py +685 -0
- pptx/enum/shapes.py +1029 -0
- pptx/enum/text.py +371 -0
- pptx/exc.py +23 -0
- pptx/media.py +197 -0
- pptx/opc/__init__.py +0 -0
- pptx/opc/constants.py +331 -0
- pptx/opc/oxml.py +188 -0
- pptx/opc/package.py +762 -0
- pptx/opc/packuri.py +109 -0
- pptx/opc/serialized.py +296 -0
- pptx/opc/shared.py +20 -0
- pptx/opc/spec.py +44 -0
- pptx/oxml/__init__.py +492 -0
- pptx/oxml/action.py +53 -0
- pptx/oxml/chart/__init__.py +0 -0
- pptx/oxml/chart/axis.py +297 -0
- pptx/oxml/chart/chart.py +282 -0
- pptx/oxml/chart/datalabel.py +252 -0
- pptx/oxml/chart/legend.py +72 -0
- pptx/oxml/chart/marker.py +61 -0
- pptx/oxml/chart/plot.py +345 -0
- pptx/oxml/chart/series.py +254 -0
- pptx/oxml/chart/shared.py +219 -0
- pptx/oxml/coreprops.py +288 -0
- pptx/oxml/dml/__init__.py +0 -0
- pptx/oxml/dml/color.py +111 -0
- pptx/oxml/dml/fill.py +197 -0
- pptx/oxml/dml/line.py +12 -0
- pptx/oxml/ns.py +129 -0
- pptx/oxml/presentation.py +130 -0
- pptx/oxml/shapes/__init__.py +19 -0
- pptx/oxml/shapes/autoshape.py +455 -0
- pptx/oxml/shapes/connector.py +107 -0
- pptx/oxml/shapes/graphfrm.py +342 -0
- pptx/oxml/shapes/groupshape.py +280 -0
- pptx/oxml/shapes/picture.py +270 -0
- pptx/oxml/shapes/shared.py +523 -0
- pptx/oxml/simpletypes.py +740 -0
- pptx/oxml/slide.py +347 -0
- pptx/oxml/table.py +588 -0
- pptx/oxml/text.py +748 -0
- pptx/oxml/theme.py +29 -0
- pptx/oxml/xmlchemy.py +717 -0
- pptx/package.py +222 -0
- pptx/parts/__init__.py +0 -0
- pptx/parts/chart.py +95 -0
- pptx/parts/coreprops.py +167 -0
- pptx/parts/embeddedpackage.py +93 -0
- pptx/parts/image.py +275 -0
- pptx/parts/media.py +37 -0
- pptx/parts/presentation.py +126 -0
- pptx/parts/slide.py +297 -0
- pptx/parts/theme.py +13 -0
- pptx/presentation.py +113 -0
- pptx/py.typed +0 -0
- pptx/shapes/__init__.py +26 -0
- pptx/shapes/autoshape.py +355 -0
- pptx/shapes/base.py +293 -0
- pptx/shapes/connector.py +297 -0
- pptx/shapes/freeform.py +337 -0
- pptx/shapes/graphfrm.py +166 -0
- pptx/shapes/group.py +69 -0
- pptx/shapes/picture.py +203 -0
- pptx/shapes/placeholder.py +407 -0
- pptx/shapes/shapetree.py +1190 -0
- pptx/shared.py +82 -0
- pptx/slide.py +577 -0
- pptx/spec.py +632 -0
- pptx/table.py +520 -0
- pptx/templates/default.pptx +0 -0
- pptx/templates/docx-icon.emf +0 -0
- pptx/templates/generic-icon.emf +0 -0
- pptx/templates/notes.xml +23 -0
- pptx/templates/notesMaster.xml +352 -0
- pptx/templates/pptx-icon.emf +0 -0
- pptx/templates/theme.xml +321 -0
- pptx/templates/xlsx-icon.emf +0 -0
- pptx/text/__init__.py +0 -0
- pptx/text/fonts.py +399 -0
- pptx/text/layout.py +325 -0
- pptx/text/text.py +770 -0
- pptx/theme.py +135 -0
- pptx/types.py +36 -0
- pptx/util.py +284 -0
- ps_python_pptx-1.1.0.dist-info/METADATA +75 -0
- ps_python_pptx-1.1.0.dist-info/RECORD +117 -0
- ps_python_pptx-1.1.0.dist-info/WHEEL +5 -0
- ps_python_pptx-1.1.0.dist-info/licenses/LICENSE +20 -0
- ps_python_pptx-1.1.0.dist-info/top_level.txt +1 -0
pptx/oxml/dml/fill.py
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"""lxml custom element classes for DrawingML-related XML elements."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pptx.enum.dml import MSO_PATTERN_TYPE
|
|
6
|
+
from pptx.oxml import parse_xml
|
|
7
|
+
from pptx.oxml.ns import nsdecls
|
|
8
|
+
from pptx.oxml.simpletypes import (
|
|
9
|
+
ST_Percentage,
|
|
10
|
+
ST_PositiveFixedAngle,
|
|
11
|
+
ST_PositiveFixedPercentage,
|
|
12
|
+
ST_RelationshipId,
|
|
13
|
+
)
|
|
14
|
+
from pptx.oxml.xmlchemy import (
|
|
15
|
+
BaseOxmlElement,
|
|
16
|
+
Choice,
|
|
17
|
+
OneOrMore,
|
|
18
|
+
OptionalAttribute,
|
|
19
|
+
RequiredAttribute,
|
|
20
|
+
ZeroOrOne,
|
|
21
|
+
ZeroOrOneChoice,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CT_Blip(BaseOxmlElement):
|
|
26
|
+
"""
|
|
27
|
+
<a:blip> element
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
rEmbed = OptionalAttribute("r:embed", ST_RelationshipId)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class CT_BlipFillProperties(BaseOxmlElement):
|
|
34
|
+
"""
|
|
35
|
+
Custom element class for <a:blipFill> element.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
_tag_seq = ("a:blip", "a:srcRect", "a:tile", "a:stretch")
|
|
39
|
+
blip = ZeroOrOne("a:blip", successors=_tag_seq[1:])
|
|
40
|
+
srcRect = ZeroOrOne("a:srcRect", successors=_tag_seq[2:])
|
|
41
|
+
del _tag_seq
|
|
42
|
+
|
|
43
|
+
def crop(self, cropping):
|
|
44
|
+
"""
|
|
45
|
+
Set `a:srcRect` child to crop according to *cropping* values.
|
|
46
|
+
"""
|
|
47
|
+
srcRect = self._add_srcRect()
|
|
48
|
+
srcRect.l, srcRect.t, srcRect.r, srcRect.b = cropping
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class CT_GradientFillProperties(BaseOxmlElement):
|
|
52
|
+
"""`a:gradFill` custom element class."""
|
|
53
|
+
|
|
54
|
+
_tag_seq = ("a:gsLst", "a:lin", "a:path", "a:tileRect")
|
|
55
|
+
gsLst = ZeroOrOne("a:gsLst", successors=_tag_seq[1:])
|
|
56
|
+
lin = ZeroOrOne("a:lin", successors=_tag_seq[2:])
|
|
57
|
+
path = ZeroOrOne("a:path", successors=_tag_seq[3:])
|
|
58
|
+
del _tag_seq
|
|
59
|
+
|
|
60
|
+
@classmethod
|
|
61
|
+
def new_gradFill(cls):
|
|
62
|
+
"""Return newly-created "loose" default gradient subtree."""
|
|
63
|
+
return parse_xml(
|
|
64
|
+
'<a:gradFill %s rotWithShape="1">\n'
|
|
65
|
+
" <a:gsLst>\n"
|
|
66
|
+
' <a:gs pos="0">\n'
|
|
67
|
+
' <a:schemeClr val="accent1">\n'
|
|
68
|
+
' <a:tint val="100000"/>\n'
|
|
69
|
+
' <a:shade val="100000"/>\n'
|
|
70
|
+
' <a:satMod val="130000"/>\n'
|
|
71
|
+
" </a:schemeClr>\n"
|
|
72
|
+
" </a:gs>\n"
|
|
73
|
+
' <a:gs pos="100000">\n'
|
|
74
|
+
' <a:schemeClr val="accent1">\n'
|
|
75
|
+
' <a:tint val="50000"/>\n'
|
|
76
|
+
' <a:shade val="100000"/>\n'
|
|
77
|
+
' <a:satMod val="350000"/>\n'
|
|
78
|
+
" </a:schemeClr>\n"
|
|
79
|
+
" </a:gs>\n"
|
|
80
|
+
" </a:gsLst>\n"
|
|
81
|
+
' <a:lin scaled="0"/>\n'
|
|
82
|
+
"</a:gradFill>\n" % nsdecls("a")
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
def _new_gsLst(self):
|
|
86
|
+
"""Override default to add minimum subtree."""
|
|
87
|
+
return CT_GradientStopList.new_gsLst()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class CT_GradientStop(BaseOxmlElement):
|
|
91
|
+
"""`a:gs` custom element class."""
|
|
92
|
+
|
|
93
|
+
eg_colorChoice = ZeroOrOneChoice(
|
|
94
|
+
(
|
|
95
|
+
Choice("a:scrgbClr"),
|
|
96
|
+
Choice("a:srgbClr"),
|
|
97
|
+
Choice("a:hslClr"),
|
|
98
|
+
Choice("a:sysClr"),
|
|
99
|
+
Choice("a:schemeClr"),
|
|
100
|
+
Choice("a:prstClr"),
|
|
101
|
+
),
|
|
102
|
+
successors=(),
|
|
103
|
+
)
|
|
104
|
+
pos = RequiredAttribute("pos", ST_PositiveFixedPercentage)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class CT_GradientStopList(BaseOxmlElement):
|
|
108
|
+
"""`a:gsLst` custom element class."""
|
|
109
|
+
|
|
110
|
+
gs = OneOrMore("a:gs")
|
|
111
|
+
|
|
112
|
+
@classmethod
|
|
113
|
+
def new_gsLst(cls):
|
|
114
|
+
"""Return newly-created "loose" default stop-list subtree.
|
|
115
|
+
|
|
116
|
+
An `a:gsLst` element must have at least two `a:gs` children. These
|
|
117
|
+
are the default from the PowerPoint built-in "White" template.
|
|
118
|
+
"""
|
|
119
|
+
return parse_xml(
|
|
120
|
+
"<a:gsLst %s>\n"
|
|
121
|
+
' <a:gs pos="0">\n'
|
|
122
|
+
' <a:schemeClr val="accent1">\n'
|
|
123
|
+
' <a:tint val="100000"/>\n'
|
|
124
|
+
' <a:shade val="100000"/>\n'
|
|
125
|
+
' <a:satMod val="130000"/>\n'
|
|
126
|
+
" </a:schemeClr>\n"
|
|
127
|
+
" </a:gs>\n"
|
|
128
|
+
' <a:gs pos="100000">\n'
|
|
129
|
+
' <a:schemeClr val="accent1">\n'
|
|
130
|
+
' <a:tint val="50000"/>\n'
|
|
131
|
+
' <a:shade val="100000"/>\n'
|
|
132
|
+
' <a:satMod val="350000"/>\n'
|
|
133
|
+
" </a:schemeClr>\n"
|
|
134
|
+
" </a:gs>\n"
|
|
135
|
+
"</a:gsLst>\n" % nsdecls("a")
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class CT_GroupFillProperties(BaseOxmlElement):
|
|
140
|
+
"""`a:grpFill` custom element class"""
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class CT_LinearShadeProperties(BaseOxmlElement):
|
|
144
|
+
"""`a:lin` custom element class"""
|
|
145
|
+
|
|
146
|
+
ang = OptionalAttribute("ang", ST_PositiveFixedAngle)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class CT_NoFillProperties(BaseOxmlElement):
|
|
150
|
+
"""`a:noFill` custom element class"""
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class CT_PatternFillProperties(BaseOxmlElement):
|
|
154
|
+
"""`a:pattFill` custom element class"""
|
|
155
|
+
|
|
156
|
+
_tag_seq = ("a:fgClr", "a:bgClr")
|
|
157
|
+
fgClr = ZeroOrOne("a:fgClr", successors=_tag_seq[1:])
|
|
158
|
+
bgClr = ZeroOrOne("a:bgClr", successors=_tag_seq[2:])
|
|
159
|
+
del _tag_seq
|
|
160
|
+
prst = OptionalAttribute("prst", MSO_PATTERN_TYPE)
|
|
161
|
+
|
|
162
|
+
def _new_bgClr(self):
|
|
163
|
+
"""Override default to add minimum subtree."""
|
|
164
|
+
xml = ("<a:bgClr %s>\n" ' <a:srgbClr val="FFFFFF"/>\n' "</a:bgClr>\n") % nsdecls("a")
|
|
165
|
+
bgClr = parse_xml(xml)
|
|
166
|
+
return bgClr
|
|
167
|
+
|
|
168
|
+
def _new_fgClr(self):
|
|
169
|
+
"""Override default to add minimum subtree."""
|
|
170
|
+
xml = ("<a:fgClr %s>\n" ' <a:srgbClr val="000000"/>\n' "</a:fgClr>\n") % nsdecls("a")
|
|
171
|
+
fgClr = parse_xml(xml)
|
|
172
|
+
return fgClr
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class CT_RelativeRect(BaseOxmlElement):
|
|
176
|
+
"""`a:srcRect` element and perhaps others."""
|
|
177
|
+
|
|
178
|
+
l = OptionalAttribute("l", ST_Percentage, default=0.0) # noqa
|
|
179
|
+
t = OptionalAttribute("t", ST_Percentage, default=0.0)
|
|
180
|
+
r = OptionalAttribute("r", ST_Percentage, default=0.0)
|
|
181
|
+
b = OptionalAttribute("b", ST_Percentage, default=0.0)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class CT_SolidColorFillProperties(BaseOxmlElement):
|
|
185
|
+
"""`a:solidFill` custom element class."""
|
|
186
|
+
|
|
187
|
+
eg_colorChoice = ZeroOrOneChoice(
|
|
188
|
+
(
|
|
189
|
+
Choice("a:scrgbClr"),
|
|
190
|
+
Choice("a:srgbClr"),
|
|
191
|
+
Choice("a:hslClr"),
|
|
192
|
+
Choice("a:sysClr"),
|
|
193
|
+
Choice("a:schemeClr"),
|
|
194
|
+
Choice("a:prstClr"),
|
|
195
|
+
),
|
|
196
|
+
successors=(),
|
|
197
|
+
)
|
pptx/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 pptx.enum.dml import MSO_LINE_DASH_STYLE
|
|
6
|
+
from pptx.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)
|
pptx/oxml/ns.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
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
|
+
"c": "http://schemas.openxmlformats.org/drawingml/2006/chart",
|
|
10
|
+
"cp": "http://schemas.openxmlformats.org/package/2006/metadata/core-properties",
|
|
11
|
+
"ct": "http://schemas.openxmlformats.org/package/2006/content-types",
|
|
12
|
+
"dc": "http://purl.org/dc/elements/1.1/",
|
|
13
|
+
"dcmitype": "http://purl.org/dc/dcmitype/",
|
|
14
|
+
"dcterms": "http://purl.org/dc/terms/",
|
|
15
|
+
"ep": "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties",
|
|
16
|
+
"i": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
|
|
17
|
+
"m": "http://schemas.openxmlformats.org/officeDocument/2006/math",
|
|
18
|
+
"mo": "http://schemas.microsoft.com/office/mac/office/2008/main",
|
|
19
|
+
"mv": "urn:schemas-microsoft-com:mac:vml",
|
|
20
|
+
"o": "urn:schemas-microsoft-com:office:office",
|
|
21
|
+
"p": "http://schemas.openxmlformats.org/presentationml/2006/main",
|
|
22
|
+
"pd": "http://schemas.openxmlformats.org/drawingml/2006/presentationDrawing",
|
|
23
|
+
"pic": "http://schemas.openxmlformats.org/drawingml/2006/picture",
|
|
24
|
+
"pr": "http://schemas.openxmlformats.org/package/2006/relationships",
|
|
25
|
+
"r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
|
26
|
+
"sl": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout",
|
|
27
|
+
"v": "urn:schemas-microsoft-com:vml",
|
|
28
|
+
"ve": "http://schemas.openxmlformats.org/markup-compatibility/2006",
|
|
29
|
+
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
|
30
|
+
"w10": "urn:schemas-microsoft-com:office:word",
|
|
31
|
+
"wne": "http://schemas.microsoft.com/office/word/2006/wordml",
|
|
32
|
+
"wp": "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
|
|
33
|
+
"xsi": "http://www.w3.org/2001/XMLSchema-instance",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
pfxmap = {value: key for key, value in _nsmap.items()}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class NamespacePrefixedTag(str):
|
|
40
|
+
"""Value object that knows the semantics of an XML tag having a namespace prefix."""
|
|
41
|
+
|
|
42
|
+
def __new__(cls, nstag: str):
|
|
43
|
+
return super(NamespacePrefixedTag, cls).__new__(cls, nstag)
|
|
44
|
+
|
|
45
|
+
def __init__(self, nstag: str):
|
|
46
|
+
self._pfx, self._local_part = nstag.split(":")
|
|
47
|
+
self._ns_uri = _nsmap[self._pfx]
|
|
48
|
+
|
|
49
|
+
@classmethod
|
|
50
|
+
def from_clark_name(cls, clark_name: str) -> NamespacePrefixedTag:
|
|
51
|
+
nsuri, local_name = clark_name[1:].split("}")
|
|
52
|
+
nstag = "%s:%s" % (pfxmap[nsuri], local_name)
|
|
53
|
+
return cls(nstag)
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def clark_name(self):
|
|
57
|
+
return "{%s}%s" % (self._ns_uri, self._local_part)
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def local_part(self):
|
|
61
|
+
"""
|
|
62
|
+
Return the local part of the tag as a string. E.g. 'foobar' is
|
|
63
|
+
returned for tag 'f:foobar'.
|
|
64
|
+
"""
|
|
65
|
+
return self._local_part
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def nsmap(self):
|
|
69
|
+
"""
|
|
70
|
+
Return a dict having a single member, mapping the namespace prefix of
|
|
71
|
+
this tag to it's namespace name (e.g. {'f': 'http://foo/bar'}). This
|
|
72
|
+
is handy for passing to xpath calls and other uses.
|
|
73
|
+
"""
|
|
74
|
+
return {self._pfx: self._ns_uri}
|
|
75
|
+
|
|
76
|
+
@property
|
|
77
|
+
def nspfx(self):
|
|
78
|
+
"""
|
|
79
|
+
Return the string namespace prefix for the tag, e.g. 'f' is returned
|
|
80
|
+
for tag 'f:foobar'.
|
|
81
|
+
"""
|
|
82
|
+
return self._pfx
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def nsuri(self):
|
|
86
|
+
"""
|
|
87
|
+
Return the namespace URI for the tag, e.g. 'http://foo/bar' would be
|
|
88
|
+
returned for tag 'f:foobar' if the 'f' prefix maps to
|
|
89
|
+
'http://foo/bar' in _nsmap.
|
|
90
|
+
"""
|
|
91
|
+
return self._ns_uri
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def namespaces(*prefixes: str):
|
|
95
|
+
"""Return a dict containing the subset namespace prefix mappings specified by *prefixes*.
|
|
96
|
+
|
|
97
|
+
Any number of namespace prefixes can be supplied, e.g. namespaces('a', 'r', 'p').
|
|
98
|
+
"""
|
|
99
|
+
return {pfx: _nsmap[pfx] for pfx in prefixes}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
nsmap = namespaces # alias for more compact use with Element()
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def nsdecls(*prefixes: str):
|
|
106
|
+
return " ".join(['xmlns:%s="%s"' % (pfx, _nsmap[pfx]) for pfx in prefixes])
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def nsuri(nspfx: str):
|
|
110
|
+
"""Return the namespace URI corresponding to `nspfx`.
|
|
111
|
+
|
|
112
|
+
Example:
|
|
113
|
+
|
|
114
|
+
>>> nsuri("p")
|
|
115
|
+
"http://schemas.openxmlformats.org/presentationml/2006/main"
|
|
116
|
+
"""
|
|
117
|
+
return _nsmap[nspfx]
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def qn(namespace_prefixed_tag: str) -> str:
|
|
121
|
+
"""Return a Clark-notation qualified tag name corresponding to `namespace_prefixed_tag`.
|
|
122
|
+
|
|
123
|
+
`namespace_prefixed_tag` is a string like 'p:body'. 'qn' stands for `qualified name`.
|
|
124
|
+
|
|
125
|
+
As an example, `qn("p:cSld")` returns:
|
|
126
|
+
`"{http://schemas.openxmlformats.org/drawingml/2006/main}cSld"`.
|
|
127
|
+
"""
|
|
128
|
+
nsptag = NamespacePrefixedTag(namespace_prefixed_tag)
|
|
129
|
+
return nsptag.clark_name
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Custom element classes for presentation-related XML elements."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING, Callable, cast
|
|
6
|
+
|
|
7
|
+
from pptx.oxml.simpletypes import ST_SlideId, ST_SlideSizeCoordinate, XsdString
|
|
8
|
+
from pptx.oxml.xmlchemy import BaseOxmlElement, RequiredAttribute, ZeroOrMore, ZeroOrOne
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from pptx.util import Length
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class CT_Presentation(BaseOxmlElement):
|
|
15
|
+
"""`p:presentation` element, root of the Presentation part stored as `/ppt/presentation.xml`."""
|
|
16
|
+
|
|
17
|
+
get_or_add_sldSz: Callable[[], CT_SlideSize]
|
|
18
|
+
get_or_add_sldIdLst: Callable[[], CT_SlideIdList]
|
|
19
|
+
get_or_add_sldMasterIdLst: Callable[[], CT_SlideMasterIdList]
|
|
20
|
+
|
|
21
|
+
sldMasterIdLst: CT_SlideMasterIdList | None = (
|
|
22
|
+
ZeroOrOne( # pyright: ignore[reportAssignmentType]
|
|
23
|
+
"p:sldMasterIdLst",
|
|
24
|
+
successors=(
|
|
25
|
+
"p:notesMasterIdLst",
|
|
26
|
+
"p:handoutMasterIdLst",
|
|
27
|
+
"p:sldIdLst",
|
|
28
|
+
"p:sldSz",
|
|
29
|
+
"p:notesSz",
|
|
30
|
+
),
|
|
31
|
+
)
|
|
32
|
+
)
|
|
33
|
+
sldIdLst: CT_SlideIdList | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
|
|
34
|
+
"p:sldIdLst", successors=("p:sldSz", "p:notesSz")
|
|
35
|
+
)
|
|
36
|
+
sldSz: CT_SlideSize | None = ZeroOrOne( # pyright: ignore[reportAssignmentType]
|
|
37
|
+
"p:sldSz", successors=("p:notesSz",)
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class CT_SlideId(BaseOxmlElement):
|
|
42
|
+
"""`p:sldId` element.
|
|
43
|
+
|
|
44
|
+
Direct child of `p:sldIdLst` that contains an `rId` reference to a slide in the presentation.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
id: int = RequiredAttribute("id", ST_SlideId) # pyright: ignore[reportAssignmentType]
|
|
48
|
+
rId: str = RequiredAttribute("r:id", XsdString) # pyright: ignore[reportAssignmentType]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class CT_SlideIdList(BaseOxmlElement):
|
|
52
|
+
"""`p:sldIdLst` element.
|
|
53
|
+
|
|
54
|
+
Direct child of <p:presentation> that contains a list of the slide parts in the presentation.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
sldId_lst: list[CT_SlideId]
|
|
58
|
+
|
|
59
|
+
_add_sldId: Callable[..., CT_SlideId]
|
|
60
|
+
sldId = ZeroOrMore("p:sldId")
|
|
61
|
+
|
|
62
|
+
def add_sldId(self, rId: str) -> CT_SlideId:
|
|
63
|
+
"""Create and return a reference to a new `p:sldId` child element.
|
|
64
|
+
|
|
65
|
+
The new `p:sldId` element has its r:id attribute set to `rId`.
|
|
66
|
+
"""
|
|
67
|
+
return self._add_sldId(id=self._next_id, rId=rId)
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def _next_id(self) -> int:
|
|
71
|
+
"""The next available slide ID as an `int`.
|
|
72
|
+
|
|
73
|
+
Valid slide IDs start at 256. The next integer value greater than the max value in use is
|
|
74
|
+
chosen, which minimizes that chance of reusing the id of a deleted slide.
|
|
75
|
+
"""
|
|
76
|
+
MIN_SLIDE_ID = 256
|
|
77
|
+
MAX_SLIDE_ID = 2147483647
|
|
78
|
+
|
|
79
|
+
used_ids = [int(s) for s in cast("list[str]", self.xpath("./p:sldId/@id"))]
|
|
80
|
+
simple_next = max([MIN_SLIDE_ID - 1] + used_ids) + 1
|
|
81
|
+
if simple_next <= MAX_SLIDE_ID:
|
|
82
|
+
return simple_next
|
|
83
|
+
|
|
84
|
+
# -- fall back to search for next unused from bottom --
|
|
85
|
+
valid_used_ids = sorted(id for id in used_ids if (MIN_SLIDE_ID <= id <= MAX_SLIDE_ID))
|
|
86
|
+
return (
|
|
87
|
+
next(
|
|
88
|
+
candidate_id
|
|
89
|
+
for candidate_id, used_id in enumerate(valid_used_ids, start=MIN_SLIDE_ID)
|
|
90
|
+
if candidate_id != used_id
|
|
91
|
+
)
|
|
92
|
+
if valid_used_ids
|
|
93
|
+
else 256
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class CT_SlideMasterIdList(BaseOxmlElement):
|
|
98
|
+
"""`p:sldMasterIdLst` element.
|
|
99
|
+
|
|
100
|
+
Child of `p:presentation` containing references to the slide masters that belong to the
|
|
101
|
+
presentation.
|
|
102
|
+
"""
|
|
103
|
+
|
|
104
|
+
sldMasterId_lst: list[CT_SlideMasterIdListEntry]
|
|
105
|
+
|
|
106
|
+
sldMasterId = ZeroOrMore("p:sldMasterId")
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class CT_SlideMasterIdListEntry(BaseOxmlElement):
|
|
110
|
+
"""
|
|
111
|
+
``<p:sldMasterId>`` element, child of ``<p:sldMasterIdLst>`` containing
|
|
112
|
+
a reference to a slide master.
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
rId: str = RequiredAttribute("r:id", XsdString) # pyright: ignore[reportAssignmentType]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class CT_SlideSize(BaseOxmlElement):
|
|
119
|
+
"""`p:sldSz` element.
|
|
120
|
+
|
|
121
|
+
Direct child of <p:presentation> that contains the width and height of slides in the
|
|
122
|
+
presentation.
|
|
123
|
+
"""
|
|
124
|
+
|
|
125
|
+
cx: Length = RequiredAttribute( # pyright: ignore[reportAssignmentType]
|
|
126
|
+
"cx", ST_SlideSizeCoordinate
|
|
127
|
+
)
|
|
128
|
+
cy: Length = RequiredAttribute( # pyright: ignore[reportAssignmentType]
|
|
129
|
+
"cy", ST_SlideSizeCoordinate
|
|
130
|
+
)
|
|
@@ -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 pptx.oxml.shapes.autoshape import CT_Shape
|
|
11
|
+
from pptx.oxml.shapes.connector import CT_Connector
|
|
12
|
+
from pptx.oxml.shapes.graphfrm import CT_GraphicalObjectFrame
|
|
13
|
+
from pptx.oxml.shapes.groupshape import CT_GroupShape
|
|
14
|
+
from pptx.oxml.shapes.picture import CT_Picture
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
ShapeElement: TypeAlias = (
|
|
18
|
+
"CT_Connector | CT_GraphicalObjectFrame | CT_GroupShape | CT_Picture | CT_Shape"
|
|
19
|
+
)
|