o
    j9                     @  s  d Z ddlmZ ddlmZmZmZ ddlmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZmZmZmZ dd	lmZ dd
lmZmZmZmZmZmZ er`ddlmZmZm Z  ddl!m"Z" G dd deZ#G dd deZ$G dd deZ%G dd deZ&G dd deZ'G dd deZ(G dd deZ)G dd deZ*G dd deZ+G dd  d eZ,G d!d" d"eZ-G d#d$ d$eZ.G d%d& d&eZ/d'S )(z;lxml custom element classes for shape-related XML elements.    )annotations)TYPE_CHECKINGCallablecast)MSO_AUTO_SHAPE_TYPEPP_PLACEHOLDER)	parse_xmlnsdecls)BaseShapeElement)ST_CoordinateST_PositiveCoordinate
XsdBoolean	XsdString)CT_TextBody)BaseOxmlElementOneAndOnlyOneOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOne)#CT_ApplicationNonVisualDrawingPropsCT_NonVisualDrawingPropsCT_ShapeProperties)Lengthc                   @  6   e Zd ZU dZedeZded< edeZded< dS )CT_AdjPoint2Dz`a:pt` custom element class.xr   yN)	__name__
__module____qualname____doc__r   r   r   __annotations__r    r$   r$   Z/home/air/Certificate/back/venv/lib/python3.10/site-packages/pptx/oxml/shapes/autoshape.pyr   &   s   
 r   c                   @  s:   e Zd ZU dZded< dZededd dZd	ed
< dS )CT_CustomGeometry2Dz"`a:custGeom` custom element class.zCallable[[], CT_Path2DList]get_or_add_pathLst)a:avLstza:gdLstza:ahLstza:cxnLstza:rect	a:pathLstr)      N
successorszCT_Path2DList | NonepathLst)r   r    r!   r"   r#   _tag_seqr   r-   r$   r$   r$   r%   r&   -   s   
 r&   c                   @  r   )CT_GeomGuidezz`a:gd` custom element class.

    Defines a "guide", corresponding to a yellow diamond-shaped handle on an autoshape.
    namestrfmlaN)	r   r    r!   r"   r   r   r0   r#   r2   r$   r$   r$   r%   r/   8   s   
 r/   c                   @  s*   e Zd ZU dZded< ded< edZdS )CT_GeomGuideListz`a:avLst` custom element class.zCallable[[], CT_GeomGuide]_add_gdlist[CT_GeomGuide]gd_lstza:gdN)r   r    r!   r"   r#   r   gdr$   r$   r$   r%   r3   B   s
   
 r3   c                   @  s,   e Zd ZU dZedZedeZde	d< dS )CT_NonVisualDrawingShapePropsz!`p:cNvSpPr` custom element class.z	a:spLockstxBoxzbool | NoneN)
r   r    r!   r"   r   spLocksr   r   r9   r#   r$   r$   r$   r%   r8   L   s   
 r8   c                   @  s   e Zd ZU dZded< ded< ded< edd	d
Zedd	d
Zedd	d
Ze	de
Zded< e	de
Zded< dddZdddZdddZdS ) 	CT_Path2Dz`a:path` custom element class.zCallable[[], CT_Path2DClose]
_add_closezCallable[[], CT_Path2DLineTo]	_add_lnTozCallable[[], CT_Path2DMoveTo]_add_moveToza:closer$   r+   za:lnToza:moveTowzLength | NonehreturnCT_Path2DClosec                 C  s   |   S )z{Return a newly created `a:close` element.

        The new `a:close` element is appended to this `a:path` element.
        )r<   selfr$   r$   r%   	add_closef   s   zCT_Path2D.add_closer   r   r   CT_Path2DLineToc                 C  "   |   }| }|||_|_|S )zReturn a newly created `a:lnTo` subtree with end point *(x, y)*.

        The new `a:lnTo` element is appended to this `a:path` element.
        )r=   _add_ptr   r   )rD   r   r   lnToptr$   r$   r%   add_lnTom      zCT_Path2D.add_lnToc                 C  rG   )zReturn a newly created `a:moveTo` subtree with point `(x, y)`.

        The new `a:moveTo` element is appended to this `a:path` element.
        )r>   rH   r   r   )rD   r   r   moveTorJ   r$   r$   r%   
add_moveTow   rL   zCT_Path2D.add_moveToN)rA   rB   )r   r   r   r   rA   rF   )r   r   r   r   )r   r    r!   r"   r#   r   closerI   rM   r   r   r?   r@   rE   rK   rN   r$   r$   r$   r%   r;   U   s"   
 


r;   c                   @  s   e Zd ZdZdS )rB   z`a:close` custom element class.N)r   r    r!   r"   r$   r$   r$   r%   rB      s    rB   c                   @  &   e Zd ZU dZded< edddZdS )rF   z`a:lnTo` custom element class.Callable[[], CT_AdjPoint2D]rH   a:ptr$   r+   Nr   r    r!   r"   r#   r   rJ   r$   r$   r$   r%   rF         
 rF   c                   @  s0   e Zd ZU dZded< edddZdd
dZdS )CT_Path2DListz!`a:pathLst` custom element class.zCallable[[], CT_Path2D]	_add_pathza:pathr$   r+   r?   r   r@   c                 C  s   |   }|||_|_|S )z.Return a newly created `a:path` child element.)rV   r?   r@   )rD   r?   r@   pathr$   r$   r%   add_path   s   zCT_Path2DList.add_pathN)r?   r   r@   r   )r   r    r!   r"   r#   r   rW   rX   r$   r$   r$   r%   rU      s
   
 rU   c                   @  rP   )CT_Path2DMoveToz `a:moveTo` custom element class.rQ   rH   rR   r$   r+   NrS   r$   r$   r$   r%   rY      rT   rY   c                   @  s\   e Zd ZU dZded< ded< edZded< ed	eZ	d
ed	< e
dddZdddZdS )CT_PresetGeometry2Dz"`a:prstGeom` custom element class.zCallable[[], CT_GeomGuideList]
_add_avLstzCallable[[], None]_remove_avLstr(   zCT_GeomGuideList | NoneavLstprstr   rA   r5   c                 C  s   | j }|du r	g S |jS )zLSequence of `a:gd` element children of `a:avLst`. Empty if none are present.N)r]   r6   )rD   r]   r$   r$   r%   r6         zCT_PresetGeometry2D.gd_lstguideslist[tuple[str, int]]c                 C  s:   |    |  }|D ]\}}| }||_d| |_q
dS )zOReplace any `a:gd` element children of `a:avLst` with ones forme from `guides`.zval %dN)r\   r[   r4   r0   r2   )rD   r`   r]   r0   valr7   r$   r$   r%   rewrite_guides   s   z"CT_PresetGeometry2D.rewrite_guidesN)rA   r5   )r`   ra   )r   r    r!   r"   r#   r   r]   r   r   r^   propertyr6   rc   r$   r$   r$   r%   rZ      s   
 rZ   c                   @  s   e Zd ZU dZded< edZded< edZded	< ed
ddZ	ded< dCddZ
dd Zedd Zedd Zedd Zedd ZedDd)d*ZedEd0d1ZedFd5d6Zed7d8 Zed9d: ZedGd<d=Zd>d? Zed@dA ZdBS )HCT_Shapez`p:sp` custom element class.zCallable[[], CT_TextBody]get_or_add_txBodyzp:nvSpPrCT_ShapeNonVisualnvSpPrzp:spPrr   spPrzp:txBody)zp:extLstr+   zCT_TextBody | NonetxBodyr?   r   r@   rA   r;   c                 C  s.   | j j}|d u rtd| }|j||dS )Nzshape must be freeform)r?   r@   )ri   custGeom
ValueErrorr'   rX   )rD   r?   r@   rk   r-   r$   r$   r%   rX      s
   zCT_Shape.add_pathc                 C  s
   | j  S )zAReturn the `a:ln` grandchild element, newly added if not present.)ri   get_or_add_lnrC   r$   r$   r%   rm      s   
zCT_Shape.get_or_add_lnc                 C  s   | j jduS )zTrue if this shape has custom geometry, i.e. is a freeform shape.

        A shape has custom geometry if it has a `p:spPr/a:custGeom`
        descendant (instead of `p:spPr/a:prstGeom`).
        N)ri   rk   rC   r$   r$   r%   has_custom_geometry   s   zCT_Shape.has_custom_geometryc                 C  s    | j }|du r	dS | jjjduS )zTrue if this shape is an auto shape.

        A shape is an auto shape if it has a `a:prstGeom` element and does not have a txBox="1"
        attribute on cNvSpPr.
        NFT)prstGeomrh   cNvSpPrr9   rD   ro   r$   r$   r%   is_autoshape   s   zCT_Shape.is_autoshapec                 C  s   | j jjdu S )zTrue if this shape is a text box.

        A shape is a text box if it has a `txBox` attribute on cNvSpPr that resolves to |True|.
        The default when the txBox attribute is missing is |False|.
        T)rh   rp   r9   rC   r$   r$   r%   
is_textbox   s   zCT_Shape.is_textboxc                 C     | j jS )z4`a:ln` grand-child element or |None| if not present.)ri   lnrC   r$   r$   r%   ru      s   zCT_Shape.lnid_intr0   r1   r^   lefttopwidthheightc              	   C  s>   dt dddddddddf | ||||||f }ttt|S )zAReturn a new `p:sp` element tree configured as a base auto shape.a  <p:sp %s>
  <p:nvSpPr>
    <p:cNvPr id="%s" name="%s"/>
    <p:cNvSpPr/>
    <p:nvPr/>
  </p:nvSpPr>
  <p:spPr>
    <a:xfrm>
      <a:off x="%s" y="%s"/>
      <a:ext cx="%s" cy="%s"/>
    </a:xfrm>
    <a:prstGeom prst="%s">
      <a:avLst/>
    </a:prstGeom>
  </p:spPr>
  <p:style>
    <a:lnRef idx="1">
      <a:schemeClr val="accent1"/>
    </a:lnRef>
    <a:fillRef idx="3">
      <a:schemeClr val="accent1"/>
    </a:fillRef>
    <a:effectRef idx="2">
      <a:schemeClr val="accent1"/>
    </a:effectRef>
    <a:fontRef idx="minor">
      <a:schemeClr val="lt1"/>
    </a:fontRef>
  </p:style>
  <p:txBody>
    <a:bodyPr rtlCol="0" anchor="ctr"/>
    <a:lstStyle/>
    <a:p>
      <a:pPr algn="ctr"/>
    </a:p>
  </p:txBody>
</p:sp>ap%d%sr
   r   re   r   )rv   r0   r^   rx   ry   rz   r{   xmlr$   r$   r%   new_autoshape_sp   s   $%'zCT_Shape.new_autoshape_spshape_idr   r   cxcyc                 C  s:   dt ddddddddf | |||||f }ttt|S )zReturn new `p:sp` element tree configured as freeform shape.

        The returned shape has a `a:custGeom` subtree but no paths in its
        path list.
        aJ  <p:sp %s>
  <p:nvSpPr>
    <p:cNvPr id="%s" name="%s"/>
    <p:cNvSpPr/>
    <p:nvPr/>
  </p:nvSpPr>
  <p:spPr>
    <a:xfrm>
      <a:off x="%s" y="%s"/>
      <a:ext cx="%s" cy="%s"/>
    </a:xfrm>
    <a:custGeom>
      <a:avLst/>
      <a:gdLst/>
      <a:ahLst/>
      <a:cxnLst/>
      <a:rect l="l" t="t" r="r" b="b"/>
      <a:pathLst/>
    </a:custGeom>
  </p:spPr>
  <p:style>
    <a:lnRef idx="1">
      <a:schemeClr val="accent1"/>
    </a:lnRef>
    <a:fillRef idx="3">
      <a:schemeClr val="accent1"/>
    </a:fillRef>
    <a:effectRef idx="2">
      <a:schemeClr val="accent1"/>
    </a:effectRef>
    <a:fontRef idx="minor">
      <a:schemeClr val="lt1"/>
    </a:fontRef>
  </p:style>
  <p:txBody>
    <a:bodyPr rtlCol="0" anchor="ctr"/>
    <a:lstStyle/>
    <a:p>
      <a:pPr algn="ctr"/>
    </a:p>
  </p:txBody>
</p:sp>r|   r}   r~   r   r   )r   r0   r   r   r   r   r   r$   r$   r%   new_freeform_sp&  s   )*,zCT_Shape.new_freeform_spph_typer   orientc           	   
   C  s~   t ttdtdd d|  d| d}|jj }||_||_||_	||_
tjtjtjtjtjf}||v r=|t  |S )zCReturn a new `p:sp` element tree configured as a placeholder shape.z<p:sp r|   r}   z >
  <p:nvSpPr>
    <p:cNvPr id="z" name="zq"/>
    <p:cNvSpPr>
      <a:spLocks noGrp="1"/>
    </p:cNvSpPr>
    <p:nvPr/>
  </p:nvSpPr>
  <p:spPr/>
</p:sp>)r   re   r   r
   rh   nvPrget_or_add_phtypeidxr   szr   TITLECENTER_TITLESUBTITLEBODYOBJECTappendr   new)	rv   r0   r   r   r   r   spph(placeholder_types_that_have_a_text_framer$   r$   r%   new_placeholder_sp[  s0   zCT_Shape.new_placeholder_spc           	      C  s(   t  }|| |||||f }t|}|S )zDReturn a new `p:sp` element tree configured as a base textbox shape.)re   _textbox_sp_tmplr   )	rv   r0   rx   ry   rz   r{   tmplr   r   r$   r$   r%   new_textbox_sp  s   zCT_Shape.new_textbox_spc                 C  s   | j }|du r	dS |jS )zKValue of `prst` attribute of `a:prstGeom` element or |None| if not present.N)ro   r^   rq   r$   r$   r%   r^     r_   zCT_Shape.prstrZ   c                 C  rt   )zReference to `a:prstGeom` child element.

        |None| if this shape doesn't have one, for example, if it's a placeholder shape.
        )ri   ro   rC   r$   r$   r%   ro     s   zCT_Shape.prstGeomc                 C  s   t  S )N)r   new_p_txBodyrC   r$   r$   r%   _new_txBody  s   zCT_Shape._new_txBodyc                   C  s   dt ddddddddf S )Na  <p:sp %s>
  <p:nvSpPr>
    <p:cNvPr id="%s" name="%s"/>
    <p:cNvSpPr txBox="1"/>
    <p:nvPr/>
  </p:nvSpPr>
  <p:spPr>
    <a:xfrm>
      <a:off x="%s" y="%s"/>
      <a:ext cx="%s" cy="%s"/>
    </a:xfrm>
    <a:prstGeom prst="rect">
      <a:avLst/>
    </a:prstGeom>
    <a:noFill/>
  </p:spPr>
  <p:txBody>
    <a:bodyPr wrap="none">
      <a:spAutoFit/>
    </a:bodyPr>
    <a:lstStyle/>
    <a:p/>
  </p:txBody>
</p:sp>r|   r}   r~   r   r	   r$   r$   r$   r%   r     s   zCT_Shape._textbox_sp_tmplN)r?   r   r@   r   rA   r;   )rv   rw   r0   r1   r^   r1   rx   rw   ry   rw   rz   rw   r{   rw   rA   re   )r   rw   r0   r1   r   rw   r   rw   r   rw   r   rw   )
rv   rw   r0   r1   r   r   r   r1   rA   re   )rA   rZ   )r   r    r!   r"   r#   r   rh   ri   r   rj   rX   rm   rd   rn   rr   rs   ru   staticmethodr   r   r   r   r^   ro   r   r   r$   r$   r$   r%   re      s>   
 




-4'

re   c                   @  sB   e Zd ZU dZedZded< edZded< edZd	ed
< dS )rg   z `p:nvSpPr` custom element class.zp:cNvPrr   cNvPrz	p:cNvSpPrr8   rp   zp:nvPrr   r   N)	r   r    r!   r"   r   r   r#   rp   r   r$   r$   r$   r%   rg     s   
 rg   N)0r"   
__future__r   typingr   r   r   pptx.enum.shapesr   r   	pptx.oxmlr   pptx.oxml.nsr
   pptx.oxml.shapes.sharedr   pptx.oxml.simpletypesr   r   r   r   pptx.oxml.textr   pptx.oxml.xmlchemyr   r   r   r   r   r   r   r   r   	pptx.utilr   r   r&   r/   r3   r8   r;   rB   rF   rU   rY   rZ   re   rg   r$   r$   r$   r%   <module>   s6    	

	- |