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,407 @@
1
+ """Placeholder-related objects.
2
+
3
+ Specific to shapes having a `p:ph` element. A placeholder has distinct behaviors
4
+ depending on whether it appears on a slide, layout, or master. Hence there is a
5
+ non-trivial class inheritance structure.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import TYPE_CHECKING
11
+
12
+ from pptx.enum.shapes import MSO_SHAPE_TYPE, PP_PLACEHOLDER
13
+ from pptx.oxml.shapes.graphfrm import CT_GraphicalObjectFrame
14
+ from pptx.oxml.shapes.picture import CT_Picture
15
+ from pptx.shapes.autoshape import Shape
16
+ from pptx.shapes.graphfrm import GraphicFrame
17
+ from pptx.shapes.picture import Picture
18
+ from pptx.util import Emu
19
+
20
+ if TYPE_CHECKING:
21
+ from pptx.oxml.shapes.autoshape import CT_Shape
22
+
23
+
24
+ class _InheritsDimensions(object):
25
+ """
26
+ Mixin class that provides inherited dimension behavior. Specifically,
27
+ left, top, width, and height report the value from the layout placeholder
28
+ where they would have otherwise reported |None|. This behavior is
29
+ distinctive to placeholders. :meth:`_base_placeholder` must be overridden
30
+ by all subclasses to provide lookup of the appropriate base placeholder
31
+ to inherit from.
32
+ """
33
+
34
+ @property
35
+ def height(self):
36
+ """
37
+ The effective height of this placeholder shape; its directly-applied
38
+ height if it has one, otherwise the height of its parent layout
39
+ placeholder.
40
+ """
41
+ return self._effective_value("height")
42
+
43
+ @height.setter
44
+ def height(self, value):
45
+ self._element.cy = value
46
+
47
+ @property
48
+ def left(self):
49
+ """
50
+ The effective left of this placeholder shape; its directly-applied
51
+ left if it has one, otherwise the left of its parent layout
52
+ placeholder.
53
+ """
54
+ return self._effective_value("left")
55
+
56
+ @left.setter
57
+ def left(self, value):
58
+ self._element.x = value
59
+
60
+ @property
61
+ def shape_type(self):
62
+ """
63
+ Member of :ref:`MsoShapeType` specifying the type of this shape.
64
+ Unconditionally ``MSO_SHAPE_TYPE.PLACEHOLDER`` in this case.
65
+ Read-only.
66
+ """
67
+ return MSO_SHAPE_TYPE.PLACEHOLDER
68
+
69
+ @property
70
+ def top(self):
71
+ """
72
+ The effective top of this placeholder shape; its directly-applied
73
+ top if it has one, otherwise the top of its parent layout
74
+ placeholder.
75
+ """
76
+ return self._effective_value("top")
77
+
78
+ @top.setter
79
+ def top(self, value):
80
+ self._element.y = value
81
+
82
+ @property
83
+ def width(self):
84
+ """
85
+ The effective width of this placeholder shape; its directly-applied
86
+ width if it has one, otherwise the width of its parent layout
87
+ placeholder.
88
+ """
89
+ return self._effective_value("width")
90
+
91
+ @width.setter
92
+ def width(self, value):
93
+ self._element.cx = value
94
+
95
+ @property
96
+ def _base_placeholder(self):
97
+ """
98
+ Return the layout or master placeholder shape this placeholder
99
+ inherits from. Not to be confused with an instance of
100
+ |BasePlaceholder| (necessarily).
101
+ """
102
+ raise NotImplementedError("Must be implemented by all subclasses.")
103
+
104
+ def _effective_value(self, attr_name):
105
+ """
106
+ The effective value of *attr_name* on this placeholder shape; its
107
+ directly-applied value if it has one, otherwise the value on the
108
+ layout placeholder it inherits from.
109
+ """
110
+ directly_applied_value = getattr(super(_InheritsDimensions, self), attr_name)
111
+ if directly_applied_value is not None:
112
+ return directly_applied_value
113
+ return self._inherited_value(attr_name)
114
+
115
+ def _inherited_value(self, attr_name):
116
+ """
117
+ Return the attribute value, e.g. 'width' of the base placeholder this
118
+ placeholder inherits from.
119
+ """
120
+ base_placeholder = self._base_placeholder
121
+ if base_placeholder is None:
122
+ return None
123
+ inherited_value = getattr(base_placeholder, attr_name)
124
+ return inherited_value
125
+
126
+
127
+ class _BaseSlidePlaceholder(_InheritsDimensions, Shape):
128
+ """Base class for placeholders on slides.
129
+
130
+ Provides common behaviors such as inherited dimensions.
131
+ """
132
+
133
+ @property
134
+ def is_placeholder(self):
135
+ """
136
+ Boolean indicating whether this shape is a placeholder.
137
+ Unconditionally |True| in this case.
138
+ """
139
+ return True
140
+
141
+ @property
142
+ def shape_type(self):
143
+ """
144
+ Member of :ref:`MsoShapeType` specifying the type of this shape.
145
+ Unconditionally ``MSO_SHAPE_TYPE.PLACEHOLDER`` in this case.
146
+ Read-only.
147
+ """
148
+ return MSO_SHAPE_TYPE.PLACEHOLDER
149
+
150
+ @property
151
+ def _base_placeholder(self):
152
+ """
153
+ Return the layout placeholder this slide placeholder inherits from.
154
+ Not to be confused with an instance of |BasePlaceholder|
155
+ (necessarily).
156
+ """
157
+ layout, idx = self.part.slide_layout, self._element.ph_idx
158
+ return layout.placeholders.get(idx=idx)
159
+
160
+ def _replace_placeholder_with(self, element):
161
+ """
162
+ Substitute *element* for this placeholder element in the shapetree.
163
+ This placeholder's `._element` attribute is set to |None| and its
164
+ original element is free for garbage collection. Any attribute access
165
+ (including a method call) on this placeholder after this call raises
166
+ |AttributeError|.
167
+ """
168
+ element._nvXxPr.nvPr._insert_ph(self._element.ph)
169
+ self._element.addprevious(element)
170
+ self._element.getparent().remove(self._element)
171
+ self._element = None
172
+
173
+
174
+ class BasePlaceholder(Shape):
175
+ """
176
+ NOTE: This class is deprecated and will be removed from a future release
177
+ along with the properties *idx*, *orient*, *ph_type*, and *sz*. The *idx*
178
+ property will be available via the .placeholder_format property. The
179
+ others will be accessed directly from the oxml layer as they are only
180
+ used for internal purposes.
181
+
182
+ Base class for placeholder subclasses that differentiate the varying
183
+ behaviors of placeholders on a master, layout, and slide.
184
+ """
185
+
186
+ @property
187
+ def idx(self):
188
+ """
189
+ Integer placeholder 'idx' attribute, e.g. 0
190
+ """
191
+ return self._sp.ph_idx
192
+
193
+ @property
194
+ def orient(self):
195
+ """
196
+ Placeholder orientation, e.g. ST_Direction.HORZ
197
+ """
198
+ return self._sp.ph_orient
199
+
200
+ @property
201
+ def ph_type(self):
202
+ """
203
+ Placeholder type, e.g. PP_PLACEHOLDER.CENTER_TITLE
204
+ """
205
+ return self._sp.ph_type
206
+
207
+ @property
208
+ def sz(self):
209
+ """
210
+ Placeholder 'sz' attribute, e.g. ST_PlaceholderSize.FULL
211
+ """
212
+ return self._sp.ph_sz
213
+
214
+
215
+ class LayoutPlaceholder(_InheritsDimensions, Shape):
216
+ """Placeholder shape on a slide layout.
217
+
218
+ Provides differentiated behavior for slide layout placeholders, in particular, inheriting
219
+ shape properties from the master placeholder having the same type, when a matching one exists.
220
+ """
221
+
222
+ element: CT_Shape # pyright: ignore[reportIncompatibleMethodOverride]
223
+
224
+ @property
225
+ def _base_placeholder(self):
226
+ """
227
+ Return the master placeholder this layout placeholder inherits from.
228
+ """
229
+ base_ph_type = {
230
+ PP_PLACEHOLDER.BODY: PP_PLACEHOLDER.BODY,
231
+ PP_PLACEHOLDER.CHART: PP_PLACEHOLDER.BODY,
232
+ PP_PLACEHOLDER.BITMAP: PP_PLACEHOLDER.BODY,
233
+ PP_PLACEHOLDER.CENTER_TITLE: PP_PLACEHOLDER.TITLE,
234
+ PP_PLACEHOLDER.ORG_CHART: PP_PLACEHOLDER.BODY,
235
+ PP_PLACEHOLDER.DATE: PP_PLACEHOLDER.DATE,
236
+ PP_PLACEHOLDER.FOOTER: PP_PLACEHOLDER.FOOTER,
237
+ PP_PLACEHOLDER.MEDIA_CLIP: PP_PLACEHOLDER.BODY,
238
+ PP_PLACEHOLDER.OBJECT: PP_PLACEHOLDER.BODY,
239
+ PP_PLACEHOLDER.PICTURE: PP_PLACEHOLDER.BODY,
240
+ PP_PLACEHOLDER.SLIDE_NUMBER: PP_PLACEHOLDER.SLIDE_NUMBER,
241
+ PP_PLACEHOLDER.SUBTITLE: PP_PLACEHOLDER.BODY,
242
+ PP_PLACEHOLDER.TABLE: PP_PLACEHOLDER.BODY,
243
+ PP_PLACEHOLDER.TITLE: PP_PLACEHOLDER.TITLE,
244
+ }[self._element.ph_type]
245
+ slide_master = self.part.slide_master
246
+ return slide_master.placeholders.get(base_ph_type, None)
247
+
248
+
249
+ class MasterPlaceholder(BasePlaceholder):
250
+ """Placeholder shape on a slide master."""
251
+
252
+ element: CT_Shape # pyright: ignore[reportIncompatibleMethodOverride]
253
+
254
+
255
+ class NotesSlidePlaceholder(_InheritsDimensions, Shape):
256
+ """
257
+ Placeholder shape on a notes slide. Inherits shape properties from the
258
+ placeholder on the notes master that has the same type (e.g. 'body').
259
+ """
260
+
261
+ @property
262
+ def _base_placeholder(self):
263
+ """
264
+ Return the notes master placeholder this notes slide placeholder
265
+ inherits from, or |None| if no placeholder of the matching type is
266
+ present.
267
+ """
268
+ notes_master = self.part.notes_master
269
+ ph_type = self.element.ph_type
270
+ return notes_master.placeholders.get(ph_type=ph_type)
271
+
272
+
273
+ class SlidePlaceholder(_BaseSlidePlaceholder):
274
+ """
275
+ Placeholder shape on a slide. Inherits shape properties from its
276
+ corresponding slide layout placeholder.
277
+ """
278
+
279
+
280
+ class ChartPlaceholder(_BaseSlidePlaceholder):
281
+ """Placeholder shape that can only accept a chart."""
282
+
283
+ def insert_chart(self, chart_type, chart_data):
284
+ """
285
+ Return a |PlaceholderGraphicFrame| object containing a new chart of
286
+ *chart_type* depicting *chart_data* and having the same position and
287
+ size as this placeholder. *chart_type* is one of the
288
+ :ref:`XlChartType` enumeration values. *chart_data* is a |ChartData|
289
+ object populated with the categories and series values for the chart.
290
+ Note that the new |Chart| object is not returned directly. The chart
291
+ object may be accessed using the
292
+ :attr:`~.PlaceholderGraphicFrame.chart` property of the returned
293
+ |PlaceholderGraphicFrame| object.
294
+ """
295
+ rId = self.part.add_chart_part(chart_type, chart_data)
296
+ graphicFrame = self._new_chart_graphicFrame(
297
+ rId, self.left, self.top, self.width, self.height
298
+ )
299
+ self._replace_placeholder_with(graphicFrame)
300
+ return PlaceholderGraphicFrame(graphicFrame, self._parent)
301
+
302
+ def _new_chart_graphicFrame(self, rId, x, y, cx, cy):
303
+ """
304
+ Return a newly created `p:graphicFrame` element having the specified
305
+ position and size and containing the chart identified by *rId*.
306
+ """
307
+ id_, name = self.shape_id, self.name
308
+ return CT_GraphicalObjectFrame.new_chart_graphicFrame(id_, name, rId, x, y, cx, cy)
309
+
310
+
311
+ class PicturePlaceholder(_BaseSlidePlaceholder):
312
+ """Placeholder shape that can only accept a picture."""
313
+
314
+ def insert_picture(self, image_file):
315
+ """Return a |PlaceholderPicture| object depicting the image in `image_file`.
316
+
317
+ `image_file` may be either a path (string) or a file-like object. The image is
318
+ cropped to fill the entire space of the placeholder. A |PlaceholderPicture|
319
+ object has all the properties and methods of a |Picture| shape except that the
320
+ value of its :attr:`~._BaseSlidePlaceholder.shape_type` property is
321
+ `MSO_SHAPE_TYPE.PLACEHOLDER` instead of `MSO_SHAPE_TYPE.PICTURE`.
322
+ """
323
+ pic = self._new_placeholder_pic(image_file)
324
+ self._replace_placeholder_with(pic)
325
+ return PlaceholderPicture(pic, self._parent)
326
+
327
+ def _new_placeholder_pic(self, image_file):
328
+ """
329
+ Return a new `p:pic` element depicting the image in *image_file*,
330
+ suitable for use as a placeholder. In particular this means not
331
+ having an `a:xfrm` element, allowing its extents to be inherited from
332
+ its layout placeholder.
333
+ """
334
+ rId, desc, image_size = self._get_or_add_image(image_file)
335
+ shape_id, name = self.shape_id, self.name
336
+ pic = CT_Picture.new_ph_pic(shape_id, name, desc, rId)
337
+ pic.crop_to_fit(image_size, (self.width, self.height))
338
+ return pic
339
+
340
+ def _get_or_add_image(self, image_file):
341
+ """
342
+ Return an (rId, description, image_size) 3-tuple identifying the
343
+ related image part containing *image_file* and describing the image.
344
+ """
345
+ image_part, rId = self.part.get_or_add_image_part(image_file)
346
+ desc, image_size = image_part.desc, image_part._px_size
347
+ return rId, desc, image_size
348
+
349
+
350
+ class PlaceholderGraphicFrame(GraphicFrame):
351
+ """
352
+ Placeholder shape populated with a table, chart, or smart art.
353
+ """
354
+
355
+ @property
356
+ def is_placeholder(self):
357
+ """
358
+ Boolean indicating whether this shape is a placeholder.
359
+ Unconditionally |True| in this case.
360
+ """
361
+ return True
362
+
363
+
364
+ class PlaceholderPicture(_InheritsDimensions, Picture):
365
+ """
366
+ Placeholder shape populated with a picture.
367
+ """
368
+
369
+ @property
370
+ def _base_placeholder(self):
371
+ """
372
+ Return the layout placeholder this picture placeholder inherits from.
373
+ """
374
+ layout, idx = self.part.slide_layout, self._element.ph_idx
375
+ return layout.placeholders.get(idx=idx)
376
+
377
+
378
+ class TablePlaceholder(_BaseSlidePlaceholder):
379
+ """Placeholder shape that can only accept a table."""
380
+
381
+ def insert_table(self, rows, cols):
382
+ """Return |PlaceholderGraphicFrame| object containing a `rows` by `cols` table.
383
+
384
+ The position and width of the table are those of the placeholder and its height
385
+ is proportional to the number of rows. A |PlaceholderGraphicFrame| object has
386
+ all the properties and methods of a |GraphicFrame| shape except that the value
387
+ of its :attr:`~._BaseSlidePlaceholder.shape_type` property is unconditionally
388
+ `MSO_SHAPE_TYPE.PLACEHOLDER`. Note that the return value is not the new table
389
+ but rather *contains* the new table. The table can be accessed using the
390
+ :attr:`~.PlaceholderGraphicFrame.table` property of the returned
391
+ |PlaceholderGraphicFrame| object.
392
+ """
393
+ graphicFrame = self._new_placeholder_table(rows, cols)
394
+ self._replace_placeholder_with(graphicFrame)
395
+ return PlaceholderGraphicFrame(graphicFrame, self._parent)
396
+
397
+ def _new_placeholder_table(self, rows, cols):
398
+ """
399
+ Return a newly added `p:graphicFrame` element containing an empty
400
+ table with *rows* rows and *cols* columns, positioned at the location
401
+ of this placeholder and having its same width. The table's height is
402
+ determined by the number of rows.
403
+ """
404
+ shape_id, name, height = self.shape_id, self.name, Emu(rows * 370840)
405
+ return CT_GraphicalObjectFrame.new_table_graphicFrame(
406
+ shape_id, name, rows, cols, self.left, self.top, self.width, height
407
+ )