o
    7 hLB                     @  s,  d 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mZ er\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 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-Table-related objects such as Table and Cell.    )annotations)TYPE_CHECKINGIterator)
FillFormat)TcRange)Subshape)	TextFrame)Emulazyproperty)MSO_VERTICAL_ANCHOR)CT_TableCT_TableCellCT_TableColCT_TableRow)BaseSlidePart)GraphicFrame)ProvidesPart)Lengthc                      s&  e Zd ZdZd3 fddZd4ddZed5ddZed6ddZ	e	j
d7ddZ	ed6ddZej
d7ddZed6ddZej
d7ddZd8ddZed6d d!Zej
d7d"d!Zed6d#d$Zej
d7d%d$Zd9d'd(Zd9d)d*Zed:d,d-Zed.d/ Zed6d0d1Zej
d7d2d1Z  ZS );TablezA DrawingML table object.

    Not intended to be constructed directly, use
    :meth:`.Slide.shapes.add_table` to add a table to a slide.
    tblr   graphic_framer   c                   s   t t|   || _|| _d S N)superr   __init___tbl_graphic_frame)selfr   r   	__class__ R/var/www/html/figdemos/bartoux_crm/venv/lib/python3.10/site-packages/pptx/table.pyr      s   
zTable.__init__row_idxintcol_idxreturn_Cellc                 C  s   t | j||| S )zReturn cell at `row_idx`, `col_idx`.

        Return value is an instance of |_Cell|. `row_idx` and `col_idx` are zero-based, e.g.
        cell(0, 0) is the top, left cell in the table.
        )r%   r   tc)r   r!   r#   r   r   r    cell"   s   z
Table.cell_ColumnCollectionc                 C     t | j| S )z|_ColumnCollection| instance for this table.

        Provides access to |_Column| objects representing the table's columns. |_Column| objects
        are accessed using list notation, e.g. `col = tbl.columns[0]`.
        )r(   r   r   r   r   r    columns*      zTable.columnsboolc                 C     | j jS )zWhen `True`, indicates first column should have distinct formatting.

        Read/write. Distinct formatting is used, for example, when the first column contains row
        headings (is a side-heading column).
        r   firstColr*   r   r   r    	first_col3      zTable.first_colvaluec                 C     || j _d S r   r/   r   r3   r   r   r    r1   <      c                 C  r.   )zWhen `True`, indicates first row should have distinct formatting.

        Read/write. Distinct formatting is used, for example, when the first row contains column
        headings.
        r   firstRowr*   r   r   r    	first_row@   r2   zTable.first_rowc                 C  r4   r   r7   r5   r   r   r    r9   I   r6   c                 C  r.   )zWhen `True`, indicates rows should have alternating shading.

        Read/write. Used to allow rows to be traversed more easily without losing track of which
        row is being read.
        r   bandRowr*   r   r   r    horz_bandingM   r2   zTable.horz_bandingc                 C  r4   r   r:   r5   r   r   r    r<   V   r6   Iterator[_Cell]c                   s    fdd j  D S )zGenerate _Cell object for each cell in this table.

        Each grid cell is generated in left-to-right, top-to-bottom order.
        c                 3      | ]}t | V  qd S r   r%   .0r&   r*   r   r    	<genexpr>_       z#Table.iter_cells.<locals>.<genexpr>)r   iter_tcsr*   r   r*   r    
iter_cellsZ   s   zTable.iter_cellsc                 C  r.   )zWhen `True`, indicates the rightmost column should have distinct formatting.

        Read/write. Used, for example, when a row totals column appears at the far right of the
        table.
        r   lastColr*   r   r   r    last_cola   r2   zTable.last_colc                 C  r4   r   rF   r5   r   r   r    rH   j   r6   c                 C  r.   )zWhen `True`, indicates the bottom row should have distinct formatting.

        Read/write. Used, for example, when a totals row appears as the bottom row.
        r   lastRowr*   r   r   r    last_rown   s   zTable.last_rowc                 C  r4   r   rI   r5   r   r   r    rK   v   r6   Nonec                 C  $   t tdd | jD }|| j_dS )zCalled by a row when its height changes.

        Triggers the graphic frame to recalculate its total height (as the sum of the row
        heights).
        c                 S     g | ]}|j qS r   )height)rA   rowr   r   r    
<listcomp>       z/Table.notify_height_changed.<locals>.<listcomp>N)r	   sumrowsr   rO   )r   Znew_table_heightr   r   r    notify_height_changedz      zTable.notify_height_changedc                 C  rM   )zCalled by a column when its width changes.

        Triggers the graphic frame to recalculate its total width (as the sum of the column
        widths).
        c                 S  rN   r   )width)rA   colr   r   r    rQ      rR   z.Table.notify_width_changed.<locals>.<listcomp>N)r	   rS   r+   r   rW   )r   Znew_table_widthr   r   r    notify_width_changed   rV   zTable.notify_width_changedr   c                 C  r.   )z'The package part containing this table.)r   partr*   r   r   r    rZ         z
Table.partc                 C  r)   )z|_RowCollection| instance for this table.

        Provides access to |_Row| objects representing the table's rows. |_Row| objects are
        accessed using list notation, e.g. `col = tbl.rows[0]`.
        )_RowCollectionr   r*   r   r   r    rT      r,   z
Table.rowsc                 C  r.   )zWhen `True`, indicates columns should have alternating shading.

        Read/write. Used to allow columns to be traversed more easily without losing track of
        which column is being read.
        r   bandColr*   r   r   r    vert_banding   r2   zTable.vert_bandingc                 C  r4   r   r]   r5   r   r   r    r_      r6   )r   r   r   r   )r!   r"   r#   r"   r$   r%   )r$   r(   r$   r-   )r3   r-   r$   r=   r$   rL   )r$   r   )__name__
__module____qualname____doc__r   r'   r
   r+   propertyr1   setterr9   r<   rE   rH   rK   rU   rY   rZ   rT   r_   __classcell__r   r   r   r    r      sJ    



		
r   c                      s`  e Zd ZdZdD fddZdEddZdEddZedFddZe	dGddZ
e	dGddZe	dHddZejdIddZe	dHddZejdJd dZe	dHd!d"ZejdKd$d"Ze	dHd%d&ZejdLd(d&ZdMd+d,Ze	dNd.d/Ze	dNd0d1ZdOd2d3Ze	dPd5d6ZejdQd8d6Ze	dRd:d;Ze	dSd=d>ZejdTd@d>ZedUdBdCZ  ZS )Vr%   z
Table cellr&   r   parentr   c                   s   t t| | || _d S r   )r   r%   r   _tc)r   r&   rj   r   r   r    r      s   
z_Cell.__init__otherobjectr$   r-   c                 C  s   t |t| s	dS | j|ju S )z|True| if this object proxies the same element as `other`.

        Equality for proxy objects is defined as referring to the same XML element, whether or not
        they are the same proxy object instance.
        F
isinstancetyperk   r   rl   r   r   r    __eq__   s   z_Cell.__eq__c                 C  s   t |t| s	dS | j|juS )NTrn   rq   r   r   r    __ne__   s   z_Cell.__ne__r   c                 C  s   | j  }t|S )zs|FillFormat| instance for this cell.

        Provides access to fill properties such as foreground color.
        )rk   get_or_add_tcPrr   from_fill_parent)r   tcPrr   r   r    fill   s   

z
_Cell.fillc                 C  r.   )z=True if this cell is the top-left grid cell in a merged cell.)rk   is_merge_originr*   r   r   r    rx      r[   z_Cell.is_merge_originc                 C  r.   )ac  True if this cell is spanned by a merge-origin cell.

        A merge-origin cell "spans" the other grid cells in its merge range, consuming their area
        and "shadowing" the spanned grid cells.

        Note this value is |False| for a merge-origin cell. A merge-origin cell spans other grid
        cells, but is not itself a spanned cell.
        )rk   
is_spannedr*   r   r   r    ry      s   
z_Cell.is_spannedr   c                 C  r.   )zLeft margin of cells.

        Read/write. If assigned |None|, the default value is used, 0.1 inches for left and right
        margins and 0.05 inches for top and bottom.
        )rk   marLr*   r   r   r    margin_left   r2   z_Cell.margin_leftr{   Length | Nonec                 C     |  | || j_d S r   )_validate_margin_valuerk   rz   )r   r{   r   r   r    r{         
c                 C  r.   )zRight margin of cell.)rk   marRr*   r   r   r    margin_right   r[   z_Cell.margin_rightr   c                 C  r}   r   )r~   rk   r   )r   r   r   r   r    r      r   c                 C  r.   )zTop margin of cell.)rk   marTr*   r   r   r    
margin_top   r[   z_Cell.margin_topr   c                 C  r}   r   )r~   rk   r   )r   r   r   r   r    r      r   c                 C  r.   )zBottom margin of cell.)rk   marBr*   r   r   r    margin_bottom   r[   z_Cell.margin_bottomr   c                 C  r}   r   )r~   rk   r   )r   r   r   r   r    r      r   
other_cellrL   c                 C  s   t | j|j}|jstd|jrtd|  |j\}}| D ]}||_q"|	 D ]}||_
q,| D ]}d|_q6| D ]}d|_q@dS )a  Create merged cell from this cell to `other_cell`.

        This cell and `other_cell` specify opposite corners of the merged cell range. Either
        diagonal of the cell region may be specified in either order, e.g. self=bottom-right,
        other_cell=top-left, etc.

        Raises |ValueError| if the specified range already contains merged cells anywhere within
        its extents or if `other_cell` is not in the same table as `self`.
        zother_cell from different tablez'range contains one or more merged cellsTN)r   rk   in_same_table
ValueErrorcontains_merged_cellmove_content_to_origin
dimensionsiter_top_row_tcsrowSpaniter_left_col_tcsgridSpaniter_except_left_col_tcshMergeiter_except_top_row_tcsvMerge)r   r   tc_rangeZ	row_count	col_countr&   r   r   r    merge  s    

z_Cell.merger"   c                 C  r.   )af  int count of rows spanned by this cell.

        The value of this property may be misleading (often 1) on cells where `.is_merge_origin`
        is not |True|, since only a merge-origin cell contains complete span information. This
        property is only intended for use on cells known to be a merge origin by testing
        `.is_merge_origin`.
        )rk   r   r*   r   r   r    span_height"     	z_Cell.span_heightc                 C  r.   )ai  int count of columns spanned by this cell.

        The value of this property may be misleading (often 1) on cells where `.is_merge_origin`
        is not |True|, since only a merge-origin cell contains complete span information. This
        property is only intended for use on cells known to be a merge origin by testing
        `.is_merge_origin`.
        )rk   r   r*   r   r   r    
span_width-  r   z_Cell.span_widthc                 C  sD   | j stdt| j}| D ]}d |_|_d |_|_	qdS )aX  Remove merge from this (merge-origin) cell.

        The merged cell represented by this object will be "unmerged", yielding a separate
        unmerged cell for each grid cell previously spanned by this merge.

        Raises |ValueError| when this cell is not a merge-origin cell. Test with
        `.is_merge_origin` before calling.
        z>not a merge-origin cell; only a merge-origin cell can be split   FN)
rx   r   r   from_merge_originrk   rD   r   r   r   r   )r   r   r&   r   r   r    split8  s   	z_Cell.splitstrc                 C  r.   )a  Textual content of cell as a single string.

        The returned string will contain a newline character (`"\n"`) separating each paragraph
        and a vertical-tab (`"\v"`) character for each line break (soft carriage return) in the
        cell's text.

        Assignment to `text` replaces all text currently contained in the cell. A newline
        character (`"\n"`) in the assigned text causes a new paragraph to be started. A
        vertical-tab (`"\v"`) character in the assigned text causes a line-break (soft
        carriage-return) to be inserted. (The vertical-tab character appears in clipboard text
        copied from PowerPoint as its encoding of line-breaks.)
        
text_frametextr*   r   r   r    r   J  s   z
_Cell.textr   c                 C  r4   r   r   )r   r   r   r   r    r   Z  r6   r   c                 C  s   | j  }t|| S )z9|TextFrame| containing the text that appears in the cell.)rk   get_or_add_txBodyr   )r   txBodyr   r   r    r   ^  s   

z_Cell.text_frameMSO_VERTICAL_ANCHOR | Nonec                 C  r.   )a  Vertical alignment of this cell.

        This value is a member of the :ref:`MsoVerticalAnchor` enumeration or |None|. A value of
        |None| indicates the cell has no explicitly applied vertical anchor setting and its
        effective value is inherited from its style-hierarchy ancestors.

        Assigning |None| to this property causes any explicitly applied vertical anchor setting to
        be cleared and inheritance of its effective value to be restored.
        rk   anchorr*   r   r   r    vertical_anchord  s   z_Cell.vertical_anchormso_anchor_idxc                 C  r4   r   r   )r   r   r   r   r    r   q  r6   margin_valuec                 C  s*   t | ts| durd}t||  dS dS )zMRaise ValueError if `margin_value` is not a positive integer value or |None|.Nz.margin value must be integer or None, got '%s')ro   r"   	TypeError)r   tmplr   r   r    r~   u  s   z_Cell._validate_margin_value)r&   r   rj   r   )rl   rm   r$   r-   )r$   r   r`   r$   r   )r{   r|   )r   r|   )r   r|   )r   r|   )r   r%   r$   rL   r$   r"   rb   )r$   r   )r   r   )r$   r   )r$   r   )r   r   )r   r|   r$   rL   )rc   rd   re   rf   r   rr   rs   r
   rw   rg   rx   ry   r{   rh   r   r   r   r   r   r   r   r   r   r   staticmethodr~   ri   r   r   r   r    r%      sZ    






r%   c                      s@   e Zd ZdZd fddZedd
dZejdddZ  ZS )_ColumnzTable columngridColr   rj   r(   c                       t t| | || _|| _d S r   )r   r   r   _parent_gridCol)r   r   rj   r   r   r    r        
z_Column.__init__r$   r   c                 C  r.   )zWidth of column in EMU.)r   wr*   r   r   r    rW     r[   z_Column.widthrW   c                 C     || j _| j  d S r   )r   r   r   rY   )r   rW   r   r   r    rW        )r   r   rj   r(   r   )rW   r   )	rc   rd   re   rf   r   rg   rW   rh   ri   r   r   r   r    r   }  s    r   c                      sL   e Zd ZdZd fddZedd	 ZedddZejdddZ  Z	S )_Rowz	Table rowtrr   rj   r\   c                   r   r   )r   r   r   r   _trr   r   rj   r   r   r    r     r   z_Row.__init__c                 C  r)   )zRead-only reference to collection of cells in row.

        An individual cell is referenced using list notation, e.g. `cell = row.cells[0]`.
        )_CellCollectionr   r*   r   r   r    cells  s   z
_Row.cellsr$   r   c                 C  r.   )zHeight of row in EMU.)r   hr*   r   r   r    rO     r[   z_Row.heightrO   c                 C  r   r   )r   r   r   rU   )r   rO   r   r   r    rO     r   )r   r   rj   r\   r   )rO   r   )
rc   rd   re   rf   r   rg   r   rO   rh   ri   r   r   r   r    r     s    
r   c                      s@   e Zd ZdZd fddZdddZdddZdddZ  ZS )r   z Horizontal sequence of row cellsr   r   rj   r   c                   r   r   )r   r   r   r   r   r   r   r   r    r     r   z_CellCollection.__init__idxr"   r$   r%   c                 C  s:   |dk s|t | jjkrd| }t|t| jj| | S )z+Provides indexed access, (e.g. 'cells[0]').r   zcell index [%d] out of range)lenr   tc_lst
IndexErrorr%   r   r   msgr   r   r    __getitem__  s   z_CellCollection.__getitem__r=   c                   s    fdd j jD S )zProvides iterability.c                 3  r>   r   r?   r@   r*   r   r    rB     rC   z+_CellCollection.__iter__.<locals>.<genexpr>)r   r   r*   r   r*   r    __iter__  s   z_CellCollection.__iter__c                 C     t | jjS )z1Supports len() function (e.g. 'len(cells) == 1').)r   r   r   r*   r   r   r    __len__  r6   z_CellCollection.__len__)r   r   rj   r   )r   r"   r$   r%   ra   r   )	rc   rd   re   rf   r   r   r   r   ri   r   r   r   r    r     s    

r   c                      s<   e Zd ZdZd fddZdd
dZdd Zdd Z  ZS )r(   zSequence of table columns.r   r   rj   r   c                   r   r   )r   r(   r   r   r   r   r   rj   r   r   r    r     r   z_ColumnCollection.__init__r   r"   c                 C  s>   |dk s|t | jjjkrd| }t|t| jjj| | S )z-Provides indexed access, (e.g. 'columns[0]').r   zcolumn index [%d] out of range)r   r   tblGridgridCol_lstr   r   r   r   r   r    r     s   z_ColumnCollection.__getitem__c                 C  s   t | jjjS )z3Supports len() function (e.g. 'len(columns) == 1').)r   r   r   r   r*   r   r   r    r        z_ColumnCollection.__len__c                 C     | j   dS )z@Called by a column when its width changes. Pass along to parent.N)r   rY   r*   r   r   r    rY     r   z&_ColumnCollection.notify_width_changedr   r   rj   r   )r   r"   )	rc   rd   re   rf   r   r   r   rY   ri   r   r   r   r    r(         
r(   c                      s<   e Zd ZdZd fddZdddZdd Zdd Z  ZS )r\   zSequence of table rowsr   r   rj   r   c                   r   r   )r   r\   r   r   r   r   r   r   r    r     r   z_RowCollection.__init__r   r"   r$   r   c                 C  s6   |dk s
|t | krd| }t|t| jj| | S )z*Provides indexed access, (e.g. 'rows[0]').r   zrow index [%d] out of range)r   r   r   r   tr_lstr   r   r   r    r     s   z_RowCollection.__getitem__c                 C  r   )z0Supports len() function (e.g. 'len(rows) == 1').)r   r   r   r*   r   r   r    r     r6   z_RowCollection.__len__c                 C  r   )z>Called by a row when its height changes. Pass along to parent.N)r   rU   r*   r   r   r    rU     r   z$_RowCollection.notify_height_changedr   )r   r"   r$   r   )	rc   rd   re   rf   r   r   r   rU   ri   r   r   r   r    r\     r   r\   N)&rf   
__future__r   typingr   r   pptx.dml.fillr   pptx.oxml.tabler   pptx.shapesr   pptx.text.textr   	pptx.utilr	   r
   pptx.enum.textr   r   r   r   r   pptx.parts.slider   pptx.shapes.graphfrmr   
pptx.typesr   r   rm   r   r%   r   r   r   r(   r\   r   r   r   r    <module>   s0      V