python-pptx icon indicating copy to clipboard operation
python-pptx copied to clipboard

added functionality for reading alt text of shape

Open cray2015 opened this issue 6 years ago • 13 comments

#508 issue implemented in this PR. kindly review it.

cray2015 avatar May 30 '19 05:05 cray2015

I have implemented this property on my local system and on my fork copy. It works as it should.

honcharovs avatar Jul 14 '21 07:07 honcharovs

@honcharovs are you asking me or the repo owner?

cray2015 avatar Jul 14 '21 08:07 cray2015

Hi All. Aware this is an old thread. Is there anything preventing this being merged? It would be a really useful addition.

will-plutoflume avatar Jul 13 '22 08:07 will-plutoflume

Hi All. Just want to upvote this. @scanny, please review and include.

Vlad22 avatar Feb 06 '23 18:02 Vlad22

Hi, it would be useful capability. @scanny could you include it?

rgmon avatar Feb 08 '23 20:02 rgmon

This would be super useful. Any obstacles to it being merged?

hermanc1 avatar Sep 09 '23 14:09 hermanc1

@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 shape.alt_text, but it's not currently on the docket and a function like this is easy to add to your package or in some sort of pptxutils package you put together if you use it on a lot of projects and want to maintain only one copy of the functions like this.

scanny avatar Sep 11 '23 03:09 scanny

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 desc, but (as in your code) it is descr. Thank you once again - it really helps!

hermanc1 avatar Sep 24 '23 07:09 hermanc1

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.

scanny avatar Sep 25 '23 16:09 scanny

is there any update?

robertschulze avatar Jan 17 '24 11:01 robertschulze

Any progress here?

mdylan2 avatar Jul 30 '24 20:07 mdylan2