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

Method target_slide

src/pptx/action.py:89–138  ·  view source on GitHub ↗

A reference to the slide in this presentation that is the target of the slide jump action in this shape. Slide jump actions include `PP_ACTION.FIRST_SLIDE`, `LAST_SLIDE`, `NEXT_SLIDE`, `PREVIOUS_SLIDE`, and `NAMED_SLIDE`. Returns |None| for all other actions.

(self)

Source from the content-addressed store, hash-verified

87
88 @property
89 def target_slide(self) -> Slide | None:
90 """
91 A reference to the slide in this presentation that is the target of
92 the slide jump action in this shape. Slide jump actions include
93 `PP_ACTION.FIRST_SLIDE`, `LAST_SLIDE`, `NEXT_SLIDE`,
94 `PREVIOUS_SLIDE`, and `NAMED_SLIDE`. Returns |None| for all other
95 actions. In particular, the `LAST_SLIDE_VIEWED` action and the `PLAY`
96 (start other presentation) actions are not supported.
97
98 A slide object may be assigned to this property, which makes the
99 shape an "internal hyperlink" to the assigened slide::
100
101 slide, target_slide = prs.slides[0], prs.slides[1]
102 shape = slide.shapes[0]
103 shape.target_slide = target_slide
104
105 Assigning |None| removes any slide jump action. Note that this is
106 accomplished by removing any action present (such as a hyperlink),
107 without first checking that it is a slide jump action.
108 """
109 slide_jump_actions = (
110 PP_ACTION.FIRST_SLIDE,
111 PP_ACTION.LAST_SLIDE,
112 PP_ACTION.NEXT_SLIDE,
113 PP_ACTION.PREVIOUS_SLIDE,
114 PP_ACTION.NAMED_SLIDE,
115 )
116
117 if self.action not in slide_jump_actions:
118 return None
119
120 if self.action == PP_ACTION.FIRST_SLIDE:
121 return self._slides[0]
122 elif self.action == PP_ACTION.LAST_SLIDE:
123 return self._slides[-1]
124 elif self.action == PP_ACTION.NEXT_SLIDE:
125 next_slide_idx = self._slide_index + 1
126 if next_slide_idx >= len(self._slides):
127 raise ValueError("no next slide")
128 return self._slides[next_slide_idx]
129 elif self.action == PP_ACTION.PREVIOUS_SLIDE:
130 prev_slide_idx = self._slide_index - 1
131 if prev_slide_idx < 0:
132 raise ValueError("no previous slide")
133 return self._slides[prev_slide_idx]
134 elif self.action == PP_ACTION.NAMED_SLIDE:
135 assert self._hlink is not None
136 rId = self._hlink.rId
137 slide_part = cast("SlidePart", self.part.related_part(rId))
138 return slide_part.slide
139
140 @target_slide.setter
141 def target_slide(self, slide: Slide | None):

Callers

nothing calls this directly

Calls 3

_clear_click_actionMethod · 0.95
related_partMethod · 0.80
relate_toMethod · 0.80

Tested by

no test coverage detected