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.
Files changed (117) hide show
  1. pptx/__init__.py +84 -0
  2. pptx/action.py +270 -0
  3. pptx/api.py +49 -0
  4. pptx/chart/__init__.py +0 -0
  5. pptx/chart/axis.py +523 -0
  6. pptx/chart/category.py +200 -0
  7. pptx/chart/chart.py +280 -0
  8. pptx/chart/data.py +864 -0
  9. pptx/chart/datalabel.py +288 -0
  10. pptx/chart/legend.py +79 -0
  11. pptx/chart/marker.py +70 -0
  12. pptx/chart/plot.py +412 -0
  13. pptx/chart/point.py +101 -0
  14. pptx/chart/series.py +258 -0
  15. pptx/chart/xlsx.py +272 -0
  16. pptx/chart/xmlwriter.py +1840 -0
  17. pptx/dml/__init__.py +0 -0
  18. pptx/dml/chtfmt.py +40 -0
  19. pptx/dml/color.py +301 -0
  20. pptx/dml/effect.py +41 -0
  21. pptx/dml/fill.py +468 -0
  22. pptx/dml/line.py +100 -0
  23. pptx/enum/__init__.py +0 -0
  24. pptx/enum/action.py +71 -0
  25. pptx/enum/base.py +175 -0
  26. pptx/enum/chart.py +492 -0
  27. pptx/enum/dml.py +405 -0
  28. pptx/enum/lang.py +685 -0
  29. pptx/enum/shapes.py +1029 -0
  30. pptx/enum/text.py +371 -0
  31. pptx/exc.py +23 -0
  32. pptx/media.py +197 -0
  33. pptx/opc/__init__.py +0 -0
  34. pptx/opc/constants.py +331 -0
  35. pptx/opc/oxml.py +188 -0
  36. pptx/opc/package.py +762 -0
  37. pptx/opc/packuri.py +109 -0
  38. pptx/opc/serialized.py +296 -0
  39. pptx/opc/shared.py +20 -0
  40. pptx/opc/spec.py +44 -0
  41. pptx/oxml/__init__.py +492 -0
  42. pptx/oxml/action.py +53 -0
  43. pptx/oxml/chart/__init__.py +0 -0
  44. pptx/oxml/chart/axis.py +297 -0
  45. pptx/oxml/chart/chart.py +282 -0
  46. pptx/oxml/chart/datalabel.py +252 -0
  47. pptx/oxml/chart/legend.py +72 -0
  48. pptx/oxml/chart/marker.py +61 -0
  49. pptx/oxml/chart/plot.py +345 -0
  50. pptx/oxml/chart/series.py +254 -0
  51. pptx/oxml/chart/shared.py +219 -0
  52. pptx/oxml/coreprops.py +288 -0
  53. pptx/oxml/dml/__init__.py +0 -0
  54. pptx/oxml/dml/color.py +111 -0
  55. pptx/oxml/dml/fill.py +197 -0
  56. pptx/oxml/dml/line.py +12 -0
  57. pptx/oxml/ns.py +129 -0
  58. pptx/oxml/presentation.py +130 -0
  59. pptx/oxml/shapes/__init__.py +19 -0
  60. pptx/oxml/shapes/autoshape.py +455 -0
  61. pptx/oxml/shapes/connector.py +107 -0
  62. pptx/oxml/shapes/graphfrm.py +342 -0
  63. pptx/oxml/shapes/groupshape.py +280 -0
  64. pptx/oxml/shapes/picture.py +270 -0
  65. pptx/oxml/shapes/shared.py +523 -0
  66. pptx/oxml/simpletypes.py +740 -0
  67. pptx/oxml/slide.py +347 -0
  68. pptx/oxml/table.py +588 -0
  69. pptx/oxml/text.py +748 -0
  70. pptx/oxml/theme.py +29 -0
  71. pptx/oxml/xmlchemy.py +717 -0
  72. pptx/package.py +222 -0
  73. pptx/parts/__init__.py +0 -0
  74. pptx/parts/chart.py +95 -0
  75. pptx/parts/coreprops.py +167 -0
  76. pptx/parts/embeddedpackage.py +93 -0
  77. pptx/parts/image.py +275 -0
  78. pptx/parts/media.py +37 -0
  79. pptx/parts/presentation.py +126 -0
  80. pptx/parts/slide.py +297 -0
  81. pptx/parts/theme.py +13 -0
  82. pptx/presentation.py +113 -0
  83. pptx/py.typed +0 -0
  84. pptx/shapes/__init__.py +26 -0
  85. pptx/shapes/autoshape.py +355 -0
  86. pptx/shapes/base.py +293 -0
  87. pptx/shapes/connector.py +297 -0
  88. pptx/shapes/freeform.py +337 -0
  89. pptx/shapes/graphfrm.py +166 -0
  90. pptx/shapes/group.py +69 -0
  91. pptx/shapes/picture.py +203 -0
  92. pptx/shapes/placeholder.py +407 -0
  93. pptx/shapes/shapetree.py +1190 -0
  94. pptx/shared.py +82 -0
  95. pptx/slide.py +577 -0
  96. pptx/spec.py +632 -0
  97. pptx/table.py +520 -0
  98. pptx/templates/default.pptx +0 -0
  99. pptx/templates/docx-icon.emf +0 -0
  100. pptx/templates/generic-icon.emf +0 -0
  101. pptx/templates/notes.xml +23 -0
  102. pptx/templates/notesMaster.xml +352 -0
  103. pptx/templates/pptx-icon.emf +0 -0
  104. pptx/templates/theme.xml +321 -0
  105. pptx/templates/xlsx-icon.emf +0 -0
  106. pptx/text/__init__.py +0 -0
  107. pptx/text/fonts.py +399 -0
  108. pptx/text/layout.py +325 -0
  109. pptx/text/text.py +770 -0
  110. pptx/theme.py +135 -0
  111. pptx/types.py +36 -0
  112. pptx/util.py +284 -0
  113. ps_python_pptx-1.1.0.dist-info/METADATA +75 -0
  114. ps_python_pptx-1.1.0.dist-info/RECORD +117 -0
  115. ps_python_pptx-1.1.0.dist-info/WHEEL +5 -0
  116. ps_python_pptx-1.1.0.dist-info/licenses/LICENSE +20 -0
  117. ps_python_pptx-1.1.0.dist-info/top_level.txt +1 -0
pptx/dml/__init__.py ADDED
File without changes
pptx/dml/chtfmt.py ADDED
@@ -0,0 +1,40 @@
1
+ """|ChartFormat| and related objects.
2
+
3
+ |ChartFormat| acts as proxy for the `spPr` element, which provides visual shape properties such as
4
+ line and fill for chart elements.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from pptx.dml.fill import FillFormat
10
+ from pptx.dml.line import LineFormat
11
+ from pptx.shared import ElementProxy
12
+ from pptx.util import lazyproperty
13
+
14
+
15
+ class ChartFormat(ElementProxy):
16
+ """
17
+ The |ChartFormat| object provides access to visual shape properties for
18
+ chart elements like |Axis|, |Series|, and |MajorGridlines|. It has two
19
+ properties, :attr:`fill` and :attr:`line`, which return a |FillFormat|
20
+ and |LineFormat| object respectively. The |ChartFormat| object is
21
+ provided by the :attr:`format` property on the target axis, series, etc.
22
+ """
23
+
24
+ @lazyproperty
25
+ def fill(self):
26
+ """
27
+ |FillFormat| instance for this object, providing access to fill
28
+ properties such as fill color.
29
+ """
30
+ spPr = self._element.get_or_add_spPr()
31
+ return FillFormat.from_fill_parent(spPr)
32
+
33
+ @lazyproperty
34
+ def line(self):
35
+ """
36
+ The |LineFormat| object providing access to the visual properties of
37
+ this object, such as line color and line style.
38
+ """
39
+ spPr = self._element.get_or_add_spPr()
40
+ return LineFormat(spPr)
pptx/dml/color.py ADDED
@@ -0,0 +1,301 @@
1
+ """DrawingML objects related to color, ColorFormat being the most prominent."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pptx.enum.dml import MSO_COLOR_TYPE, MSO_THEME_COLOR
6
+ from pptx.oxml.dml.color import (
7
+ CT_HslColor,
8
+ CT_PresetColor,
9
+ CT_SchemeColor,
10
+ CT_ScRgbColor,
11
+ CT_SRgbColor,
12
+ CT_SystemColor,
13
+ )
14
+
15
+
16
+ class ColorFormat(object):
17
+ """
18
+ Provides access to color settings such as RGB color, theme color, and
19
+ luminance adjustments.
20
+ """
21
+
22
+ def __init__(self, eg_colorChoice_parent, color):
23
+ super(ColorFormat, self).__init__()
24
+ self._xFill = eg_colorChoice_parent
25
+ self._color = color
26
+
27
+ @property
28
+ def brightness(self):
29
+ """
30
+ Read/write float value between -1.0 and 1.0 indicating the brightness
31
+ adjustment for this color, e.g. -0.25 is 25% darker and 0.4 is 40%
32
+ lighter. 0 means no brightness adjustment.
33
+ """
34
+ return self._color.brightness
35
+
36
+ @brightness.setter
37
+ def brightness(self, value):
38
+ self._validate_brightness_value(value)
39
+ self._color.brightness = value
40
+
41
+ @classmethod
42
+ def from_colorchoice_parent(cls, eg_colorChoice_parent):
43
+ xClr = eg_colorChoice_parent.eg_colorChoice
44
+ color = _Color(xClr)
45
+ color_format = cls(eg_colorChoice_parent, color)
46
+ return color_format
47
+
48
+ @property
49
+ def rgb(self):
50
+ """
51
+ |RGBColor| value of this color, or None if no RGB color is explicitly
52
+ defined for this font. Setting this value to an |RGBColor| instance
53
+ causes its type to change to MSO_COLOR_TYPE.RGB. If the color was a
54
+ theme color with a brightness adjustment, the brightness adjustment
55
+ is removed when changing it to an RGB color.
56
+ """
57
+ return self._color.rgb
58
+
59
+ @rgb.setter
60
+ def rgb(self, rgb):
61
+ if not isinstance(rgb, RGBColor):
62
+ raise ValueError("assigned value must be type RGBColor")
63
+ # change to rgb color format if not already
64
+ if not isinstance(self._color, _SRgbColor):
65
+ srgbClr = self._xFill.get_or_change_to_srgbClr()
66
+ self._color = _SRgbColor(srgbClr)
67
+ # call _SRgbColor instance to do the setting
68
+ self._color.rgb = rgb
69
+
70
+ @property
71
+ def theme_color(self):
72
+ """Theme color value of this color.
73
+
74
+ Value is a member of :ref:`MsoThemeColorIndex`, e.g.
75
+ ``MSO_THEME_COLOR.ACCENT_1``. Raises AttributeError on access if the
76
+ color is not type ``MSO_COLOR_TYPE.SCHEME``. Assigning a member of
77
+ :ref:`MsoThemeColorIndex` causes the color's type to change to
78
+ ``MSO_COLOR_TYPE.SCHEME``.
79
+ """
80
+ return self._color.theme_color
81
+
82
+ @theme_color.setter
83
+ def theme_color(self, mso_theme_color_idx):
84
+ # change to theme color format if not already
85
+ if not isinstance(self._color, _SchemeColor):
86
+ schemeClr = self._xFill.get_or_change_to_schemeClr()
87
+ self._color = _SchemeColor(schemeClr)
88
+ self._color.theme_color = mso_theme_color_idx
89
+
90
+ @property
91
+ def type(self):
92
+ """
93
+ Read-only. A value from :ref:`MsoColorType`, either RGB or SCHEME,
94
+ corresponding to the way this color is defined, or None if no color
95
+ is defined at the level of this font.
96
+ """
97
+ return self._color.color_type
98
+
99
+ def _validate_brightness_value(self, value):
100
+ if value < -1.0 or value > 1.0:
101
+ raise ValueError("brightness must be number in range -1.0 to 1.0")
102
+ if isinstance(self._color, _NoneColor):
103
+ msg = (
104
+ "can't set brightness when color.type is None. Set color.rgb"
105
+ " or .theme_color first."
106
+ )
107
+ raise ValueError(msg)
108
+
109
+
110
+ class _Color(object):
111
+ """
112
+ Object factory for color object of the appropriate type, also the base
113
+ class for all color type classes such as SRgbColor.
114
+ """
115
+
116
+ def __new__(cls, xClr):
117
+ color_cls = {
118
+ type(None): _NoneColor,
119
+ CT_HslColor: _HslColor,
120
+ CT_PresetColor: _PrstColor,
121
+ CT_SchemeColor: _SchemeColor,
122
+ CT_ScRgbColor: _ScRgbColor,
123
+ CT_SRgbColor: _SRgbColor,
124
+ CT_SystemColor: _SysColor,
125
+ }[type(xClr)]
126
+ return super(_Color, cls).__new__(color_cls)
127
+
128
+ def __init__(self, xClr):
129
+ super(_Color, self).__init__()
130
+ self._xClr = xClr
131
+
132
+ @property
133
+ def brightness(self):
134
+ lumMod, lumOff = self._xClr.lumMod, self._xClr.lumOff
135
+ # a tint is lighter, a shade is darker
136
+ # only tints have lumOff child
137
+ if lumOff is not None:
138
+ brightness = lumOff.val
139
+ return brightness
140
+ # which leaves shades, if lumMod is present
141
+ if lumMod is not None:
142
+ brightness = lumMod.val - 1.0
143
+ return brightness
144
+ # there's no brightness adjustment if no lum{Mod|Off} elements
145
+ return 0
146
+
147
+ @brightness.setter
148
+ def brightness(self, value):
149
+ if value > 0:
150
+ self._tint(value)
151
+ elif value < 0:
152
+ self._shade(value)
153
+ else:
154
+ self._xClr.clear_lum()
155
+
156
+ @property
157
+ def color_type(self): # pragma: no cover
158
+ tmpl = ".color_type property must be implemented on %s"
159
+ raise NotImplementedError(tmpl % self.__class__.__name__)
160
+
161
+ @property
162
+ def rgb(self):
163
+ """
164
+ Raises TypeError on access unless overridden by subclass.
165
+ """
166
+ tmpl = "no .rgb property on color type '%s'"
167
+ raise AttributeError(tmpl % self.__class__.__name__)
168
+
169
+ @property
170
+ def theme_color(self):
171
+ """
172
+ Raises TypeError on access unless overridden by subclass.
173
+ """
174
+ return MSO_THEME_COLOR.NOT_THEME_COLOR
175
+
176
+ def _shade(self, value):
177
+ lumMod_val = 1.0 - abs(value)
178
+ color_elm = self._xClr.clear_lum()
179
+ color_elm.add_lumMod(lumMod_val)
180
+
181
+ def _tint(self, value):
182
+ lumOff_val = value
183
+ lumMod_val = 1.0 - lumOff_val
184
+ color_elm = self._xClr.clear_lum()
185
+ color_elm.add_lumMod(lumMod_val)
186
+ color_elm.add_lumOff(lumOff_val)
187
+
188
+
189
+ class _HslColor(_Color):
190
+ @property
191
+ def color_type(self):
192
+ return MSO_COLOR_TYPE.HSL
193
+
194
+
195
+ class _NoneColor(_Color):
196
+ @property
197
+ def color_type(self):
198
+ return None
199
+
200
+ @property
201
+ def theme_color(self):
202
+ """
203
+ Raise TypeError on attempt to access .theme_color when no color
204
+ choice is present.
205
+ """
206
+ tmpl = "no .theme_color property on color type '%s'"
207
+ raise AttributeError(tmpl % self.__class__.__name__)
208
+
209
+
210
+ class _PrstColor(_Color):
211
+ @property
212
+ def color_type(self):
213
+ return MSO_COLOR_TYPE.PRESET
214
+
215
+
216
+ class _SchemeColor(_Color):
217
+ def __init__(self, schemeClr):
218
+ super(_SchemeColor, self).__init__(schemeClr)
219
+ self._schemeClr = schemeClr
220
+
221
+ @property
222
+ def color_type(self):
223
+ return MSO_COLOR_TYPE.SCHEME
224
+
225
+ @property
226
+ def theme_color(self):
227
+ """
228
+ Theme color value of this color, one of those defined in the
229
+ MSO_THEME_COLOR enumeration, e.g. MSO_THEME_COLOR.ACCENT_1. None if
230
+ no theme color is explicitly defined for this font. Setting this to a
231
+ value in MSO_THEME_COLOR causes the color's type to change to
232
+ ``MSO_COLOR_TYPE.SCHEME``.
233
+ """
234
+ return self._schemeClr.val
235
+
236
+ @theme_color.setter
237
+ def theme_color(self, mso_theme_color_idx):
238
+ self._schemeClr.val = mso_theme_color_idx
239
+
240
+
241
+ class _ScRgbColor(_Color):
242
+ @property
243
+ def color_type(self):
244
+ return MSO_COLOR_TYPE.SCRGB
245
+
246
+
247
+ class _SRgbColor(_Color):
248
+ def __init__(self, srgbClr):
249
+ super(_SRgbColor, self).__init__(srgbClr)
250
+ self._srgbClr = srgbClr
251
+
252
+ @property
253
+ def color_type(self):
254
+ return MSO_COLOR_TYPE.RGB
255
+
256
+ @property
257
+ def rgb(self):
258
+ """
259
+ |RGBColor| value of this color, corresponding to the value in the
260
+ required ``val`` attribute of the ``<a:srgbColr>`` element.
261
+ """
262
+ return RGBColor.from_string(self._srgbClr.val)
263
+
264
+ @rgb.setter
265
+ def rgb(self, rgb):
266
+ self._srgbClr.val = str(rgb)
267
+
268
+
269
+ class _SysColor(_Color):
270
+ @property
271
+ def color_type(self):
272
+ return MSO_COLOR_TYPE.SYSTEM
273
+
274
+
275
+ class RGBColor(tuple):
276
+ """
277
+ Immutable value object defining a particular RGB color.
278
+ """
279
+
280
+ def __new__(cls, r, g, b):
281
+ msg = "RGBColor() takes three integer values 0-255"
282
+ for val in (r, g, b):
283
+ if not isinstance(val, int) or val < 0 or val > 255:
284
+ raise ValueError(msg)
285
+ return super(RGBColor, cls).__new__(cls, (r, g, b))
286
+
287
+ def __str__(self):
288
+ """
289
+ Return a hex string rgb value, like '3C2F80'
290
+ """
291
+ return "%02X%02X%02X" % self
292
+
293
+ @classmethod
294
+ def from_string(cls, rgb_hex_str):
295
+ """
296
+ Return a new instance from an RGB color hex string like ``'3C2F80'``.
297
+ """
298
+ r = int(rgb_hex_str[:2], 16)
299
+ g = int(rgb_hex_str[2:4], 16)
300
+ b = int(rgb_hex_str[4:], 16)
301
+ return cls(r, g, b)
pptx/dml/effect.py ADDED
@@ -0,0 +1,41 @@
1
+ """Visual effects on a shape such as shadow, glow, and reflection."""
2
+
3
+ from __future__ import annotations
4
+
5
+
6
+ class ShadowFormat(object):
7
+ """Provides access to shadow effect on a shape."""
8
+
9
+ def __init__(self, spPr):
10
+ # ---spPr may also be a grpSpPr; both have a:effectLst child---
11
+ self._element = spPr
12
+
13
+ @property
14
+ def inherit(self):
15
+ """True if shape inherits shadow settings.
16
+
17
+ Read/write. An explicitly-defined shadow setting on a shape causes
18
+ this property to return |False|. A shape with no explicitly-defined
19
+ shadow setting inherits its shadow settings from the style hierarchy
20
+ (and so returns |True|).
21
+
22
+ Assigning |True| causes any explicitly-defined shadow setting to be
23
+ removed and inheritance is restored. Note this has the side-effect of
24
+ removing **all** explicitly-defined effects, such as glow and
25
+ reflection, and restoring inheritance for all effects on the shape.
26
+ Assigning |False| causes the inheritance link to be broken and **no**
27
+ effects to appear on the shape.
28
+ """
29
+ if self._element.effectLst is None:
30
+ return True
31
+ return False
32
+
33
+ @inherit.setter
34
+ def inherit(self, value):
35
+ inherit = bool(value)
36
+ if inherit:
37
+ # ---remove any explicitly-defined effects
38
+ self._element._remove_effectLst()
39
+ else:
40
+ # ---ensure at least the effectLst element is present
41
+ self._element.get_or_add_effectLst()