Skip to content

Add a non private API to be able to modify the description of the picture. #1139

Description

@Alexandre-SCHOEPP

Basic functionality

I want to be able to add pictures to my slide while being somewhat accessible to visually impaired people.

As far as I know, this is done by setting the descr attribute in the p:cNvPr tag, which I think you currently set, in the desc property, to be the file name if it exists or the image.{ext} template if it does not.

I would like you to add, to the parts.image.ImagePart class a _descr attribute which defaults to None upon first instanciation, and which would be readable and writable.

I would also like the add_picture method of the SlideShapes class to have an optional, keyword only argument that would set this value.

Proposed implementation

class ImagePart(Part):
  ...
  def __init__(self, partname, ..., descr: str | None = None):
    ...
    self._descr = desc

  @property
  def desc(self) -> str:
    if self._descr is not None:
      return self._descr
    ...  # Existing logic

  @property
  def image(self)
    return Image(self._blob, self._filename)
class _BaseGroupShapes(_BaseShapes):
  def add_picture(self, ..., *, description: str | None = None):
    image_part, rId = self.part.get_or_add_image_part(image_file)
    if description is not None:
      image_part._descr = description
    ...  # existing logic

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions