"""Objects related to shapes.A shape is a visual object that appears on the drawing layer of a document."""from__future__importannotationsfromtypingimportTYPE_CHECKINGfromdocx.enum.shapeimportWD_INLINE_SHAPEfromdocx.oxml.nsimportnsmapfromdocx.sharedimportParentedifTYPE_CHECKING:fromdocx.oxml.documentimportCT_Bodyfromdocx.oxml.shapeimportCT_Inlinefromdocx.parts.storyimportStoryPartfromdocx.sharedimportLength
[文档]classInlineShapes(Parented):"""Sequence of |InlineShape| instances, supporting len(), iteration, and indexed access."""def__init__(self,body_elm:CT_Body,parent:StoryPart):super(InlineShapes,self).__init__(parent)self._body=body_elmdef__getitem__(self,idx:int):"""Provide indexed access, e.g. 'inline_shapes[idx]'."""try:inline=self._inline_lst[idx]exceptIndexError:msg="inline shape index [%d] out of range"%idxraiseIndexError(msg)returnInlineShape(inline)def__iter__(self):return(InlineShape(inline)forinlineinself._inline_lst)def__len__(self):returnlen(self._inline_lst)@propertydef_inline_lst(self):body=self._bodyxpath="//w:p/w:r/w:drawing/wp:inline"returnbody.xpath(xpath)
[文档]classInlineShape:"""Proxy for an ``<wp:inline>`` element, representing the container for an inline graphical object."""def__init__(self,inline:CT_Inline):super(InlineShape,self).__init__()self._inline=inline@propertydefheight(self)->Length:"""Read/write. The display height of this inline shape as an |Emu| instance. """returnself._inline.extent.cy@height.setterdefheight(self,cy:Length):self._inline.extent.cy=cyself._inline.graphic.graphicData.pic.spPr.cy=cy@propertydeftype(self):"""The type of this inline shape as a member of ``docx.enum.shape.WD_INLINE_SHAPE``, e.g. ``LINKED_PICTURE``. Read-only. """graphicData=self._inline.graphic.graphicDatauri=graphicData.uriifuri==nsmap["pic"]:blip=graphicData.pic.blipFill.blipifblip.linkisnotNone:returnWD_INLINE_SHAPE.LINKED_PICTUREreturnWD_INLINE_SHAPE.PICTUREifuri==nsmap["c"]:returnWD_INLINE_SHAPE.CHARTifuri==nsmap["dgm"]:returnWD_INLINE_SHAPE.SMART_ARTreturnWD_INLINE_SHAPE.NOT_IMPLEMENTED@propertydefwidth(self):"""Read/write. The display width of this inline shape as an |Emu| instance. """returnself._inline.extent.cx@width.setterdefwidth(self,cx:Length):self._inline.extent.cx=cxself._inline.graphic.graphicData.pic.spPr.cx=cx