added functionality for reading alt text of shape#512
Conversation
|
I have implemented this property on my local system and on my fork copy. |
honcharovs
left a comment
There was a problem hiding this comment.
It works as it should.
Can you change
pptx/oxml/shapes/shared.py line 314 ' to " around 'descr'?
|
@honcharovs are you asking me or the repo owner? |
|
Hi All. Aware this is an old thread. Is there anything preventing this being merged? It would be a really useful addition. |
|
Hi All. Just want to upvote this. @scanny, please review and include. |
|
Hi, it would be useful capability. @scanny could you include it? |
|
This would be super useful. Any obstacles to it being merged? |
|
@hermanc1 You can accomplish this inline like this: alt_text = shape._element._nvXxPr.cNvPr.attrib.get("descr", "")or wrap it in a utility/work-around function like this: from pptx.shapes.base import BaseShape
def shape_alt_text(shape: BaseShape) -> str:
"""Alt-text defined in shape's `descr` attribute, or "" if not present."""
return shape._element._nvXxPr.cNvPr.attrib.get("descr", "")We might well add this at something like |
|
Thank you @scanny - I appreciate it! I implemented it now and it works well. One small note: in the docstring for the function, you call the attribute |
|
Good catch, thanks @hermanc1 :) I've updated the docstring. I expect to be in making a few additions before long so have shortlisted this to consider for the next release as well. |
|
is there any update? |
|
Any progress here? |
|
Can I somehow help to get this merged? |
|
+1 |
…]) (scanny#512) Closes scanny#512. Scheduled / unattended deck rebuilds crash the day a primary image source quietly moves: the CDN URL 404s, the brand-asset path on the shared drive is renamed, the local cache was cleaned by the agent. `pptx.kit.image_fallback_chain` wraps `add_picture` with a fallback chain — a list of candidate sources tried in priority order. The first one that loads becomes the embedded image; the rest are ignored. When every source fails, an `on_fail` policy picks **raise** (default), **warn** (log + return None), or **placeholder** (embed a deterministic 1x1 transparent PNG so the rest of the slide build can continue). Each candidate may be a filesystem path (`str` / `os.PathLike`), an `http(s)://` / `file://` URL (stdlib `urllib`, no extra runtime dep, configurable timeout), a `bytes`/`bytearray`/`memoryview` blob, or any file-like object exposing `.read()`. URL credentials and query strings are redacted from log payloads via `redact_source` so secrets never leak into cron logs. `bind()` installs `add_picture_with_fallback` on Slide / SlideShapes for the natural chained call shape. Public surface: - `fallback_chain(target, sources, left, top, ...)` — list-first - `add_picture_with_fallback(target, primary, fallbacks, ...)` — keyword-form mirroring the issue spec literal - `bind()` — install Slide.add_picture_with_fallback (idempotent) - `is_placeholder_picture(picture)` — audit-side helper - `make_placeholder_blob()`, `redact_source(src)`, `AllSourcesFailedError`, `PLACEHOLDER_PNG_BYTES`, `ON_FAIL_MODES`, `RECOVERABLE_LOAD_ERRORS`, `DEFAULT_TIMEOUT` 64 unit tests covering all public callables, every `on_fail` branch, all four source-shape branches, URL redaction (incl. userinfo + query string), the bound-method binding, and end-to-end secret- redaction in warn-mode log payloads. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
#508 issue implemented in this PR. kindly review it.