Skip to content

Let Shapes and SlidePlaceholders fulfill the Mapping interface#800

Open
timhoffm wants to merge 1 commit into
scanny:masterfrom
timhoffm:placeholders-mapping
Open

Let Shapes and SlidePlaceholders fulfill the Mapping interface#800
timhoffm wants to merge 1 commit into
scanny:masterfrom
timhoffm:placeholders-mapping

Conversation

@timhoffm

Copy link
Copy Markdown

Both are essentially mappings and define the minimal interface
for collections.abc.Mapping (https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes),
i.e. __iter__, __getitem__ and __len__.

By inheriting from Mapping we mix in the full mapping behavior, .e.g. .get()
and .key() methods. This is to make these collections feel more pythonic.
Additionally, it's a real usability improvement: e.g. for SlidePlaceholders
one cannot guess the valid keys, which makes placeholders[idx] difficult to use.
Having placeholders.keys() available makes inspection much easier.

Both are essentially mappings and define the minimal interface
for `collections.abc.Mapping` (https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes).

By inheriting from `Mapping` we mix in the full mapping behavior, .e.g. `.get()`
and `.key()` methods. This is to make these collections feel more pythonic.
Additionally, it's a real usability improvement: e.g. for `SlidePlaceholders`
one cannot guess the valid keys, which makes `placeholders[idx]` difficult to use.
Having `placeholders.keys()` available makes inspection much easier.
loadfix added a commit to loadfix/python-pptx that referenced this pull request Jun 2, 2026
… Frame fit/justify (scanny#773, scanny#791, scanny#794) (scanny#800)

Box.text(text, style={"font_size_pt": N, ...}) now estimates natural_w
/ natural_h from the text content + font size when the caller leaves
both axes implicit (width ~= len(longest_line) * font_size_pt * 0.55em
capped at 8in; height ~= font_size_pt * line_count * 1.4). Authors
who wrote ``Box.text("Title", style={"font_size_pt": 28})`` previously
got a 1in x 10pt rectangle and watched their text overflow; the
estimator now hands them a usable allocation. from_markdown stamps a
default 11pt body size on bullet / paragraph leaves so the estimator
runs for them too. Stack.wrap accepts "when_overflow" as a CSS-flexbox
alias for "auto" (both spellings dispatch to the same wrap path; the
spelling round-trips through to_spec / from_spec). Frame(fit="contain")
is silently promoted to "fill" when the child is a Stack whose justify
is space-between / space-around / space-evenly, so the distribution
mode actually receives the full inner rectangle.

Closes scanny#773.
Closes scanny#791.
Closes scanny#794.

Co-authored-by: Ben Hooper <ben@plex.networkinsanity.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant