
    hi'                    *   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rddlmZ ddlm Z  ddlm!Z!  G d de          Z" G d de          Z# G 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                     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	dCdZ
dDd ZdEd!ZdFd"ZdGd&ZdHd,ZdId0ZdJd1Zed2             Zed3             ZdKd5Zd6 ZdLd8ZedMd9            ZedNd:            ZdOd<ZedPd>            ZedQd@            ZedMdA            ZdBS )R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           	     f    t          j        |||||||          }|                     |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&   sps	            s/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/pptx/oxml/shapes/groupshape.pyadd_autoshapezCT_GroupShape.add_autoshape+   s;     &sD$1b"EE""2z222	    type_memberr   flipHboolflipVr   c
                    t          j        |          }
t          j        |||
||||||		  	        }|                     |d           |S )zRReturn new `p:cxnSp` appended to the group/shapetree with the specified attribues.r)   )r   to_xmlr   	new_cxnSpr+   )r,   r   r    r1   r#   r$   r%   r&   r2   r4   r"   cxnSps               r.   	add_cxnSpzCT_GroupShape.add_cxnSp3   sO     "(55&sD$1b"eUSS""5*555r0   c                    | j         }d|dz
  fz  }t          j        ||||||          }|                     |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-   s           r.   add_freeform_spzCT_GroupShape.add_freeform_spE   sO    &1.%haBCC""2z222	r0   c                    | j         }d|dz
  fz  }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 %dr;   r)   )r<   r   	new_grpSpr+   )r,   r>   r    grpSps       r.   	add_grpSpzCT_GroupShape.add_grpSpM   sL     &X\O+''$77""5*555r0   descrIdr   c	           
     h    t          j        ||||||||          }	|                     |	d           |	S )zUAppend a `p:pic` shape to the group/shapetree having properties as specified in call.r)   )r   new_picr+   )
r,   r   r    rD   rE   r#   r$   r%   r&   pics
             r.   add_piczCT_GroupShape.add_picY   s=      dD#q!RDD""3
333
r0   ph_typer   orientszidxc                d    t          j        ||||||          }|                     |d           |S )zPAppend a newly-created placeholder `p:sp` shape having the specified properties.r)   )r   new_placeholder_spr+   )r,   r   r    rJ   rK   rL   rM   r-   s           r.   add_placeholderzCT_GroupShape.add_placeholdera   s9     (dGVRMM""2z222	r0   rowscolsr   c	           
     h    t          j        ||||||||          }	|                     |	d           |	S )zHAppend a `p:graphicFrame` shape containing a table as specified in call.r)   )r   new_table_graphicFramer+   )
r,   r   r    rQ   rR   r#   r$   r%   r&   graphicFrames
             r.   	add_tablezCT_GroupShape.add_tablei   sE     /EtT1aR
 
 	""<<<<r0   c                d    t          j        ||||||          }|                     |d           |S )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-   s           r.   add_textboxzCT_GroupShape.add_textboxs   s7    $S$1b"==""2z222	r0   c                X    | j                                                                         S )z.Descendent `p:grpSpPr/a:xfrm/a:chExt` element.)r   get_or_add_xfrmget_or_add_chExtr,   s    r.   chExtzCT_GroupShape.chExty   $     |++-->>@@@r0   c                X    | j                                                                         S )z.Descendent `p:grpSpPr/a:xfrm/a:chOff` element.)r   r[   get_or_add_chOffr]   s    r.   chOffzCT_GroupShape.chOff~   r_   r0   r   c                4    | j                                         S )zCReturn the `a:xfrm` grandchild element, newly-added if not present.)r   r[   r]   s    r.   r[   zCT_GroupShape.get_or_add_xfrm   s    |++---r0   c              #  N   K   |                                  D ]}|j        r|V  dS )z@Generate each placeholder shape child element in document order.N)iter_shape_elms
has_ph_elm)r,   es     r.   iter_ph_elmszCT_GroupShape.iter_ph_elms   s?      %%'' 	 	A| 	 	r0   Iterator[ShapeElement]c              #  \   K   |                                  D ]}|j        | j        v r|V  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,   elms     r.   re   zCT_GroupShape.iter_shape_elms   sG      
 $$&& 	 	Cw$***				 	r0   c                j    |                      d          }d |D             }|rt          |          n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                T    g | ]%}|                                 t          |          &S  isdigitr   .0id_strs     r.   
<listcomp>z.CT_GroupShape.max_shape_id.<locals>.<listcomp>   -    MMMFFNN<L<LMCKKMMMr0   r   )xpathmax)r,   
id_str_lstused_idss      r.   max_shape_idzCT_GroupShape.max_shape_id   s=     ZZ((
MMjMMM (/s8}}}a/r0   c                V    dt          ddd          z  ||fz  }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    xmlrB   s        r.   rA   zCT_GroupShape.new_grpSp   s?     #3S112 $K!" #r0   Nonec                6   | j         t          d          k    sdS | j        \  }}}}|x| j        _        | _        |x| j        _        | _        |x| j        _        | _        |x| 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)rl   r
   _child_extentsrb   r#   r$   r^   r%   r&   	getparentrecalculate_extents)r,   r#   r$   r%   r&   s        r.   r   z!CT_GroupShape.recalculate_extents   s     x2i==((F*1b" !!
tv !!
tv"$$
"$$
,,.....r0   CT_Transform2D | Nonec                    | j         j        S )z7The `a:xfrm` grandchild element or |None| if not found.)r   xfrmr]   s    r.   r   zCT_GroupShape.xfrm   s     |  r0   tuple[int, int, int, int]c                   t          |                                           }|s:t          d          t          d          t          d          t          d          fS t          d |D                       }t          d |D                       }t	          d |D                       }t	          d |D                       }|}|}||z
  }||z
  }	||||	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                    g | ]	}|j         
S rr   )r#   rv   xSps     r.   rx   z0CT_GroupShape._child_extents.<locals>.<listcomp>       777sSU777r0   c                    g | ]	}|j         
S rr   )r$   r   s     r.   rx   z0CT_GroupShape._child_extents.<locals>.<listcomp>   r   r0   c                ,    g | ]}|j         |j        z   S rr   )r#   r%   r   s     r.   rx   z0CT_GroupShape._child_extents.<locals>.<listcomp>        BBB#cecfnBBBr0   c                ,    g | ]}|j         |j        z   S rr   )r$   r&   r   s     r.   rx   z0CT_GroupShape._child_extents.<locals>.<listcomp>   r   r0   )listre   r   minr{   )
r,   child_shape_elmsmin_xmin_ymax_xmax_yr#   r$   r%   r&   s
             r.   r   zCT_GroupShape._child_extents   s       4 4 6 677 	2q663q663q663q661177&67778877&677788BB1ABBBCCBB1ABBBCCU]U]!R|r0   c                    |                      d          }d |D             }t          dt          |          dz             D ]
}||vr|c S 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".
        rp   c                T    g | ]%}|                                 t          |          &S rr   rs   ru   s     r.   rx   z0CT_GroupShape._next_shape_id.<locals>.<listcomp>   ry   r0   r;      N)rz   rangelen)r,   r|   r}   ns       r.   r<   zCT_GroupShape._next_shape_id   so     ZZ((
MMjMMMq#h--!+,, 	 	A   !	 	r0   N)r   r   r    r!   r"   r!   r#   r   r$   r   r%   r   r&   r   r'   r   )r   r   r    r!   r1   r   r#   r   r$   r   r%   r   r&   r   r2   r3   r4   r3   r'   r   )
r#   r   r$   r   r%   r   r&   r   r'   r   )r'   r   )r   r   r    r!   rD   r!   rE   r!   r#   r   r$   r   r%   r   r&   r   r'   r   )r   r   r    r!   rJ   r   rK   r!   rL   r!   rM   r   r'   r   )r   r   r    r!   rQ   r   rR   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'   ri   )r'   r   )r   r   r    r!   r'   r   )r'   r   )r'   r   )r'   r   )__name__
__module____qualname____doc__r   r   __annotations__r   r
   rm   r/   r9   r?   rC   rI   rP   rV   rY   propertyr^   rb   r[   rh   re   r~   classmethodrA   r   r   r   r<   rr   r0   r.   r   r      s        [[(5) )I     (5}( (G    
 	6


9

9
7
?K      $   
 
 
 
             A A XA A A XA. . . .      0 0 0 X0    [,/ / / /( ! ! ! X!    X,    X  r0   r   c                  (    e Zd ZdZ ed          ZdS )r   z`p:nvGrpSpPr` element.zp:cNvPrN)r   r   r   r   r   cNvPrrr   r0   r.   r   r      s#          M)$$EEEr0   r   c                      e Zd ZU dZded<   dZ ededd                   Zd	ed
<    ededd                   Z[dS )r   zp:grpSpPr elementzCallable[[], CT_Transform2D]r[   )a:xfrmza:noFillza:solidFillz
a:gradFillz
a:blipFillz
a:pattFillz	a:grpFilla:effectLstza:effectDagz	a:scene3dza:extLstr   r;   N)
successorsr   r   r      )	r   r   r   r   r   _tag_seqr   r   	effectLstrr   r0   r.   r   r     s         1111H #,)Xabb\# # #D     	-HQRRLAAAIr0   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   pptx.oxml.shapesr   r   r   r   r   rr   r0   r.   <module>r      s   F F " " " " " " 4 4 4 4 4 4 4 4 4 4 / / / / / /       $ $ $ $ $ $ $ $ / / / / / / 3 3 3 3 3 3 = = = = = = / / / / / / 4 4 4 4 4 4 H H H H H H H H H H       7//////------666666a a a a a$ a a aH% % % % %- % % %    o     r0   