Commit 4a53782
committed
feat(action): Hyperlinks 2.0 & Click Actions — issue #21 epic
Closes #21. Authors a unified, accessible API for hyperlinks, ScreenTips,
click/hover actions, and accessibility surfaces on shapes, runs, and
pictures. Lands eight sub-features as a single coherent surface so the
"hyperlink on a run" and "click action on a shape" stories share one
Hyperlink/ActionSetting/CT_Hyperlink core.
Sub-features:
1. ScreenTip on a run hyperlink — Run.hyperlink.tooltip getter/setter,
read/write the `tooltip` attribute on the run's a:hlinkClick.
2. Color override on a hyperlink run — Run.hyperlink.color delegates to
the same lazy Font.color machinery; closes scanny/python-pptx scanny#940
and scanny#821 (theme-hyperlink-color override without materialising
a:solidFill on read).
3. Click actions for shapes —
- ActionSetting.run_macro(macro_name) — emits
ppaction://macro?name=<urlquoted>
- ActionSetting.target_program(file_path) — emits
ppaction://program with an external HYPERLINK relationship
- ActionSetting.play_sound(audio_file) — embeds a WAV via the
AUDIO relationship under a:snd, with endSnd=True; uses
RT.AUDIO (relationships/audio), NOT relationships/media — the
latter triggers PowerPoint's Repair dialog on load.
4. Independent hover action — Shape.hover_action exposes an
ActionSetting bound to a:hlinkHover so click and hover behaviors
can co-exist without overwriting each other.
5. Jump to slide from a text run — Run.click_action gives runs the
same ActionSetting surface shapes have; target_slide=other_slide
emits ppaction://hlinksldjump with a SLIDE relationship.
6. Picture hyperlinks — Picture.hyperlink exposes the same Hyperlink
surface (address, tooltip, color), backed by the picture's cNvPr.
7. Accessibility surface on every shape —
- BaseShape.alt_text (cNvPr/@Descr)
- BaseShape.alt_title (cNvPr/@title)
- BaseShape.is_decorative (adec:decorative ext, Office 2019+)
- BaseShape.is_hidden_from_accessibility (alias of is_decorative)
8. Unified click/hover API — runs and shapes share the same
ActionSetting/Hyperlink objects so target_slide/run_macro/
target_program/play_sound/tooltip/address work the same on
either surface.
PowerPoint compatibility notes (load-bearing — verified by Repair-dialog
testing):
- Every a:hlinkClick / a:hlinkHover we create gets r:id="" as a default
even when no relationship is needed. PowerPoint's load-time validator
strips a:hlinkClick elements that omit @r:id, even though ECMA-376
marks it optional. Real PowerPoint output always carries r:id, empty
when there is no relationship — mirroring the precedent in
oxml/shapes/picture.py for ppaction://media.
- For an otherwise-empty (tooltip-only or inert) a:hlinkClick, we add
action="ppaction://noaction". This matches real PowerPoint's own
emission for inert hlinks. The marker is added by
_ensure_noaction_if_inert and pruned in lockstep with the rest of
the hlink's contents by _prune_hlink_if_empty.
- play_sound uses RT.AUDIO, not RT.MEDIA. The Microsoft-2007
relationships/media rel under CT_EmbeddedWAVAudioFile/@r:embed
triggers PowerPoint's Repair dialog and strips the entire hlinkClick
plus the WAV part. relationships/audio (ECMA-376) is the rel
PowerPoint actually expects for embedded WAV under a:snd.
KNOWN LIMITATION — no-click-action hover ScreenTip not rendered:
PowerPoint does not surface a hover ScreenTip in slideshow mode for
shapes that have no click action. This applies to BOTH paths:
- cNvPr/a:hlinkClick/@ToolTip without a navigation target
- cNvPr/@Descr (alt_text)
Both round-trip correctly through save/reload at the XML layer, but
PowerPoint's slideshow runtime only activates hover-ScreenTip
rendering when the hyperlink carries a real navigation target — URL,
slide jump, macro, or program. There is no known fully-supported
OOXML workaround for a pure no-click-action hover ScreenTip.
ScreenTips on hyperlinks WITH a navigation target work correctly.
alt_text remains useful for accessibility / screen reader text.
The relevant docstrings (Hyperlink.tooltip, ActionSetting.tooltip,
Run.hyperlink.tooltip) all document this limitation.
Surface:
- src/pptx/action.py: +229 lines — target_program, run_macro,
play_sound, tooltip (read/write) on both ActionSetting and
Hyperlink; _get_or_add_hlink default r:id=""; helpers
_prune_hlink_if_empty, _ensure_noaction_if_inert,
_ensure_noaction_pruned
- src/pptx/oxml/action.py: +63 lines — CT_Hyperlink expanded with
a:snd (CT_EmbeddedWAVAudioFile) child, endSnd attribute, tooltip
attribute, tgtFrame attribute; CT_EmbeddedWAVAudioFile element
class with @r:embed and @name
- src/pptx/oxml/__init__.py: registration for a:snd
- src/pptx/shapes/base.py: alt_text, alt_title, is_decorative,
is_hidden_from_accessibility properties on BaseShape
- src/pptx/shapes/picture.py: hyperlink property
- src/pptx/text/text.py: Run.hyperlink.tooltip, Run.hyperlink.color,
Run.click_action (parallel to Shape.click_action)
- tests/test_issue21_hyperlinks.py: 38 new unit tests covering every
sub-feature
- features/iss-21-hyperlinks-clickactions.feature: 9 acceptance
scenarios (run ScreenTip, alt_text round-trip, run hyperlink color,
run-macro, play-sound, hover action, run jump-to-slide, picture
hyperlink, tooltip-only XML round-trip)
- features/steps/iss21.py: behave step implementations
- .gitignore: .DS_Store (macOS Finder noise)
Tests: 4021 passed (was 3983 before #21; +38 new). Lint: ruff format +
check clean. Behave: 1139 scenarios, 0 failed.1 parent ee53fd0 commit 4a53782
10 files changed
Lines changed: 1227 additions & 9 deletions
File tree
- features
- steps
- src/pptx
- oxml
- shapes
- text
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
0 commit comments