
    hiLB                       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e          Z G d de          Z  G d de          Z! G d de          Z" G d de          Z# G d de          Z$ G 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                      e Zd ZdZd% fdZd&dZed'd            Zed(d            Z	e	j
        d)d            Z	ed(d            Zej
        d)d            Zed(d            Zej
        d)d            Zd*dZed(d            Zej
        d)d            Zed(d            Zej
        d)d            Zd+dZd+dZed,d!            Zed"             Zed(d#            Zej
        d)d$            Z x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                r    t          t          |                                            || _        || _        d S N)superr   __init___tbl_graphic_frame)selfr   r   	__class__s      b/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/pptx/table.pyr   zTable.__init__   s4    eT##%%%	+    row_idxintcol_idxreturn_Cellc                T    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%   s      r!   cellz
Table.cell"   s$     TY\\'733T:::r"   _ColumnCollectionc                ,    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   s    r!   columnszTable.columns*   s     !D111r"   boolc                    | 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-   s    r!   	first_colzTable.first_col3        y!!r"   valuec                    || j         _        d S r   r1   r   r5   s     r!   r3   zTable.first_col<       "	r"   c                    | j         j        S )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-   s    r!   	first_rowzTable.first_row@   r4   r"   c                    || j         _        d S r   r:   r7   s     r!   r<   zTable.first_rowI   r8   r"   c                    | j         j        S )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-   s    r!   horz_bandingzTable.horz_bandingM        y  r"   c                    || j         _        d S r   r?   r7   s     r!   rA   zTable.horz_bandingV       !	r"   Iterator[_Cell]c                N      f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  8   K   | ]}t          |          V  d S r   r'   .0r)   r   s     r!   	<genexpr>z#Table.iter_cells.<locals>.<genexpr>_   s+      ??Bb$??????r"   )r   iter_tcsr-   s   `r!   
iter_cellszTable.iter_cellsZ   s.    
 @???$)*<*<*>*>????r"   c                    | j         j        S )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-   s    r!   last_colzTable.last_cola   rB   r"   c                    || j         _        d S r   rO   r7   s     r!   rQ   zTable.last_colj   rD   r"   c                    | j         j        S )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-   s    r!   last_rowzTable.last_rown   s     y  r"   c                    || j         _        d S r   rT   r7   s     r!   rV   zTable.last_rowv   rD   r"   Nonec                t    t          t          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                    g | ]	}|j         
S  )height)rJ   rows     r!   
<listcomp>z/Table.notify_height_changed.<locals>.<listcomp>   s    #D#D#D3CJ#D#D#Dr"   N)r
   sumrowsr   r\   )r   new_table_heights     r!   notify_height_changedzTable.notify_height_changedz   s<     s#D#D$)#D#D#DEEFF%5"""r"   c                t    t          t          d | j        D                                 }|| j        _        dS )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                    g | ]	}|j         
S r[   )width)rJ   cols     r!   r^   z.Table.notify_width_changed.<locals>.<listcomp>   s    "E"E"E39"E"E"Er"   N)r
   r_   r.   r   re   )r   new_table_widths     r!   notify_width_changedzTable.notify_width_changed   s;     c"E"E"E"E"EFFGG$3!!!r"   r   c                    | j         j        S )z'The package part containing this table.)r   partr-   s    r!   rj   z
Table.part   s     "''r"   c                ,    t          | j        |           S )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-   s    r!   r`   z
Table.rows   s     di...r"   c                    | j         j        S )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-   s    r!   vert_bandingzTable.vert_banding   rB   r"   c                    || j         _        d S r   rn   r7   s     r!   rp   zTable.vert_banding   rD   r"   )r   r   r   r   )r#   r$   r%   r$   r&   r'   )r&   r+   r&   r/   )r5   r/   r&   rE   r&   rX   )r&   r   )__name__
__module____qualname____doc__r   r*   r   r.   propertyr3   setterr<   rA   rM   rQ   rV   rb   rh   rj   r`   rp   __classcell__r    s   @r!   r   r      s        , , , , , ,
; ; ; ; 2 2 2 \2 " " " X" # # # # " " " X" # # # # ! ! ! X! " " " "@ @ @ @ ! ! ! X! _" " " _" ! ! ! X! _" " " _"6 6 6 64 4 4 4 ( ( ( X( / / \/ ! ! ! X! " " " " " " " "r"   r   c                  H    e Zd ZdZd2 fdZd3dZd3dZed4d            Ze	d5d            Z
e	d5d            Ze	d6d            Zej        d7d            Ze	d6d            Zej        d8d            Ze	d6d            Zej        d9d            Ze	d6d            Zej        d:d            Zd;d!Ze	d<d#            Ze	d<d$            Zd=d%Ze	d>d'            Zej        d?d)            Ze	d@d+            Ze	dAd-            Zej        dBd/            ZedCd1            Z xZS )Dr'   z
Table cellr)   r   parentr   c                f    t          t          |                               |           || _        d S r   )r   r'   r   _tc)r   r)   r~   r    s      r!   r   z_Cell.__init__   s,    eT##F+++r"   otherobjectr&   r/   c                \    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typer   r   r   s     r!   __eq__z_Cell.__eq__   s0     %d,, 	5x59$$r"   c                \    t          |t          |                     sdS | j        |j        uS )NTr   r   s     r!   __ne__z_Cell.__ne__   s.    %d,, 	4xuy((r"   r   c                \    | j                                         }t          j        |          S )zs|FillFormat| instance for this cell.

        Provides access to fill properties such as foreground color.
        )r   get_or_add_tcPrr   from_fill_parent)r   tcPrs     r!   fillz
_Cell.fill   s(     x''))*4000r"   c                    | j         j        S )z=True if this cell is the top-left grid cell in a merged cell.)r   is_merge_originr-   s    r!   r   z_Cell.is_merge_origin   s     x''r"   c                    | j         j        S )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.
        )r   
is_spannedr-   s    r!   r   z_Cell.is_spanned   s     x""r"   r   c                    | j         j        S )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.
        )r   marLr-   s    r!   margin_leftz_Cell.margin_left   s     x}r"   r   Length | Nonec                H    |                      |           || j        _        d S r   )_validate_margin_valuer   r   )r   r   s     r!   r   z_Cell.margin_left   s#    ##K000#r"   c                    | j         j        S )zRight margin of cell.)r   marRr-   s    r!   margin_rightz_Cell.margin_right        x}r"   r   c                H    |                      |           || j        _        d S r   )r   r   r   )r   r   s     r!   r   z_Cell.margin_right   s#    ##L111$r"   c                    | j         j        S )zTop margin of cell.)r   marTr-   s    r!   
margin_topz_Cell.margin_top   r   r"   r   c                H    |                      |           || j        _        d S r   )r   r   r   )r   r   s     r!   r   z_Cell.margin_top   s#    ##J///"r"   c                    | j         j        S )zBottom margin of cell.)r   marBr-   s    r!   margin_bottomz_Cell.margin_bottom   r   r"   r   c                H    |                      |           || j        _        d S r   )r   r   r   )r   r   s     r!   r   z_Cell.margin_bottom   s#    ##M222%r"   
other_cellrX   c                   t          | j        |j                  }|j        st          d          |j        rt          d          |                                 |j        \  }}|                                D ]	}||_        
|	                                D ]	}||_
        
|                                D ]	}d|_        
|                                D ]	}d|_        
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   r   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_range	row_count	col_countr)   s         r!   mergez_Cell.merge  s    48Z^44% 	@>???( 	HFGGG'')))'2	9++-- 	# 	#B"BJJ,,.. 	$ 	$B#BKK3355 	 	BBII2244 	 	BBII	 	r"   r$   c                    | j         j        S )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`.
        )r   r   r-   s    r!   span_heightz_Cell.span_height"  s     xr"   c                    | j         j        S )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`.
        )r   r   r-   s    r!   
span_widthz_Cell.span_width-  s     x  r"   c                    | j         st          d          t          j        | j                  }|                                D ]}dx|_        |_        dx|_        |_	        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)
r   r   r   from_merge_originr   rL   r   r   r   r   )r   r   r)   s      r!   splitz_Cell.split8  st     # 	b`aaa,TX66##%% 	* 	*B'((BJ$))BI			* 	*r"   strc                    | j         j        S )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-   s    r!   r   z
_Cell.textJ  s     ##r"   r   c                    || j         _        d S r   r   )r   r   s     r!   r   z
_Cell.textZ  s    #r"   r	   c                T    | j                                         }t          ||           S )z9|TextFrame| containing the text that appears in the cell.)r   get_or_add_txBodyr	   )r   txBodys     r!   r   z_Cell.text_frame^  s'     ++--&&&r"   MSO_VERTICAL_ANCHOR | Nonec                    | j         j        S )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.
        r   anchorr-   s    r!   vertical_anchorz_Cell.vertical_anchord  s     xr"   mso_anchor_idxc                    || j         _        d S r   r   )r   r   s     r!   r   z_Cell.vertical_anchorq  s    (r"   margin_valuec                `    t          | t                    s| d}t          || z            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')r   r$   	TypeError)r   tmpls     r!   r   z_Cell._validate_margin_valueu  sC     ,,, 	11ICDD</000	1 	11I1Ir"   )r)   r   r~   r   )r   r   r&   r/   )r&   r   rr   r&   r   )r   r   )r   r   )r   r   )r   r   )r   r'   r&   rX   r&   r$   rt   )r&   r   )r   r   )r&   r	   )r&   r   )r   r   )r   r   r&   rX   )ru   rv   rw   rx   r   r   r   r   r   ry   r   r   r   rz   r   r   r   r   r   r   r   r   r   r   staticmethodr   r{   r|   s   @r!   r'   r'      s	            % % % %) ) ) )
 1 1 1 \1 ( ( ( X( 	# 	# 	# X	#    X $ $ $ $    X % % % %    X # # # #    X & & & &   <       X  ! ! ! X!* * * *$ $ $ $ X$ 
[$ $ $ [$ ' ' ' X'
 
 
 
 X
 ) ) ) ) 1 1 1 \1 1 1 1 1r"   r'   c                  ^     e Zd ZdZd fdZedd	            Zej        dd            Z xZS )_ColumnzTable columngridColr   r~   r+   c                t    t          t          |                               |           || _        || _        d S r   )r   r   r   _parent_gridCol)r   r   r~   r    s      r!   r   z_Column.__init__  s3    gt%%f---r"   r&   r   c                    | j         j        S )zWidth of column in EMU.)r   wr-   s    r!   re   z_Column.width  s     }r"   re   c                P    || j         _        | j                                         d S r   )r   r   r   rh   )r   re   s     r!   re   z_Column.width  s%    ))+++++r"   )r   r   r~   r+   r   )re   r   )	ru   rv   rw   rx   r   ry   re   rz   r{   r|   s   @r!   r   r   }  s                   
    X \, , , \, , , , ,r"   r   c                  t     e Zd ZdZd fdZed             Zedd
            Zej        dd            Z xZ	S )_Rowz	Table rowtrr   r~   rl   c                t    t          t          |                               |           || _        || _        d S r   )r   r   r   r   _trr   r   r~   r    s      r!   r   z_Row.__init__  s3    dD""6***r"   c                ,    t          | j        |           S )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-   s    r!   cellsz
_Row.cells  s     tx...r"   r&   r   c                    | j         j        S )zHeight of row in EMU.)r   hr-   s    r!   r\   z_Row.height  s     xzr"   r\   c                P    || j         _        | j                                         d S r   )r   r   r   rb   )r   r\   s     r!   r\   z_Row.height  s%    
**,,,,,r"   )r   r   r~   rl   r   )r\   r   )
ru   rv   rw   rx   r   ry   r   r\   rz   r{   r|   s   @r!   r   r     s        O     
 / / X/    X ]- - - ]- - - - -r"   r   c                  <     e Zd ZdZd fdZddZddZddZ xZS )r   z Horizontal sequence of row cellsr   r   r~   r   c                t    t          t          |                               |           || _        || _        d S r   )r   r   r   r   r   r   s      r!   r   z_CellCollection.__init__  s3    ot$$--f555r"   idxr$   r&   r'   c                    |dk     s|t          | j        j                  k    rd|z  }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   msgs      r!   __getitem__z_CellCollection.__getitem__  sP    77cS1111036CS//!TX_S)4000r"   rE   c                4      fd j         j        D             S )zProvides iterability.c              3  8   K   | ]}t          |          V  d S r   rH   rI   s     r!   rK   z+_CellCollection.__iter__.<locals>.<genexpr>  s+      ::Bb$::::::r"   )r   r   r-   s   `r!   __iter__z_CellCollection.__iter__  s!    ::::$(/::::r"   c                4    t          | j        j                  S )z1Supports len() function (e.g. 'len(cells) == 1').)r   r   r   r-   s    r!   __len__z_CellCollection.__len__  s    48?###r"   )r   r   r~   r   )r   r$   r&   r'   rs   r   )	ru   rv   rw   rx   r   r   r   r   r{   r|   s   @r!   r   r     s        **     
1 1 1 1; ; ; ;$ $ $ $ $ $ $ $r"   r   c                  8     e Zd ZdZd fdZdd	Zd
 Zd Z xZS )r+   zSequence of table columns.r   r   r~   r   c                t    t          t          |                               |           || _        || _        d S r   )r   r+   r   r   r   r   r   r~   r    s      r!   r   z_ColumnCollection.__init__  s4    &&//777			r"   r   r$   c                    |dk     s"|t          | j        j        j                  k    rd|z  }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   s      r!   r   z_ColumnCollection.__getitem__  sX    77cS!2!>????2S8CS//!ty(4S94@@@r"   c                >    t          | j        j        j                  S )z3Supports len() function (e.g. 'len(columns) == 1').)r   r   r  r  r-   s    r!   r   z_ColumnCollection.__len__  s    49$0111r"   c                8    | j                                          dS )z@Called by a column when its width changes. Pass along to parent.N)r   rh   r-   s    r!   rh   z&_ColumnCollection.notify_width_changed  s    ))+++++r"   r   r   r~   r   )r   r$   )	ru   rv   rw   rx   r   r   r   rh   r{   r|   s   @r!   r+   r+     sy        $$     
A A A A2 2 2, , , , , , ,r"   r+   c                  8     e Zd ZdZd fdZddZd Zd Z xZS )rl   zSequence of table rowsr   r   r~   r   c                t    t          t          |                               |           || _        || _        d S r   )r   rl   r   r   r   r   s      r!   r   z_RowCollection.__init__  s3    nd##,,V444			r"   r   r$   r&   r   c                    |dk     s|t          |           k    rd|z  }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   s      r!   r   z_RowCollection.__getitem__  sK    77cSYY&&/#5CS//!DI$S)4000r"   c                4    t          | j        j                  S )z0Supports len() function (e.g. 'len(rows) == 1').)r   r   r	  r-   s    r!   r   z_RowCollection.__len__  s    49#$$$r"   c                8    | j                                          dS )z>Called by a row when its height changes. Pass along to parent.N)r   rb   r-   s    r!   rb   z$_RowCollection.notify_height_changed  s    **,,,,,r"   r  )r   r$   r&   r   )	ru   rv   rw   rx   r   r   r   rb   r{   r|   s   @r!   rl   rl     su               
1 1 1 1% % %- - - - - - -r"   rl   N)&rx   
__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   r   r   r'   r   r   r   r+   rl   r[   r"   r!   <module>r     s]   3 3 " " " " " " * * * * * * * * $ $ $ $ $ $ # # # # # #             $ $ $ $ $ $ ' ' ' ' ' ' ' ' !222222PPPPPPPPPPPP......111111''''''      O" O" O" O" O"F O" O" O"dR1 R1 R1 R1 R1H R1 R1 R1j, , , , ,h , , ,&- - - - -8 - - -6$ $ $ $ $h $ $ $0, , , , , , , ,0- - - - -X - - - - -r"   