MCPcopy Create free account
hub / github.com/scanny/python-pptx / CT_SlideIdList

Class CT_SlideIdList

src/pptx/oxml/presentation.py:51–94  ·  view source on GitHub ↗

`p:sldIdLst` element. Direct child of that contains a list of the slide parts in the presentation.

Source from the content-addressed store, hash-verified

49
50
51class 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
97class CT_SlideMasterIdList(BaseOxmlElement):

Callers

nothing calls this directly

Calls 1

ZeroOrMoreClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…