o
    7 hN                     @  sH  d 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 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mZmZ ddl m!Z!m"Z" erbd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,dS )z5Custom element classes for table-related XML elements    )annotations)TYPE_CHECKINGCallableIteratorcast)MSO_VERTICAL_ANCHOR)	parse_xml)CT_GradientFillPropertiesnsdecls)ST_CoordinateST_Coordinate32
XsdBooleanXsdInt)CT_TextBody)BaseOxmlElementChoiceOneAndOnlyOneOptionalAttributeRequiredAttribute
ZeroOrMore	ZeroOrOneZeroOrOneChoice)Emulazyproperty)Lengthc                   @  st  e Zd ZU dZded< ded< ded< dZed	ed
d dZded< edZ	ded< e
dedd dZ[dGddZedHddZejdIddZedHdd ZejdId!d ZedHd"d#ZejdId$d#ZedHd%d&ZejdId'd&ZdJd)d*ZedHd+d,ZejdId-d,ZedHd.d/ZejdId0d/Ze	dKdLd7d8ZdMd<d=ZdNd@dAZdOdCdDZedEdF ZdS )PCT_Tablez`a:tbl` custom element classz Callable[[], CT_TableProperties]get_or_add_tblPrzlist[CT_TableRow]tr_lstzCallable[..., CT_TableRow]_add_tr)a:tblPr	a:tblGrida:trr       N
successorszCT_TableProperties | NonetblPrr!   CT_TableGridtblGridr"      heightr   returnCT_TableRowc                 C     | j |dS )zUReturn a newly created `a:tr` child element having its `h` attribute set to `height`.)h)r   )selfr*    r0   W/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/pptx/oxml/table.pyadd_tr,      zCT_Table.add_trboolc                 C  
   |  dS NbandCol_get_boolean_propertyr/   r0   r0   r1   r7   0      
zCT_Table.bandColvaluec                 C     |  d| d S r6   _set_boolean_propertyr/   r<   r0   r0   r1   r7   4      c                 C  r5   NbandRowr8   r:   r0   r0   r1   rC   8   r;   zCT_Table.bandRowc                 C  r=   rB   r>   r@   r0   r0   r1   rC   <   rA   c                 C  r5   NfirstColr8   r:   r0   r0   r1   rE   @   r;   zCT_Table.firstColc                 C  r=   rD   r>   r@   r0   r0   r1   rE   D   rA   c                 C  r5   NfirstRowr8   r:   r0   r0   r1   rG   H   r;   zCT_Table.firstRowc                 C  r=   rF   r>   r@   r0   r0   r1   rG   L   rA   Iterator[CT_TableCell]c                 C  s   dd | j D S )zwGenerate each `a:tc` element in this tbl.

        `a:tc` elements are generated left-to-right, top-to-bottom.
        c                 s  s     | ]}|j D ]}|V  qqd S N)tc_lst.0trtcr0   r0   r1   	<genexpr>U   s    z$CT_Table.iter_tcs.<locals>.<genexpr>)r   r:   r0   r0   r1   iter_tcsP   s   zCT_Table.iter_tcsc                 C  r5   NlastColr8   r:   r0   r0   r1   rR   W   r;   zCT_Table.lastColc                 C  r=   rQ   r>   r@   r0   r0   r1   rR   [   rA   c                 C  r5   NlastRowr8   r:   r0   r0   r1   rT   _   r;   zCT_Table.lastRowc                 C  r=   rS   r>   r@   r0   r0   r1   rT   c   rA   rowsintcolswidthtableStyleId
str | Nonec                 C  s   |du rd}|   | }ttt|}|| }|| }	t|D ]}
|
|d kr/||d |	  }	|jjt|	d qt|D ]#}||d krM||d |  }|jt|d}t|D ]}
|	  qYq=|S )z"Return a new `p:tbl` element tree.Nz&{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}r#   )rX   )r*   )
	_tbl_tmplr   r   r   ranger(   add_gridColr   r2   add_tc)clsrU   rW   rX   r*   rY   xmltblZ	rowheightcolwidthcolrowrM   r0   r0   r1   new_tblg   s$   
zCT_Table.new_tblrow_idxcol_idxCT_TableCellc                 C  s   | j | j| S )z.Return `a:tc` element at `row_idx`, `col_idx`.)r   rJ   )r/   rf   rg   r0   r0   r1   rN      rA   zCT_Table.tcpropnamestrc                 C  s,   | j }|du r	dS t||}dddd| S )zGeneralized getter for the boolean properties on the `a:tblPr` child element.

        Defaults to False if `propname` attribute is missing or `a:tblPr` element itself is not
        present.
        NFT)TFN)r&   getattr)r/   ri   r&   Zpropvalr0   r0   r1   r9      s
   
zCT_Table._get_boolean_propertyNonec                 C  s,   |dvr
t d| |  }t||| dS )a  Generalized setter for boolean properties on the `a:tblPr` child element.

        Sets `propname` attribute appropriately based on `value`. If `value` is True, the
        attribute is set to "1"; a tblPr child element is added if necessary. If `value` is False,
        the `propname` attribute is removed if present, allowing its default value of False to be
        its effective value.
        )TFz3assigned value must be either True or False, got %sN)
ValueErrorr   setattr)r/   ri   r<   r&   r0   r0   r1   r?      s   zCT_Table._set_boolean_propertyc                 C  s   dt ddf S )Nz|<a:tbl %s>
  <a:tblPr firstRow="1" bandRow="1">
    <a:tableStyleId>%s</a:tableStyleId>
  </a:tblPr>
  <a:tblGrid/>
</a:tbl>az%sr
   r_   r0   r0   r1   r[      s   
zCT_Table._tbl_tmpl)r*   r   r+   r,   r+   r4   )r<   r4   )r+   rH   rI   )rU   rV   rW   rV   rX   rV   r*   rV   rY   rZ   r+   r   )rf   rV   rg   rV   r+   rh   )ri   rj   r+   r4   )ri   rj   r<   r4   r+   rl   )__name__
__module____qualname____doc____annotations___tag_seqr   r&   r   r(   r   rM   r2   propertyr7   setterrC   rE   rG   rP   rR   rT   classmethodre   rN   r9   r?   r[   r0   r0   r0   r1   r      s\   
 




r   c                   @  s  e Zd ZU dZded< ded< dZededd	 d
Zded< ededd	 d
Zded< [e	de
ddZded< e	de
ddZded< e	deddZded< e	deddZded< edLddZejdMddZdNd d!ZedOd"d#ZedPd$d%ZedPd&d'ZedQd)d*ZejdRd-d*ZedQd.d/ZejdRd0d/ZedQd1d2ZejdRd3d2ZedQd4d5ZejdRd6d5ZedSd7d8ZedOd9d:ZedTd<d=ZedUd?d@ZdVdCdDZ dWdFdGZ!dXdJdKZ"d	S )Yrh   z`a:tc` custom element classz$Callable[[], CT_TableCellProperties]get_or_add_tcPrzCallable[[], CT_TextBody]get_or_add_txBody)a:txBodya:tcPra:extLstr}   r#   Nr$   zCT_TextBody | NonetxBodyr~      zCT_TableCellProperties | NonetcPrgridSpandefaultrV   rowSpanhMergeFr4   vMerger+   MSO_VERTICAL_ANCHOR | Nonec                 C  s   | j du rdS | j jS )zSString held in `anchor` attribute of `a:tcPr` child element of this `a:tc` element.N)r   anchorr:   r0   r0   r1   r      s   
zCT_TableCell.anchoranchor_enum_idxc                 C  s(   |du r| j du rdS |  }||_dS )z8Set value of anchor attribute on `a:tcPr` child element.N)r   r{   r   )r/   r   r   r0   r0   r1   r      s   

spanned_tcc                 C  sR   |  }|   }|jrdS |jr|  |jD ]}|| q|  |  dS )aK  Append `a:p` elements taken from `spanned_tc`.

        Any non-empty paragraph elements in `spanned_tc` are removed and appended to the
        text-frame of this cell. If `spanned_tc` is left with no content after this process, a
        single empty `a:p` element is added to ensure the cell is compliant with the spec.
        N)r|   is_emptyclear_contentp_lstappendunclear_content)r/   r   Zsource_txBodyZtarget_txBodypr0   r0   r1   append_ps_from   s   
zCT_TableCell.append_ps_fromc                 C  s   t t|  | S )z*Offset of this cell's column in its table.)r   r,   	getparentindexr:   r0   r0   r1   rg      s   zCT_TableCell.col_idxc                 C  s&   | j dkr
| js
dS | jdko| j S )z.True if cell is top-left in merged cell range.r#   T)r   r   r   r   r:   r0   r0   r1   is_merge_origin   s   zCT_TableCell.is_merge_originc                 C  s   | j p| jS )z?True if cell is in merged cell range but not merge origin cell.)r   r   r:   r0   r0   r1   
is_spanned  s   zCT_TableCell.is_spannedr   c                 C     |  dtdS )a  Top margin for this cell.

        This value is stored in the `marT` attribute of the `a:tcPr` child element of this `a:tc`.

        Read/write. If the attribute is not present, the default value `45720` (0.05 inches) is
        returned for top and bottom; `91440` (0.10 inches) is the default for left and right.
        Assigning |None| to any `marX` property clears that attribute from the element,
        effectively setting it to the default value.
        marT防  	_get_marXr   r:   r0   r0   r1   r     s   zCT_TableCell.marTr<   Length | Nonec                 C  r=   )Nr   	_set_marXr@   r0   r0   r1   r     rA   c                 C  r   )z3Right margin value represented in `marR` attribute.marR0e r   r:   r0   r0   r1   r        zCT_TableCell.marRc                 C  r=   )Nr   r   r@   r0   r0   r1   r     rA   c                 C  r   )z4Bottom margin value represented in `marB` attribute.marBr   r   r:   r0   r0   r1   r      r   zCT_TableCell.marBc                 C  r=   )Nr   r   r@   r0   r0   r1   r   %  rA   c                 C  r   )z2Left margin value represented in `marL` attribute.marLr   r   r:   r0   r0   r1   r   )  r   zCT_TableCell.marLc                 C  r=   )Nr   r   r@   r0   r0   r1   r   .  rA   c                 C  s   t ttdtd dS )z$Return a new `a:tc` element subtree.z<a:tc ro   z]>
  <a:txBody>
    <a:bodyPr/>
    <a:lstStyle/>
    <a:p/>
  </a:txBody>
  <a:tcPr/>
</a:tc>)r   rh   r   r   rp   r0   r0   r1   new2  s   zCT_TableCell.newc                 C  s   t t|  jS )z'Offset of this cell's row in its table.)r   r,   r   rf   r:   r0   r0   r1   rf   C  r   zCT_TableCell.row_idxr   c                 C  s   t t| dd S )z#Table element this cell belongs to.zancestor::a:tblr   )r   r   xpathr:   r0   r0   r1   ra   H  s   zCT_TableCell.tblrj   c                 C  s(   | j }|du r	dS ddd |jD S )zstr text contained in cellN 
c                 S  s   g | ]}|j qS r0   )text)rL   r   r0   r0   r1   
<listcomp>T  s    z%CT_TableCell.text.<locals>.<listcomp>)r   joinr   )r/   r   r0   r0   r1   r   M  s   zCT_TableCell.text	attr_namer   c                 C  s(   | j du r	t|S tt| j ||S )z(Generalized method to get margin values.N)r   r   rV   get)r/   r   r   r0   r0   r1   r   V  s   
zCT_TableCell._get_marXr   c                 C     t  S rI   )r   new_a_txBodyr:   r0   r0   r1   _new_txBody\     zCT_TableCell._new_txBodymarXrl   c                 C  s.   |du r| j du rdS |  }t||| dS )zSet value of marX attribute on `a:tcPr` child element.

        If `marX` is |None|, the marX attribute is removed. `marX` is a string, one of `('marL',
        'marR', 'marT', 'marB')`.
        N)r   r{   rn   )r/   r   r<   r   r0   r0   r1   r   _  s   zCT_TableCell._set_marX)r+   r   )r   r   )r   rh   r+   rV   rq   )r+   r   )r<   r   r+   rh   )r+   r   )r+   rj   )r   rj   r   r   r+   r   )r+   r   )r   rj   r<   r   r+   rl   )#rr   rs   rt   ru   rv   rw   r   r   r   r   r   r   r   r   r   r   rx   r   ry   r   rg   r   r   r   r   r   r   rz   r   rf   ra   r   r   r   r   r0   r0   r0   r1   rh      s|   
 


rh   c                   @  s   e Zd ZU dZeededededededfdd	Zed
eZ	de
d
< edeZde
d< edeZde
d< edeZde
d< edeZde
d< dd ZdS )CT_TableCellPropertiesz`a:tcPr` custom element classza:noFillza:solidFillz
a:gradFillz
a:blipFillz
a:pattFillz	a:grpFill)z	a:headersr   r$   r   r   r   r   r   r   r   c                 C  r   rI   )r	   new_gradFillr:   r0   r0   r1   _new_gradFill  r   z$CT_TableCellProperties._new_gradFillN)rr   rs   rt   ru   r   r   eg_fillPropertiesr   r   r   rv   r   r   r   r   r   r   r0   r0   r0   r1   r   k  s8   
 r   c                   @  s$   e Zd ZU dZedeZded< dS )CT_TableColz!`a:gridCol` custom element class.wr   N)rr   rs   rt   ru   r   r   r   rv   r0   r0   r0   r1   r     s   
 r   c                   @  s4   e Zd ZU dZded< ded< edZdddZdS )r'   z!`a:tblGrid` custom element class.zlist[CT_TableCol]ZgridCol_lstzCallable[..., CT_TableCol]_add_gridColz	a:gridColrX   r   r+   r   c                 C  r-   )zSA newly appended `a:gridCol` child element having its `w` attribute set to `width`.)r   )r   )r/   rX   r0   r0   r1   r]     r3   zCT_TableGrid.add_gridColN)rX   r   r+   r   )rr   rs   rt   ru   rv   r   ZgridColr]   r0   r0   r0   r1   r'     s   
 r'   c                   @  sd   e Zd ZdZededdZededdZededdZededdZ	ededdZ
ed	eddZd
S )CT_TablePropertiesz`a:tblPr` custom element class.rC   Fr   r7   rG   rE   rT   rR   N)rr   rs   rt   ru   r   r   rC   r7   rG   rE   rT   rR   r0   r0   r0   r1   r     s    r   c                   @  s`   e Zd ZU dZded< ded< edddZed	eZ	d
ed	< dddZ
edddZdd ZdS )r,   z`a:tr` custom element class.zlist[CT_TableCell]rJ   zCallable[[], CT_TableCell]_add_tcza:tc)r   r$   r.   r   r+   rh   c                 C  s   |   S )z1A newly added minimal valid `a:tc` child element.)r   r:   r0   r0   r1   r^     s   zCT_TableRow.add_tcrV   c                 C  s   t t|  j| S )z Offset of this row in its table.)r   r   r   r   r   r:   r0   r0   r1   rf     s   zCT_TableRow.row_idxc                 C  r   rI   )rh   r   r:   r0   r0   r1   _new_tc  r   zCT_TableRow._new_tcNr   r   )rr   rs   rt   ru   rv   r   rN   r   r   r.   r^   rx   rf   r   r0   r0   r0   r1   r,     s   
 
r,   c                   @  s   e Zd ZdZd,ddZed-ddZed.ddZed/ddZ	edd Z
dd Zdd Zdd Zdd Zdd Zdd Zedd Zed0d!d"Zed#d$ Zed%d& Zed'd( Zed)d* Zd+S )1TcRangea  A 2D block of `a:tc` cell elements in a table.

    This object assumes the structure of the underlying table does not change during its lifetime.
    Structural changes in this context would be insertion or removal of rows or columns.

    The client is expected to create, use, and then abandon an instance in the context of a single
    user operation that is known to have no structural side-effects of this type.
    rN   rh   other_tcc                 C  s   || _ || _d S rI   )_tc	_other_tc)r/   rN   r   r0   r0   r1   __init__  s   
zTcRange.__init__c                 C  s0   |j |j|j d |j|j d }| ||S )z5Return instance created from merge-origin tc element.r#   )ra   rN   rf   r   rg   r   )r_   rN   r   r0   r0   r1   from_merge_origin  s
   
zTcRange.from_merge_originr+   r4   c                 C  sJ   |   D ]}|jdkr dS |jdkr dS |jr dS |jr" dS qdS )z=True if one or more cells in range are part of a merged cell.r#   TF)rP   r   r   r   r   )r/   rN   r0   r0   r1   contains_merged_cell  s   

zTcRange.contains_merged_celltuple[int, int]c                 C  s   | j \}}}}||fS )z5(row_count, col_count) pair describing size of range._extents)r/   _rX   r*   r0   r0   r1   
dimensions     zTcRange.dimensionsc                 C  s   | j j| jju r
dS dS )z=True if both cells provided to constructor are in same table.TF)r   ra   r   r:   r0   r0   r1   in_same_table  s   zTcRange.in_same_tablec                 c  sB    | j j| j| j D ]}|j| jd | j D ]}|V  qqdS )z=Generate each `a:tc` element not in leftmost column of range.r#   N_tblr   _top_bottomrJ   _left_rightr/   rM   rN   r0   r0   r1   iter_except_left_col_tcs  s   z TcRange.iter_except_left_col_tcsc                 c  sB    | j j| jd | j D ]}|j| j| j D ]}|V  qqdS )z8Generate each `a:tc` element in non-first rows of range.r#   Nr   r   r0   r0   r1   iter_except_top_row_tcs  s   zTcRange.iter_except_top_row_tcsc                 c  s2    | j }| jj| j| j D ]}|j| V  qdS )z9Generate each `a:tc` element in leftmost column of range.N)r   r   r   r   r   rJ   )r/   rg   rM   r0   r0   r1   iter_left_col_tcs  s
   zTcRange.iter_left_col_tcsc                   s"    fdd j j j j D S )zwGenerate each `a:tc` element in this range.

        Cell elements are generated left-to-right, top-to-bottom.
        c                 3  s,    | ]}|j  j j D ]}|V  qqd S rI   )rJ   r   r   rK   r:   r0   r1   rO   
  s    z#TcRange.iter_tcs.<locals>.<genexpr>)r   r   r   r   r:   r0   r:   r1   rP     s   
zTcRange.iter_tcsc                 c  s2    | j j| j }|j| j| j D ]}|V  qdS )z5Generate each `a:tc` element in topmost row of range.N)r   r   r   rJ   r   r   r   r0   r0   r1   iter_top_row_tcs  s
   zTcRange.iter_top_row_tcsc                 C  s4   t |  }|d }|dd D ]}|| qdS )z,Move all paragraphs in range to origin cell.r   r#   N)listrP   r   )r/   ZtcsZ	origin_tcr   r0   r0   r1   move_content_to_origin  s
   zTcRange.move_content_to_originc                 C  s   | j \}}}}|| S )z(Index of row following last row of ranger   )r/   r   topr*   r0   r0   r1   r     r   zTcRange._bottomtuple[int, int, int, int]c                 C  sH   d	dd}| j | j}}||j|j\}}||j|j\}}||||fS )
a5  A (left, top, width, height) tuple describing range extents.

        Note this is normalized to accommodate the various orderings of the corner cells provided
        on construction, which may be in any of four configurations such as (top-left,
        bottom-right), (bottom-left, top-right), etc.
        idxrV   	other_idxr+   r   c                 S  s   t | |t| | d fS )z:Return beginning and length of range based on two indexes.r#   )minabs)r   r   r0   r0   r1   start_and_size,  s   z(TcRange._extents.<locals>.start_and_sizeN)r   rV   r   rV   r+   r   )r   r   rg   rf   )r/   r   rN   r   leftrX   r   r*   r0   r0   r1   r   #  s
   
	zTcRange._extentsc                 C  s   | j \}}}}|S )z"Index of leftmost column in range.r   )r/   r   r   r0   r0   r1   r   7     zTcRange._leftc                 C  s   | j \}}}}|| S )z3Index of column following the last column in range.r   )r/   r   r   rX   r0   r0   r1   r   =  r   zTcRange._rightc                 C  s   | j jS )z+`a:tbl` element containing this cell range.)r   ra   r:   r0   r0   r1   r   C  s   zTcRange._tblc                 C  s   | j \}}}}|S )zIndex of topmost row in range.r   )r/   r   r   r0   r0   r1   r   H  r   zTcRange._topN)rN   rh   r   rh   )rN   rh   rq   )r+   r   )r+   r   )rr   rs   rt   ru   r   rz   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   r   r0   r0   r0   r1   r     s:    
	




r   N)-ru   
__future__r   typingr   r   r   r   pptx.enum.textr   	pptx.oxmlr   pptx.oxml.dml.fillr	   pptx.oxml.nsr   pptx.oxml.simpletypesr   r   r   r   pptx.oxml.textr   pptx.oxml.xmlchemyr   r   r   r   r   r   r   r   	pptx.utilr   r   r   r   rh   r   r   r'   r   r,   objectr   r0   r0   r0   r1   <module>   s.    (
  <"