o
    7 h'                     @  s  d Z ddlmZ ddlmZmZmZ ddlmZ ddl	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 ddlmZ ddlmZmZmZ ddlmZ erhddlmZ ddl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$dS )z@lxml custom element classes for shape-tree-related XML elements.    )annotations)TYPE_CHECKINGCallableIterator)MSO_CONNECTOR_TYPE)	parse_xml)nsdeclsqn)CT_Shape)CT_Connector)CT_GraphicalObjectFrame)
CT_Picture)BaseShapeElement)BaseOxmlElementOneAndOnlyOne	ZeroOrOne)Emu)PP_PLACEHOLDER)ShapeElement)CT_Transform2Dc                   @  s.  e Zd ZU dZedZded< edZded< eded	ed
edededfZ	dVddZ
dWd!d"ZdXd#d$ZdYd%d&ZdZd*d+Zd[d1d2Zd\d6d7Zd]d8d9Zed:d; Zed<d= Zd^d?d@ZdAdB Zd_dDdEZed`dFdGZedadHdIZdbdKdLZedcdNdOZedddQdRZed`dSdTZdUS )eCT_GroupShapezQUsed for shape tree (`p:spTree`) as well as the group shape (`p:grpSp`) elements.zp:nvGrpSpPrCT_GroupShapeNonVisual	nvGrpSpPrz	p:grpSpPrCT_GroupShapePropertiesgrpSpPrzp:spp:grpSpzp:graphicFramezp:cxnSpzp:piczp:contentPartid_intnamestrprstxycxcyreturnr
   c           	   	   C  s&   t |||||||}| |d |S )zLReturn new `p:sp` appended to the group/shapetree with specified attributes.p:extLst)r
   new_autoshape_spinsert_element_before)	selfr   r   r    r!   r"   r#   r$   sp r+   c/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/pptx/oxml/shapes/groupshape.pyadd_autoshape+   s   zCT_GroupShape.add_autoshapetype_memberr   flipHboolflipVr   c
                 C  s4   t |}
t|||
||||||		}| |d |S )zRReturn new `p:cxnSp` appended to the group/shapetree with the specified attribues.r&   )r   to_xmlr   	new_cxnSpr(   )r)   r   r   r.   r!   r"   r#   r$   r/   r1   r    ZcxnSpr+   r+   r,   	add_cxnSp3   s   
zCT_GroupShape.add_cxnSpc                 C  s8   | j }d|d f }t||||||}| |d |S )z>Append a new freeform `p:sp` with specified position and size.zFreeform %d   r&   )_next_shape_idr
   new_freeform_spr(   )r)   r!   r"   r#   r$   shape_idr   r*   r+   r+   r,   add_freeform_spE   s
   zCT_GroupShape.add_freeform_spc                 C  s0   | j }d|d f }t||}| |d |S )zReturn `p:grpSp` element newly appended to this shape tree.

        The element contains no sub-shapes, is positioned at (0, 0), and has
        width and height of zero.
        zGroup %dr5   r&   )r6   r   	new_grpSpr(   )r)   r8   r   grpSpr+   r+   r,   	add_grpSpM   s
   zCT_GroupShape.add_grpSpdescrIdr   c	           
   
   C  (   t ||||||||}	| |	d |	S )zUAppend a `p:pic` shape to the group/shapetree having properties as specified in call.r&   )r   Znew_picr(   )
r)   r   r   r=   r>   r!   r"   r#   r$   picr+   r+   r,   add_picY   s   zCT_GroupShape.add_picph_typer   orientszidxc                 C  $   t ||||||}| |d |S )zPAppend a newly-created placeholder `p:sp` shape having the specified properties.r&   )r
   new_placeholder_spr(   )r)   r   r   rB   rC   rD   rE   r*   r+   r+   r,   add_placeholdera   s   zCT_GroupShape.add_placeholderrowscolsr   c	           
   
   C  r?   )zHAppend a `p:graphicFrame` shape containing a table as specified in call.r&   )r   new_table_graphicFramer(   )
r)   r   r   rI   rJ   r!   r"   r#   r$   graphicFramer+   r+   r,   	add_tablei   s
   zCT_GroupShape.add_tablec                 C  rF   )zSAppend a newly-created textbox `p:sp` shape having the specified position and size.r&   )r
   new_textbox_spr(   )r)   r   r   r!   r"   r#   r$   r*   r+   r+   r,   add_textboxs   s   zCT_GroupShape.add_textboxc                 C     | j   S )z.Descendent `p:grpSpPr/a:xfrm/a:chExt` element.)r   get_or_add_xfrmget_or_add_chExtr)   r+   r+   r,   chExty      zCT_GroupShape.chExtc                 C  rP   )z.Descendent `p:grpSpPr/a:xfrm/a:chOff` element.)r   rQ   get_or_add_chOffrS   r+   r+   r,   chOff~   rU   zCT_GroupShape.chOffr   c                 C  s
   | j  S )zCReturn the `a:xfrm` grandchild element, newly-added if not present.)r   rQ   rS   r+   r+   r,   rQ      s   
zCT_GroupShape.get_or_add_xfrmc                 c  s     |   D ]}|jr|V  qdS )z@Generate each placeholder shape child element in document order.N)iter_shape_elms
has_ph_elm)r)   er+   r+   r,   iter_ph_elms   s   zCT_GroupShape.iter_ph_elmsIterator[ShapeElement]c                 c  s&    |   D ]}|j| jv r|V  qdS )zGenerate each child of this `p:spTree` element that corresponds to a shape.

        Items appear in XML document order.
        N)iterchildrentag_shape_tags)r)   elmr+   r+   r,   rX      s   zCT_GroupShape.iter_shape_elmsc                 C  s(   |  d}dd |D }|rt|S dS )ai  Maximum int value assigned as @id in this slide.

        This is generally a shape-id, but ids can be assigned to other
        objects so we just check all @id values anywhere in the document
        (XML id-values have document scope).

        In practice, its minimum value is 1 because the spTree element itself
        is always assigned id="1".
        //@idc                 S     g | ]
}|  rt|qS r+   isdigitr   .0Zid_strr+   r+   r,   
<listcomp>       z.CT_GroupShape.max_shape_id.<locals>.<listcomp>r   )xpathmax)r)   
id_str_lstused_idsr+   r+   r,   max_shape_id   s   
zCT_GroupShape.max_shape_idc                 C  s$   dt ddd ||f }t|}|S )z=Return new "loose" `p:grpSp` element having `id_` and `name`.a)  <p:grpSp %s>
  <p:nvGrpSpPr>
    <p:cNvPr id="%%d" name="%%s"/>
    <p:cNvGrpSpPr/>
    <p:nvPr/>
  </p:nvGrpSpPr>
  <p:grpSpPr>
    <a:xfrm>
      <a:off x="0" y="0"/>
      <a:ext cx="0" cy="0"/>
      <a:chOff x="0" y="0"/>
      <a:chExt cx="0" cy="0"/>
    </a:xfrm>
  </p:grpSpPr>
</p:grpSp>apr)r   r   )clsr   r   xmlr;   r+   r+   r,   r:      s   
zCT_GroupShape.new_grpSpNonec                 C  sh   | j tdks	dS | j\}}}}| | j_| _| | j_| _| | j_| _| | j_| _| 	 
  dS )aN  Adjust x, y, cx, and cy to incorporate all contained shapes.

        This would typically be called when a contained shape is added,
        removed, or its position or size updated.

        This method is recursive "upwards" since a change in a group shape
        can change the position and size of its containing group.
        r   N)r^   r	   _child_extentsrW   r!   r"   rT   r#   r$   	getparentrecalculate_extents)r)   r!   r"   r#   r$   r+   r+   r,   rv      s   	z!CT_GroupShape.recalculate_extentsCT_Transform2D | Nonec                 C  s   | j jS )z7The `a:xfrm` grandchild element or |None| if not found.)r   xfrmrS   r+   r+   r,   rx      s   zCT_GroupShape.xfrmtuple[int, int, int, int]c           
      C  s   t |  }|stdtdtdtdfS tdd |D }tdd |D }tdd |D }tdd |D }|}|}|| }|| }	||||	fS )z(x, y, cx, cy) tuple representing net position and size.

        The values are formed as a composite of the contained child shapes.
        r   c                 S     g | ]}|j qS r+   )r!   rf   ZxSpr+   r+   r,   rg          z0CT_GroupShape._child_extents.<locals>.<listcomp>c                 S  rz   r+   )r"   r{   r+   r+   r,   rg      r|   c                 S     g | ]}|j |j qS r+   )r!   r#   r{   r+   r+   r,   rg          c                 S  r}   r+   )r"   r$   r{   r+   r+   r,   rg      r~   )listrX   r   minrj   )
r)   Zchild_shape_elmsZmin_xZmin_yZmax_xZmax_yr!   r"   r#   r$   r+   r+   r,   rt      s   zCT_GroupShape._child_extentsc                 C  sD   |  d}dd |D }tdt|d D ]
}||vr|  S qdS )aZ  Return unique shape id suitable for use with a new shape element.

        The returned id is the next available positive integer drawing object
        id in shape tree, starting from 1 and making use of any gaps in
        numbering. In practice, the minimum id is 2 because the spTree
        element itself is always assigned id="1".
        ra   c                 S  rb   r+   rc   re   r+   r+   r,   rg      rh   z0CT_GroupShape._next_shape_id.<locals>.<listcomp>r5      N)ri   rangelen)r)   rk   rl   nr+   r+   r,   r6      s   
	zCT_GroupShape._next_shape_idN)r   r   r   r   r    r   r!   r   r"   r   r#   r   r$   r   r%   r
   )r   r   r   r   r.   r   r!   r   r"   r   r#   r   r$   r   r/   r0   r1   r0   r%   r   )
r!   r   r"   r   r#   r   r$   r   r%   r
   )r%   r   )r   r   r   r   r=   r   r>   r   r!   r   r"   r   r#   r   r$   r   r%   r   )r   r   r   r   rB   r   rC   r   rD   r   rE   r   r%   r
   )r   r   r   r   rI   r   rJ   r   r!   r   r"   r   r#   r   r$   r   r%   r   )r   r   r   r   r!   r   r"   r   r#   r   r$   r   r%   r
   )r%   r   )r%   r\   )r%   r   )r   r   r   r   r%   r   )r%   rs   )r%   rw   )r%   ry   )__name__
__module____qualname____doc__r   r   __annotations__r   r	   r_   r-   r4   r9   r<   rA   rH   rM   rO   propertyrT   rW   rQ   r[   rX   rm   classmethodr:   rv   rx   rt   r6   r+   r+   r+   r,   r      sR   
 
	











	
r   c                   @  s   e Zd ZdZedZdS )r   z`p:nvGrpSpPr` element.zp:cNvPrN)r   r   r   r   r   cNvPrr+   r+   r+   r,   r      s    r   c                   @  sP   e Zd ZU dZded< dZededd dZd	ed
< ededd dZ[dS )r   zp:grpSpPr elementzCallable[[], CT_Transform2D]rQ   )a:xfrmza:noFillza:solidFillz
a:gradFillz
a:blipFillz
a:pattFillz	a:grpFilla:effectLstza:effectDagz	a:scene3dza:extLstr   r5   N)
successorsrw   rx   r      )	r   r   r   r   r   _tag_seqr   rx   	effectLstr+   r+   r+   r,   r     s   
 r   N)%r   
__future__r   typingr   r   r   pptx.enum.shapesr   	pptx.oxmlr   pptx.oxml.nsr   r	   pptx.oxml.shapes.autoshaper
   pptx.oxml.shapes.connectorr   pptx.oxml.shapes.graphfrmr   pptx.oxml.shapes.picturer   pptx.oxml.shapes.sharedr   pptx.oxml.xmlchemyr   r   r   	pptx.utilr   r   Zpptx.oxml.shapesr   r   r   r   r   r+   r+   r+   r,   <module>   s*     e