
    l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$y)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		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"dZ
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d#dZd$dZd%dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d&dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 d'dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d(dZd)dZed        Zed        Zd*dZd Zd+dZed,d       Zed-d       Zd.dZed/d       Zed0d       Zed,d        Zy!)1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:contentPartc           	     `    t        j                  |||||||      }| j                  |d       |S )zLReturn new `p:sp` appended to the group/shapetree with specified attributes.p:extLst)r   new_autoshape_spinsert_element_before)	selfid_nameprstxycxcysps	            Y/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/pptx/oxml/shapes/groupshape.pyadd_autoshapezCT_GroupShape.add_autoshape+   s5     &&sD$1b"E""2z2	    c
                    t        j                  |      }
t        j                  |||
||||||		      }| 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$   type_memberr&   r'   r(   r)   flipHflipVr%   cxnSps               r+   	add_cxnSpzCT_GroupShape.add_cxnSp3   sI     "((5&&sD$1b"eUS""5*5r-   c                    | j                   }d|dz
  fz  }t        j                  ||||||      }| 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   sL    &&1.%%haBC""2z2	r-   c                    | j                   }d|dz
  fz  }t        j                  ||      }| j                  |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 %dr7   r   )r8   r   	new_grpSpr!   )r"   r:   r$   grpSps       r+   	add_grpSpzCT_GroupShape.add_grpSpM   sF     &&X\O+''$7""5*5r-   c	           
     b    t        j                  ||||||||      }	| 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$   descrIdr&   r'   r(   r)   pics
             r+   add_piczCT_GroupShape.add_picY   s7       dD#q!RD""3
3
r-   c                ^    t        j                  ||||||      }| j                  |d       |S )zPAppend a newly-created placeholder `p:sp` shape having the specified properties.r   )r   new_placeholder_spr!   )r"   r#   r$   ph_typeorientszidxr*   s           r+   add_placeholderzCT_GroupShape.add_placeholdera   s3     ((dGVRM""2z2	r-   c	           
     b    t        j                  ||||||||      }	| j                  |	d       |	S )zHAppend a `p:graphicFrame` shape containing a table as specified in call.r   )r   new_table_graphicFramer!   )
r"   r#   r$   rowscolsr&   r'   r(   r)   graphicFrames
             r+   	add_tablezCT_GroupShape.add_tablei   s=     /EEtT1aR
 	""<<r-   c                ^    t        j                  ||||||      }| 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   s1    $$S$1b"=""2z2	r-   c                R    | j                   j                         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         ||++->>@@r-   c                R    | j                   j                         j                         S )z.Descendent `p:grpSpPr/a:xfrm/a:chOff` element.)r   rW   get_or_add_chOffrY   s    r+   chOffzCT_GroupShape.chOff~   r[   r-   c                6    | j                   j                         S )zCReturn the `a:xfrm` grandchild element, newly-added if not present.)r   rW   rY   s    r+   rW   zCT_GroupShape.get_or_add_xfrm   s    ||++--r-   c              #  X   K   | j                         D ]  }|j                  s|  yw)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||	s    **c              #  p   K   | j                         D ]  }|j                  | j                  v s| ! yw)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+   ra   zCT_GroupShape.iter_shape_elms   s7     
 $$& 	Cww$***		s   ,66c                    | j                  d      }|D cg c]  }|j                         st        |        }}|rt        |      S dS c c}w )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".
        //@idr   )xpathisdigitintmax)r"   
id_str_lstid_strused_idss       r+   max_shape_idzCT_GroupShape.max_shape_id   sI     ZZ(
.8MFFNN<LCKMM (s8}/a/ Ns
   A
A
c                F    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$   xmlr>   s        r+   r=   zCT_GroupShape.new_grpSp   s:     #3S12 $K!" #r-   c                T   | j                   t        d      k(  sy| j                  \  }}}}|x| j                  _        | _        |x| j                  _        | _        |x| j                  _        | _        |x| j                  _        | _        | j                         j                          y)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)rg   r
   _child_extentsr^   r&   r'   rZ   r(   r)   	getparentrecalculate_extents)r"   r&   r'   r(   r)   s        r+   r}   z!CT_GroupShape.recalculate_extents   s     xx2i=(**1b" !!

tv !!

tv"$$

"$$

,,.r-   c                .    | j                   j                  S )z7The `a:xfrm` grandchild element or |None| if not found.)r   xfrmrY   s    r+   r   zCT_GroupShape.xfrm   s     ||   r-   c                (   t        | j                               }|s*t        d      t        d      t        d      t        d      fS t        |D cg c]  }|j                   c}      }t        |D cg c]  }|j
                   c}      }t        |D cg c]  }|j                  |j                  z    c}      }t        |D cg c]  }|j
                  |j                  z    c}      }|}|}||z
  }	||z
  }
|||	|
fS c c}w c c}w c c}w c c}w )z(x, y, cx, cy) tuple representing net position and size.

        The values are formed as a composite of the contained child shapes.
        r   )	listra   r   minr&   r'   ro   r(   r)   )r"   child_shape_elmsxSpmin_xmin_ymax_xmax_yr&   r'   r(   r)   s              r+   r{   zCT_GroupShape._child_extents   s       4 4 67q63q63q63q611&67sSUU78&67sSUU781AB#ceecffnBC1AB#ceecffnBCU]U]!R| 87BBs   D 2D D
 Dc                    | j                  d      }|D cg c]  }|j                         st        |        }}t        dt	        |      dz         D ]
  }||vs|c S  yc c}w )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".
        rk   r7      N)rl   rm   rn   rangelen)r"   rp   rq   rr   ns        r+   r8   zCT_GroupShape._next_shape_id   sd     ZZ(
.8MFFNN<LCKMMq#h-!+, 	A 	 Ns
   A!A!N)r#   rn   r$   strr%   r   r&   rn   r'   rn   r(   rn   r)   rn   returnr   )r#   rn   r$   r   r1   r   r&   rn   r'   rn   r(   rn   r)   rn   r2   boolr3   r   r   r   )
r&   rn   r'   rn   r(   rn   r)   rn   r   r   )r   r   )r#   rn   r$   r   rB   r   rC   r   r&   rn   r'   rn   r(   rn   r)   rn   r   r   )r#   rn   r$   r   rH   r   rI   r   rJ   r   rK   rn   r   r   )r#   rn   r$   r   rO   rn   rP   rn   r&   rn   r'   rn   r(   rn   r)   rn   r   r   )r#   rn   r$   r   r&   rn   r'   rn   r(   rn   r)   rn   r   r   )r   r   )r   zIterator[ShapeElement])r   rn   )r#   rn   r$   r   r   r   )r   None)r   CT_Transform2D | None)r   ztuple[int, int, int, int])__name__
__module____qualname____doc__r   r   __annotations__r   r
   rh   r,   r5   r;   r?   rE   rL   rR   rU   propertyrZ   r^   rW   rd   ra   rs   classmethodr=   r}   r   r{   r8    r-   r+   r   r      s   [(5)I%  (5(G$ 
 	6

9

9
7
?K!),149<BEKN	  (	
       
$
!),36;>CFLOUX	!,:DGMPWZ	!),47<?DGMPVY	  A A A A. 0 0  ,/( ! !  ,  r-   r   c                       e Zd ZdZ ed      Zy)r   z`p:nvGrpSpPr` element.zp:cNvPrN)r   r   r   r   r   cNvPrr   r-   r+   r   r      s     )$Er-   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[y)r   zp:grpSpPr elementzCallable[[], CT_Transform2D]rW   )a:xfrmza:noFillza:solidFillz
a:gradFillz
a:blipFillz
a:pattFillz	a:grpFilla:effectLstza:effectDagz	a:scene3dza:extLstr   r7   N)
successorsr   r   r      )	r   r   r   r   r   _tag_seqr   r   	effectLstr   r-   r+   r   r     sH    11H #,Xab\#D
  -HQRLAIr-   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   r   r-   r+   <module>r      sg    F " 4 4 /  $ / 3 = / 4 H H /-6a$ aH%- %o r-   