XjdZddlmZddlmZmZmZmZddlm Z ddl m Z ddl mZddlmZmZerddlmZdd lmZdd lmZdd lmZGd d e Zy)z |StoryPart| and related objects.) annotations)IO TYPE_CHECKINGTuplecast)RELATIONSHIP_TYPE)XmlPart) CT_Inline)Length lazyproperty) WD_STYLE_TYPE)Image) DocumentPart) BaseStylecteZdZdZd dZd dZ d dZ d d dZeddZ e ddZ y) StoryPartzBase class for story parts. A story part is one that can contain textual content, such as the document-part and header or footer parts. These all share content behaviors like `.paragraphs`, `.add_paragraph()`, `.add_table()` etc. c|j}|J|j|}|j|tj}||j fS)a|Return (rId, image) pair for image identified by `image_descriptor`. `rId` is the str key (often like "rId7") for the relationship between this story part and the image part, reused if already present, newly created if not. `image` is an |Image| instance providing access to the properties of the image, such as dimensions and image type. )_packageget_or_add_image_part relate_toRTIMAGEimage)selfimage_descriptorpackage image_partrIds d/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/docx/parts/story.pyget_or_add_imagezStoryPart.get_or_add_imagesO--"""223CD nnZ2J$$$$c:|jj||S)zReturn the style in this document matching `style_id`. Returns the default style for `style_type` if `style_id` is |None| or does not match a defined style of `style_type`. )_document_part get_style)rstyle_id style_types rr$zStoryPart.get_style)s "",,XzBBr!c:|jj||S)a2Return str style_id for `style_or_name` of `style_type`. Returns |None| if the style resolves to the default style for `style_type` or if `style_or_name` is itself |None|. Raises if `style_or_name` is a style of the wrong type or names a style not present in the document. )r# get_style_id)r style_or_namer&s rr(zStoryPart.get_style_id1s""// zJJr!Nc|j|\}}|j||\}}|j|j} }t j ||| ||S)zReturn a newly-created `w:inline` element. The element contains the image specified by `image_descriptor` and is scaled based on the values of `width` and `height`. )r scaled_dimensionsnext_idfilenamer new_pic_inline) rrwidthheightrrcxcyshape_idr-s rr.zStoryPart.new_pic_inline<sY**+;< U((7B!\\5>>(''#xRHHr!c|jjd}|Dcgc]}|jst| }}|syt |dzScc}w)aBNext available positive integer id value in this story XML document. The value is determined by incrementing the maximum existing id value. Gaps in the existing id sequence are not filled. The id attribute value is unique in the document, without regard to the element type it appears on. z//@id)_elementxpathisdigitintmax)r id_str_lstid_strused_idss rr,zStoryPart.next_idLsS]]((1 .8MFFNN$>??r!)rstr | IO[bytes]returnzTuple[str, Image])r% str | Noner&r rAr)r)zBaseStyle | str | Noner&r rArB)NN)rr@r/int | Length | Noner0rCrAr )rAr9)rAr) __name__ __module__ __qualname____doc__r r$r(r.propertyr,r r#r!rrrs %C K3 KAN K  K&*&* I)I#I$ I  I  ! !@@r!rN)rG __future__rtypingrrrrdocx.opc.constantsrr docx.opc.partr docx.oxml.shaper docx.sharedr r docx.enum.styler docx.image.imagerdocx.parts.documentrdocx.styles.stylerrrIr!rrTs<&"116!%,-&0+L@L@r!