Commit 6f65019
committed
feat: HandoutMaster + add_text_watermark helper — Phase 5, closing #20
Closes the headers/footers epic (#20). Phase 1 (PR #48) shipped the
`CT_HandoutMaster` OOXML wrapper; Phases 2-4 (PRs #49, #50, #51) built
out the public headers/footers/fields surface. Phase 5 adds the two
remaining pieces: a public `HandoutMaster` Python class so users can
read a handout master's visibility settings without dropping into XML,
and a `SlideMaster.add_text_watermark()` helper that wraps the common
"DRAFT"-style watermark pattern into one call.
Why this is small. `_HeaderFooterVisibility` (Phase 2) and
`CT_HandoutMaster` (Phase 1) already do the heavy lifting; Phase 5 just
wires a Python proxy + part + accessor onto them and adds a thin
convenience method.
Changes:
- pptx.slide.HandoutMaster — new class, inherits
`_HeaderFooterVisibility, _BaseMaster` in the same order as
`NotesMaster`. Docstring names the deferred auto-create.
- pptx.slide.SlideMaster.add_text_watermark — new method. Adds a
centered 6in x 1.5in textbox to the master at standard 10in x 7.5in
slide coordinates (left=2in, top=3in). Text gets `PP_ALIGN.CENTER`;
the first run gets `font.name`, `font.size`, mid-gray solid fill,
and the configured `transparency` (default 0.7). Returns the new
`Shape` so callers can re-position or restyle.
- pptx.slide._HeaderFooterVisibility — `_element` type union widened
to include `CT_HandoutMaster` so the mixin types cleanly under
`HandoutMaster`.
- pptx.parts.slide.HandoutMasterPart — new `BaseSlidePart` subclass.
Defines `handout_master` lazyproperty; deliberately omits
`create_default` / `_new` / `_new_theme_part` because no
`handoutMaster.xml` template ships in this fork yet.
- pptx.parts.presentation.PresentationPart.handout_master_part — new
lazyproperty. Returns `part_related_by(RT.HANDOUT_MASTER)` when
present; raises `ValueError` with a "no handout master" message
(chained `from KeyError`) when absent. Unlike
`notes_master_part`, this does NOT auto-create.
- pptx.parts.presentation.PresentationPart.handout_master — new
lazyproperty pass-through to `.handout_master_part.handout_master`.
- pptx.presentation.Presentation.handout_master — new property
pass-through, matching the shape of `notes_master`.
- pptx.shapes.shapetree.MasterShapes.add_textbox — new method,
parallel to the existing `SlideShapes.add_textbox`. Needed so
`SlideMaster.add_text_watermark` can drop a textbox directly on
the master's shape tree (master shapes previously had no
`add_textbox`, only the slide / layout collections did).
- pptx/__init__.py — registers `HandoutMasterPart` against
`CT.PML_HANDOUT_MASTER` in `content_type_to_part_class_map` and
adds it to the cleanup `del (...)` tuple.
Out of scope for Phase 5 (deliberate, see ISA Out of Scope):
- Auto-create of handout master when absent. Synthesizing one from
scratch needs a known-good `handoutMaster.xml` template, and
shipping that template + the theme wiring is risky without a
reference deck. Phase 6+ if real users ask. The error message
surfaces the deferral explicitly.
- `HandoutMaster.add_placeholder()` / placeholder cloning — read-only
this phase; the inherited visibility props are write-enabled, but
the placeholder set on the handout master is static.
- Image-watermark helper — `master.shapes.add_picture(...)` already
does this in one line; wrapping it adds little value.
- Per-slide watermark — `add_text_watermark` lives on `SlideMaster`
so every slide using that master gets the watermark by inheritance;
per-slide watermark is just `slide.shapes.add_textbox(...)` today.
- `MSO_WATERMARK_PRESET` enum or canned styles — string text +
numeric transparency is the entire API surface.
Anti-criteria upheld:
- No `handoutMaster.xml` template file added (verified by
`find src -name '*handoutMaster*'`).
- `Presentation.handout_master` does NOT silently auto-create — the
`but_it_raises_ValueError_when_no_handout_master_is_present` test
in `tests/parts/test_presentation.py` pins this.
- No `add_image_watermark` or `MSO_WATERMARK_PRESET` (verified by
`grep -rn 'add_image_watermark|MSO_WATERMARK' src/ tests/`).
- `NotesMaster` and `NotesMasterPart` bodies are unchanged; only
import lines that previously named just `NotesMaster` now also
name `HandoutMaster`.
- `it_has_no_create_default_classmethod` in
`tests/parts/test_slide.py` regression-pins that
`HandoutMasterPart` does NOT acquire `create_default` over time.
Test counts: 19 new test cases (16 new `it_/but_/and_` functions; the
`it_round_trips_show_attrs_via_hf` parametrize fans out to 4 cases).
Distribution: 6 in `DescribeHandoutMaster`, 4 in
`DescribeSlideMasterAddTextWatermark`, 4 in `DescribeHandoutMasterPart`,
3 in `DescribePresentationPart`, 1 in `DescribePresentation`. Pytest
runs at 3651 passed (baseline 3632 + 19).
Verification (local, CPython 3.14.4):
$ python3 -m pytest tests/ -q | tail -3
........................................................................ [100%]
................................................... [100%]
3651 passed in 5.28s
$ python3 -m ruff check src tests | tail -3
All checks passed!
$ python3 -m ruff format --check src tests | tail -3
216 files already formatted
$ python3 -m behave features/ --no-color 2>&1 | tail -3
1048 scenarios passed, 0 failed, 0 skipped
3151 steps passed, 0 failed, 0 skipped
Took 0min 1.696s
$ python3 uat/uat_headers_footers_phase5.py
opening /Users/mhoroszowski/Projects/AI/python-pptx/tests/test_files/test.pptx
OK — missing handout master raises ValueError: presentation has no handout master; auto-create is deferred because no handout master template ships in this fork yet
adding watermark 'DRAFT' to slide_masters[0]
watermark shape: left=1828800 top=2743200 width=5486400 height=1371600
saving to /Users/mhoroszowski/Projects/AI/python-pptx/uat/out_headers_footers_phase5.pptx
re-opening /Users/mhoroszowski/Projects/AI/python-pptx/uat/out_headers_footers_phase5.pptx
round-tripped watermark: text='DRAFT' font='Calibri' size=72.0 transparency=0.7
OK — watermark transparency round-tripped at 0.7
PASS — handout-master absent-path and watermark helper verified
Closes #20.1 parent 87b22c7 commit 6f65019
10 files changed
Lines changed: 290 additions & 10 deletions
File tree
- src/pptx
- parts
- shapes
- tests
- parts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
| 86 | + | |
84 | 87 | | |
85 | 88 | | |
86 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
101 | 101 | | |
102 | 102 | | |
103 | 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 | + | |
104 | 128 | | |
105 | 129 | | |
106 | 130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
117 | 131 | | |
118 | 132 | | |
119 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
70 | 79 | | |
71 | 80 | | |
72 | 81 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
831 | 831 | | |
832 | 832 | | |
833 | 833 | | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
834 | 841 | | |
835 | 842 | | |
836 | 843 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | | - | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| |||
97 | 101 | | |
98 | 102 | | |
99 | 103 | | |
100 | | - | |
| 104 | + | |
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
| |||
178 | 182 | | |
179 | 183 | | |
180 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
181 | 194 | | |
182 | 195 | | |
183 | 196 | | |
| |||
735 | 748 | | |
736 | 749 | | |
737 | 750 | | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
738 | 784 | | |
739 | 785 | | |
740 | 786 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
86 | 86 | | |
87 | 87 | | |
88 | 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 | + | |
89 | 123 | | |
90 | 124 | | |
91 | 125 | | |
| |||
192 | 226 | | |
193 | 227 | | |
194 | 228 | | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
195 | 233 | | |
196 | 234 | | |
197 | 235 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
179 | 180 | | |
180 | 181 | | |
181 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
182 | 211 | | |
183 | 212 | | |
184 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| |||
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
93 | 103 | | |
94 | 104 | | |
95 | 105 | | |
| |||
194 | 204 | | |
195 | 205 | | |
196 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
197 | 211 | | |
198 | 212 | | |
199 | 213 | | |
| |||
0 commit comments