An overall .pptx package.
| 14 | |
| 15 | |
| 16 | class Package(OpcPackage): |
| 17 | """An overall .pptx package.""" |
| 18 | |
| 19 | @lazyproperty |
| 20 | def core_properties(self) -> CorePropertiesPart: |
| 21 | """Instance of |CoreProperties| holding read/write Dublin Core doc properties. |
| 22 | |
| 23 | Creates a default core properties part if one is not present (not common). |
| 24 | """ |
| 25 | try: |
| 26 | return self.part_related_by(RT.CORE_PROPERTIES) |
| 27 | except KeyError: |
| 28 | core_props = CorePropertiesPart.default(self) |
| 29 | self.relate_to(core_props, RT.CORE_PROPERTIES) |
| 30 | return core_props |
| 31 | |
| 32 | def get_or_add_image_part(self, image_file: str | IO[bytes]): |
| 33 | """ |
| 34 | Return an |ImagePart| object containing the image in *image_file*. If |
| 35 | the image part already exists in this package, it is reused, |
| 36 | otherwise a new one is created. |
| 37 | """ |
| 38 | return self._image_parts.get_or_add_image_part(image_file) |
| 39 | |
| 40 | def get_or_add_media_part(self, media): |
| 41 | """Return a |MediaPart| object containing the media in *media*. |
| 42 | |
| 43 | If a media part for this media bytestream ("file") is already present |
| 44 | in this package, it is reused, otherwise a new one is created. |
| 45 | """ |
| 46 | return self._media_parts.get_or_add_media_part(media) |
| 47 | |
| 48 | def next_image_partname(self, ext: str) -> PackURI: |
| 49 | """Return a |PackURI| instance representing the next available image partname. |
| 50 | |
| 51 | Partname uses the next available sequence number. *ext* is used as the extention on the |
| 52 | returned partname. |
| 53 | """ |
| 54 | |
| 55 | def first_available_image_idx(): |
| 56 | image_idxs = sorted( |
| 57 | [ |
| 58 | part.partname.idx |
| 59 | for part in self.iter_parts() |
| 60 | if ( |
| 61 | part.partname.startswith("/ppt/media/image") |
| 62 | and part.partname.idx is not None |
| 63 | ) |
| 64 | ] |
| 65 | ) |
| 66 | for i, image_idx in enumerate(image_idxs): |
| 67 | idx = i + 1 |
| 68 | if idx < image_idx: |
| 69 | return idx |
| 70 | return len(image_idxs) + 1 |
| 71 | |
| 72 | idx = first_available_image_idx() |
| 73 | return PackURI("/ppt/media/image%d.%s" % (idx, ext)) |
no outgoing calls
searching dependent graphs…