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
@@ -0,0 +1,288 @@
1
+ """Data label-related objects."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pptx.text.text import Font, TextFrame
6
+ from pptx.util import lazyproperty
7
+
8
+
9
+ class DataLabels(object):
10
+ """Provides access to properties of data labels for a plot or a series.
11
+
12
+ This is not a collection and does not provide access to individual data
13
+ labels. Access to individual labels is via the |Point| object. The
14
+ properties this object provides control formatting of *all* the data
15
+ labels in its scope.
16
+ """
17
+
18
+ def __init__(self, dLbls):
19
+ super(DataLabels, self).__init__()
20
+ self._element = dLbls
21
+
22
+ @lazyproperty
23
+ def font(self):
24
+ """
25
+ The |Font| object that provides access to the text properties for
26
+ these data labels, such as bold, italic, etc.
27
+ """
28
+ defRPr = self._element.defRPr
29
+ font = Font(defRPr)
30
+ return font
31
+
32
+ @property
33
+ def number_format(self):
34
+ """
35
+ Read/write string specifying the format for the numbers on this set
36
+ of data labels. Returns 'General' if no number format has been set.
37
+ Note that this format string has no effect on rendered data labels
38
+ when :meth:`number_format_is_linked` is |True|. Assigning a format
39
+ string to this property automatically sets
40
+ :meth:`number_format_is_linked` to |False|.
41
+ """
42
+ numFmt = self._element.numFmt
43
+ if numFmt is None:
44
+ return "General"
45
+ return numFmt.formatCode
46
+
47
+ @number_format.setter
48
+ def number_format(self, value):
49
+ self._element.get_or_add_numFmt().formatCode = value
50
+ self.number_format_is_linked = False
51
+
52
+ @property
53
+ def number_format_is_linked(self):
54
+ """
55
+ Read/write boolean specifying whether number formatting should be
56
+ taken from the source spreadsheet rather than the value of
57
+ :meth:`number_format`.
58
+ """
59
+ numFmt = self._element.numFmt
60
+ if numFmt is None:
61
+ return True
62
+ souceLinked = numFmt.sourceLinked
63
+ if souceLinked is None:
64
+ return True
65
+ return numFmt.sourceLinked
66
+
67
+ @number_format_is_linked.setter
68
+ def number_format_is_linked(self, value):
69
+ numFmt = self._element.get_or_add_numFmt()
70
+ numFmt.sourceLinked = value
71
+
72
+ @property
73
+ def position(self):
74
+ """
75
+ Read/write :ref:`XlDataLabelPosition` enumeration value specifying
76
+ the position of the data labels with respect to their data point, or
77
+ |None| if no position is specified. Assigning |None| causes
78
+ PowerPoint to choose the default position, which varies by chart
79
+ type.
80
+ """
81
+ dLblPos = self._element.dLblPos
82
+ if dLblPos is None:
83
+ return None
84
+ return dLblPos.val
85
+
86
+ @position.setter
87
+ def position(self, value):
88
+ if value is None:
89
+ self._element._remove_dLblPos()
90
+ return
91
+ self._element.get_or_add_dLblPos().val = value
92
+
93
+ @property
94
+ def show_category_name(self):
95
+ """Read/write. True when name of category should appear in label."""
96
+ return self._element.get_or_add_showCatName().val
97
+
98
+ @show_category_name.setter
99
+ def show_category_name(self, value):
100
+ self._element.get_or_add_showCatName().val = bool(value)
101
+
102
+ @property
103
+ def show_legend_key(self):
104
+ """Read/write. True when data label displays legend-color swatch."""
105
+ return self._element.get_or_add_showLegendKey().val
106
+
107
+ @show_legend_key.setter
108
+ def show_legend_key(self, value):
109
+ self._element.get_or_add_showLegendKey().val = bool(value)
110
+
111
+ @property
112
+ def show_percentage(self):
113
+ """Read/write. True when data label displays percentage.
114
+
115
+ This option is not operative on all chart types. Percentage appears
116
+ on polar charts such as pie and donut.
117
+ """
118
+ return self._element.get_or_add_showPercent().val
119
+
120
+ @show_percentage.setter
121
+ def show_percentage(self, value):
122
+ self._element.get_or_add_showPercent().val = bool(value)
123
+
124
+ @property
125
+ def show_series_name(self):
126
+ """Read/write. True when data label displays series name."""
127
+ return self._element.get_or_add_showSerName().val
128
+
129
+ @show_series_name.setter
130
+ def show_series_name(self, value):
131
+ self._element.get_or_add_showSerName().val = bool(value)
132
+
133
+ @property
134
+ def show_value(self):
135
+ """Read/write. True when label displays numeric value of datapoint."""
136
+ return self._element.get_or_add_showVal().val
137
+
138
+ @show_value.setter
139
+ def show_value(self, value):
140
+ self._element.get_or_add_showVal().val = bool(value)
141
+
142
+
143
+ class DataLabel(object):
144
+ """
145
+ The data label associated with an individual data point.
146
+ """
147
+
148
+ def __init__(self, ser, idx):
149
+ super(DataLabel, self).__init__()
150
+ self._ser = self._element = ser
151
+ self._idx = idx
152
+
153
+ @lazyproperty
154
+ def font(self):
155
+ """The |Font| object providing text formatting for this data label.
156
+
157
+ This font object is used to customize the appearance of automatically
158
+ inserted text, such as the data point value. The font applies to the
159
+ entire data label. More granular control of the appearance of custom
160
+ data label text is controlled by a font object on runs in the text
161
+ frame.
162
+ """
163
+ txPr = self._get_or_add_txPr()
164
+ text_frame = TextFrame(txPr, self)
165
+ paragraph = text_frame.paragraphs[0]
166
+ return paragraph.font
167
+
168
+ @property
169
+ def has_text_frame(self):
170
+ """
171
+ Return |True| if this data label has a text frame (implying it has
172
+ custom data label text), and |False| otherwise. Assigning |True|
173
+ causes a text frame to be added if not already present. Assigning
174
+ |False| causes any existing text frame to be removed along with any
175
+ text contained in the text frame.
176
+ """
177
+ dLbl = self._dLbl
178
+ if dLbl is None:
179
+ return False
180
+ if dLbl.xpath("c:tx/c:rich"):
181
+ return True
182
+ return False
183
+
184
+ @has_text_frame.setter
185
+ def has_text_frame(self, value):
186
+ if bool(value) is True:
187
+ self._get_or_add_tx_rich()
188
+ else:
189
+ self._remove_tx_rich()
190
+
191
+ @property
192
+ def position(self):
193
+ """
194
+ Read/write :ref:`XlDataLabelPosition` member specifying the position
195
+ of this data label with respect to its data point, or |None| if no
196
+ position is specified. Assigning |None| causes PowerPoint to choose
197
+ the default position, which varies by chart type.
198
+ """
199
+ dLbl = self._dLbl
200
+ if dLbl is None:
201
+ return None
202
+ dLblPos = dLbl.dLblPos
203
+ if dLblPos is None:
204
+ return None
205
+ return dLblPos.val
206
+
207
+ @position.setter
208
+ def position(self, value):
209
+ if value is None:
210
+ dLbl = self._dLbl
211
+ if dLbl is None:
212
+ return
213
+ dLbl._remove_dLblPos()
214
+ return
215
+ dLbl = self._get_or_add_dLbl()
216
+ dLbl.get_or_add_dLblPos().val = value
217
+
218
+ @property
219
+ def text_frame(self):
220
+ """
221
+ |TextFrame| instance for this data label, containing the text of the
222
+ data label and providing access to its text formatting properties.
223
+ """
224
+ rich = self._get_or_add_rich()
225
+ return TextFrame(rich, self)
226
+
227
+ @property
228
+ def _dLbl(self):
229
+ """
230
+ Return the |CT_DLbl| instance referring specifically to this
231
+ individual data label (having the same index value), or |None| if not
232
+ present.
233
+ """
234
+ return self._ser.get_dLbl(self._idx)
235
+
236
+ def _get_or_add_dLbl(self):
237
+ """
238
+ The ``CT_DLbl`` instance referring specifically to this individual
239
+ data label, newly created if not yet present in the XML.
240
+ """
241
+ return self._ser.get_or_add_dLbl(self._idx)
242
+
243
+ def _get_or_add_rich(self):
244
+ """
245
+ Return the `c:rich` element representing the text frame for this data
246
+ label, newly created with its ancestors if not present.
247
+ """
248
+ dLbl = self._get_or_add_dLbl()
249
+
250
+ # having a c:spPr or c:txPr when a c:tx is present causes the "can't
251
+ # save" bug on bubble charts. Remove c:spPr and c:txPr when present.
252
+ dLbl._remove_spPr()
253
+ dLbl._remove_txPr()
254
+
255
+ return dLbl.get_or_add_rich()
256
+
257
+ def _get_or_add_tx_rich(self):
258
+ """
259
+ Return the `c:tx` element for this data label, with its `c:rich`
260
+ child and descendants, newly created if not yet present.
261
+ """
262
+ dLbl = self._get_or_add_dLbl()
263
+
264
+ # having a c:spPr or c:txPr when a c:tx is present causes the "can't
265
+ # save" bug on bubble charts. Remove c:spPr and c:txPr when present.
266
+ dLbl._remove_spPr()
267
+ dLbl._remove_txPr()
268
+
269
+ return dLbl.get_or_add_tx_rich()
270
+
271
+ def _get_or_add_txPr(self):
272
+ """Return the `c:txPr` element for this data label.
273
+
274
+ The `c:txPr` element and its parent `c:dLbl` element are created if
275
+ not yet present.
276
+ """
277
+ dLbl = self._get_or_add_dLbl()
278
+ return dLbl.get_or_add_txPr()
279
+
280
+ def _remove_tx_rich(self):
281
+ """
282
+ Remove any `c:tx/c:rich` child of the `c:dLbl` element for this data
283
+ label. Do nothing if that element is not present.
284
+ """
285
+ dLbl = self._dLbl
286
+ if dLbl is None:
287
+ return
288
+ dLbl.remove_tx_rich()
pptx/chart/legend.py ADDED
@@ -0,0 +1,79 @@
1
+ """Legend of a chart."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pptx.enum.chart import XL_LEGEND_POSITION
6
+ from pptx.text.text import Font
7
+ from pptx.util import lazyproperty
8
+
9
+
10
+ class Legend(object):
11
+ """
12
+ Represents the legend in a chart. A chart can have at most one legend.
13
+ """
14
+
15
+ def __init__(self, legend_elm):
16
+ super(Legend, self).__init__()
17
+ self._element = legend_elm
18
+
19
+ @lazyproperty
20
+ def font(self):
21
+ """
22
+ The |Font| object that provides access to the text properties for
23
+ this legend, such as bold, italic, etc.
24
+ """
25
+ defRPr = self._element.defRPr
26
+ font = Font(defRPr)
27
+ return font
28
+
29
+ @property
30
+ def horz_offset(self):
31
+ """
32
+ Adjustment of the x position of the legend from its default.
33
+ Expressed as a float between -1.0 and 1.0 representing a fraction of
34
+ the chart width. Negative values move the legend left, positive
35
+ values move it to the right. |None| if no setting is specified.
36
+ """
37
+ return self._element.horz_offset
38
+
39
+ @horz_offset.setter
40
+ def horz_offset(self, value):
41
+ self._element.horz_offset = value
42
+
43
+ @property
44
+ def include_in_layout(self):
45
+ """|True| if legend should be located inside plot area.
46
+
47
+ Read/write boolean specifying whether legend should be placed inside
48
+ the plot area. In many cases this will cause it to be superimposed on
49
+ the chart itself. Assigning |None| to this property causes any
50
+ `c:overlay` element to be removed, which is interpreted the same as
51
+ |True|. This use case should rarely be required and assigning
52
+ a boolean value is recommended.
53
+ """
54
+ overlay = self._element.overlay
55
+ if overlay is None:
56
+ return True
57
+ return overlay.val
58
+
59
+ @include_in_layout.setter
60
+ def include_in_layout(self, value):
61
+ if value is None:
62
+ self._element._remove_overlay()
63
+ return
64
+ self._element.get_or_add_overlay().val = bool(value)
65
+
66
+ @property
67
+ def position(self):
68
+ """
69
+ Read/write :ref:`XlLegendPosition` enumeration value specifying the
70
+ general region of the chart in which to place the legend.
71
+ """
72
+ legendPos = self._element.legendPos
73
+ if legendPos is None:
74
+ return XL_LEGEND_POSITION.RIGHT
75
+ return legendPos.val
76
+
77
+ @position.setter
78
+ def position(self, position):
79
+ self._element.get_or_add_legendPos().val = position
pptx/chart/marker.py ADDED
@@ -0,0 +1,70 @@
1
+ """Marker-related objects.
2
+
3
+ Only the line-type charts Line, XY, and Radar have markers.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ from pptx.dml.chtfmt import ChartFormat
9
+ from pptx.shared import ElementProxy
10
+ from pptx.util import lazyproperty
11
+
12
+
13
+ class Marker(ElementProxy):
14
+ """
15
+ Represents a data point marker, such as a diamond or circle, on
16
+ a line-type chart.
17
+ """
18
+
19
+ @lazyproperty
20
+ def format(self):
21
+ """
22
+ The |ChartFormat| instance for this marker, providing access to shape
23
+ properties such as fill and line.
24
+ """
25
+ marker = self._element.get_or_add_marker()
26
+ return ChartFormat(marker)
27
+
28
+ @property
29
+ def size(self):
30
+ """
31
+ An integer between 2 and 72 inclusive indicating the size of this
32
+ marker in points. A value of |None| indicates no explicit value is
33
+ set and the size is inherited from a higher-level setting or the
34
+ PowerPoint default (which may be 9). Assigning |None| removes any
35
+ explicitly assigned size, causing this value to be inherited.
36
+ """
37
+ marker = self._element.marker
38
+ if marker is None:
39
+ return None
40
+ return marker.size_val
41
+
42
+ @size.setter
43
+ def size(self, value):
44
+ marker = self._element.get_or_add_marker()
45
+ marker._remove_size()
46
+ if value is None:
47
+ return
48
+ size = marker._add_size()
49
+ size.val = value
50
+
51
+ @property
52
+ def style(self):
53
+ """
54
+ A member of the :ref:`XlMarkerStyle` enumeration indicating the shape
55
+ of this marker. Returns |None| if no explicit style has been set,
56
+ which corresponds to the "Automatic" option in the PowerPoint UI.
57
+ """
58
+ marker = self._element.marker
59
+ if marker is None:
60
+ return None
61
+ return marker.symbol_val
62
+
63
+ @style.setter
64
+ def style(self, value):
65
+ marker = self._element.get_or_add_marker()
66
+ marker._remove_symbol()
67
+ if value is None:
68
+ return
69
+ symbol = marker._add_symbol()
70
+ symbol.val = value