
    g
fI                         d Z dZdZdZdZdZddlZddlZddlZ ej                  dd	       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  G d d      Zej)                          y)a  
Utilities for obtaining information about accessible tables.
These utilities are app-type- and toolkit-agnostic. Utilities that might have
different implementations or results depending on the type of app (e.g. terminal,
chat, web) or toolkit (e.g. Qt, Gtk) should be in script_utilities.py file(s).

N.B. There are currently utilities that should never have custom implementations
that live in script_utilities.py files. These will be moved over time.
z$Id$z
$Revision$z$Date$zGCopyright (c) 2023 Igalia, S.L.Copyright (c) 2023 GNOME Foundation Inc.LGPL    NAtspiz2.0)r      )debug)messages)AXObject)AXUtilitiesc                      e Zd ZdZi Zi Zi Zi Zi Zi Z	i Z
i Zi Zi Zi Zi Zi Zi Zi Zi Z ej*                         Zed        Zed        ZedCd       ZedCd       Zed        ZedDd       Zed        ZedDd	       Zed
        Z edEd       Z!ed        Z"ed        Z#ed        Z$ed        Z%ed        Z&ed        Z'ed        Z(edDd       Z)ed        Z*ed        Z+ed        Z,ed        Z-ed        Z.ed        Z/ed        Z0ed        Z1ed        Z2ed        Z3ed        Z4edFd       Z5ed         Z6ed!        Z7edFd"       Z8edGd#       Z9ed$        Z:ed%        Z;ed&        Z<ed'        Z=ed(        Z>ed)        Z?ed*        Z@ed+        ZAed,        ZBed-        ZCed.        ZDed/        ZEed0        ZFed1        ZGed2        ZHed3        ZIed4        ZJed5        ZKed6        ZLed7        ZMed8        ZNed9        ZOed:        ZPed;        ZQed<        ZRed=        ZSed>        ZTed?        ZUed@        ZVedA        ZWyB)HAXTablez<Utilities for obtaining information about accessible tables.c                  z    t        j                  t        j                        } d| _        | j                          y)z3Starts thread to periodically clear cached details.)targetTN)	threadingThreadr   _clear_stored_datadaemonstart)threads    //usr/lib/python3/dist-packages/orca/ax_table.pystart_cache_clearing_threadz#AXTable.start_cache_clearing_threadL   s*     !!)C)CD    c                  X    	 t        j                  d       t        j                          *)z*Clears any data we have cached for objects<   )timesleepr   _clear_all_dictionaries r   r   r   zAXTable._clear_stored_dataT   s#     JJrN++- r   c                    d}| r|d|  z  }t        j                  t         j                  |d       t        j                  5  t        j
                  j                          t        j                  j                          t        j                  j                          t        j                  j                          t        j                  j                          t        j                  j                          t        j                  j                          t        j                  j                          t        j                  j                          t        j                  j                          t        j                   j                          t        j"                  j                          t        j$                  j                          d d d        y # 1 sw Y   y xY w)NzAXTable: Clearing cache.z	 Reason: T)r   printMessage
LEVEL_INFOr   _lockCAPTIONSclearPHYSICAL_COORDINATES_FROM_CELLPHYSICAL_COORDINATES_FROM_TABLEPHYSICAL_SPANS_FROM_CELLPHYSICAL_SPANS_FROM_TABLEPHYSICAL_COLUMN_COUNTPHYSICAL_ROW_COUNTPRESENTABLE_COORDINATESPRESENTABLE_COORDINATES_LABELSPRESENTABLE_COLUMN_COUNTPRESENTABLE_ROW_COUNTCOLUMN_HEADERS_FOR_CELLROW_HEADERS_FOR_CELL)reasonmsgs     r   r   zAXTable._clear_all_dictionaries\   s9   (Yvh''C5++S$7]] 	1""$2288:3399;,,224--335))//1&&,,.++1132288:,,224))//1++113((..0	1 	1 	1s   FGGc                 .    t         j                  |        y)z*Clears all cached information immediately.N)r   r   )r/   s    r   clear_cache_nowzAXTable.clear_cache_nowr   s     	''/r   c                    t        j                  |       syt        |       t        j                  v r(t        j                  j                  t        |             S 	 t        j                  j                  |       }d| d|g}t        j                  t        j                  |d       |t        j                  t        |       <   |S # t        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)z>Returns the accessible object containing the caption of table.Nz#AXTable: Exception in get_caption: TzAXTable: Caption foris)r   supports_tablehashr   r!   getr   Tableget_caption	Exceptionr   r   r   printTokens)tablecaptionerrorr0   tokenss        r   r9   zAXTable.get_captionx   s     &&u-;'***##''U44	kk--e4G )%w?%**FD9(/e%  	7w?Cu//d;	s   C 	D *C;;D c                    t        j                  |       sy|rt        j                  |       }||S t        j                  j                  t        |             }||S 	 t        j                  j                  |       }d| d|g}t        j                  t        j                  |d       |t        j                  t        |       <   |S # t        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)z"Returns the column count of table.Nz(AXTable: Exception in get_column_count: TzAXTable: Column count forr4   )r   r5   r    _get_column_count_from_attributer'   r7   r6   r   r8   get_n_columnsr:   r   r   r   r;   r<   prefer_attributecountr>   r0   r?   s         r   get_column_countzAXTable.get_column_count   s     &&u-<<UCE --11$u+>L	KK--e4E .udEB%**FD95:%%d5k2  	<UGDCu//d;	   C 	D*C??Dc                    t        |       t        j                  v r(t        j                  j                  t        |             S t	        j
                  |       }|j                  d      }d}|t        |      }d| d|g}t        j                  t        j                  |d       |t        j                  t        |       <   |S )zJReturns the value of the 'colcount' object attribute or None if not found.colcountNz#AXTable: Column count attribute forr4   T)
r6   r   r+   r7   r   get_attributes_dictintr   r;   r   r<   attrsattrrF   r?   s        r   rB   z(AXTable._get_column_count_from_attribute   s     ;':::3377UDD,,U3yy$IE7eL%**FD98=((e5r   c                    t        j                  |       sy|rt        j                  |       }||S t        j                  j                  t        |             }||S 	 t        j                  j                  |       }d| d|g}t        j                  t        j                  |d       |t        j                  t        |       <   |S # t        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)zReturns the row count of table.rA   Nz%AXTable: Exception in get_row_count: TzAXTable: Row count forr4   )r   r5   r   _get_row_count_from_attributer(   r7   r6   r   r8   
get_n_rowsr:   r   r   r   r;   rD   s         r   get_row_countzAXTable.get_row_count   s     &&u-99%@E **..tE{;L	KK**51E +E4?%**FD927""4;/  	9%ACu//d;	rH   c                    t        |       t        j                  v r(t        j                  j                  t        |             S t	        j
                  |       }|j                  d      }d}|t        |      }d| d|g}t        j                  t        j                  |d       |t        j                  t        |       <   |S )zJReturns the value of the 'rowcount' object attribute or None if not found.rowcountNz AXTable: Row count attribute forr4   T)
r6   r   r,   r7   r   rK   rL   r   r;   r   rM   s        r   rQ   z%AXTable._get_row_count_from_attribute   s     ;'7770044T%[AA,,U3yy$IE4eT5I%**FD95:%%d5k2r   c           
         t        t        |t        j                  | d                  D ]  }t        t        |t        j	                  | d                  D ]Q  }	 t
        j                  j                  | ||      dkD  r  yt
        j                  j                  | ||      dkD  r  yS  y# t        $ r6}d| }t        j                  t        j                  |d       Y d}~  yd}~ww xY w)z<Returns True if table has at least one cell with a span > 1.Fr   Tz,AXTable: Exception in is_non_uniform_table: N)rangeminr   rS   rG   r   r8   get_row_extent_atget_column_extent_atr:   r   r   r   )r<   max_rowsmax_colsrowcolr>   r0   s          r   is_non_uniform_tablezAXTable.is_non_uniform_table   s     Xw'<'<UE'JKL 
	!CS7+C+CE5+QRS 	!!{{44UCEI#{{77sCH1L# M		!
	!  ! !HPC&&u'7'7dC !s   $B-$B--	C,6*C''C,c                 N   t        j                  |       sg S 	 t        j                  j	                  |       }d| d|g}t        j                  t        j                  |d       |S # t
        $ r6}d| }t        j                  t        j                  |d       g cY d}~S d}~ww xY w)z0Returns the number of selected columns in table.z0AXTable: Exception in get_selected_column_count TNz"AXTable: Selected column count forr4   )
r   r5   r   r8   get_n_selected_columnsr:   r   r   r   r;   r<   rF   r>   r0   r?   s        r   get_selected_column_countz!AXTable.get_selected_column_count   s     &&u-I	KK66u=E 7tUK%**FD9  	DUGLCu//d;I	   A% %	B$.+BB$B$c                 N   t        j                  |       sg S 	 t        j                  j	                  |       }d| d|g}t        j                  t        j                  |d       |S # t
        $ r6}d| }t        j                  t        j                  |d       g cY d}~S d}~ww xY w)zCReturns a list of column indices for the selected columns in table.z,AXTable: Exception in get_selected_columns: TNzAXTable: Selected columns forare)
r   r5   r   r8   get_selected_columnsr:   r   r   r   r;   )r<   columnsr>   r0   r?   s        r   rg   zAXTable.get_selected_columns  s     &&u-I	kk66u=G 25%I%**FD9  	@HCu//d;I	rd   c                 N   t        j                  |       sg S 	 t        j                  j	                  |       }d| d|g}t        j                  t        j                  |d       |S # t
        $ r6}d| }t        j                  t        j                  |d       g cY d}~S d}~ww xY w)z-Returns the number of selected rows in table.z-AXTable: Exception in get_selected_row_count TNzAXTable: Selected row count forr4   )
r   r5   r   r8   get_n_selected_rowsr:   r   r   r   r;   rb   s        r   get_selected_row_countzAXTable.get_selected_row_count   s     &&u-I	KK33E:E 4UD%H%**FD9  	A%ICu//d;I	rd   c                 N   t        j                  |       sg S 	 t        j                  j	                  |       }d| d|g}t        j                  t        j                  |d       |S # t
        $ r6}d| }t        j                  t        j                  |d       g cY d}~S d}~ww xY w)z=Returns a list of row indices for the selected rows in table.z)AXTable: Exception in get_selected_rows: TNzAXTable: Selected rows forrf   )
r   r5   r   r8   get_selected_rowsr:   r   r   r   r;   )r<   rowsr>   r0   r?   s        r   rm   zAXTable.get_selected_rows2  s     &&u-I	;;007D /udC%**FD9  	=eWECu//d;I	rd   c                     t        j                  |       syt        j                  | d      }|dk  ryt        j	                  |       |k(  ryt        j                  | d      }t        j                  |       |k(  S )z0Returns True if all cells in table are selected.FrE   r   T)r   r5   r   rS   rk   rG   rc   )r<   rn   colss      r   all_cells_are_selectedzAXTable.all_cells_are_selectedD  su     &&u-$$UU$C19))%0D8'''F0074??r   c                 j   t        j                  |       sy	 t        j                  j	                  | ||      }d| d| d| d|g}t        j                  t        j                  |d       |S # t
        $ r<}d| d| d| d|g}t        j                  t        j                  |d       Y d}~yd}~ww xY w)	z1Returns the cell at the 0-indexed row and column.Nz(AXTable: Exception getting cell at row: z col: z in:TzAXTable: Cell at row: r4   )	r   r5   r   r8   get_accessible_atr:   r   r;   r   )r<   r]   columncellr>   r?   s         r   get_cell_atzAXTable.get_cell_atU  s     &&u-	;;00VDD +3%vfXSA5$PTU%**FD9  	@VF8SVWY^5"Fe..=		s   !A- -	B262B--B2c                 
   t        j                  | d      }||dk7  rt        |      S t        j                  |       }t        j                  |      t
        j                  j                  k(  r|} t        j                  |       S )z>Returns the index of cell to be used with the table interface.ztable-cell-index )	r   get_attributerL   
get_parentget_roler   Role
TABLE_CELLget_index_in_parent)rw   indexparents      r   _get_cell_indexzAXTable._get_cell_indexh  sr     &&t-?@"u:
 $$T*V$

(=(==D++D11r   c                 2   t        j                  |       syt        j                  |       rt        j                  |       \  }}nt        j                  |       \  }}|s||fS t        j                  |       \  }}|t        |      }|t        |      }||fS )z!Returns the row and column spans.rA   rA   )	r	   is_table_cell_or_headerr   supports_table_cellr   _get_cell_spans_from_table_cell_get_cell_spans_from_table_get_cell_spans_from_attributerL   )rw   rE   row_spancol_spanrowspan_attrcolspan_attrs         r   get_cell_spanszAXTable.get_cell_spansy  s     2248''-!(!H!H!NHh!(!C!CD!IHhX%%%,%K%KD%Q"l#<(H#<(H!!r   c                    t        |       t        j                  v r(t        j                  j                  t        |             S t	        j
                  |       }|j                  d      }|j                  d      }d| d|d|g}t        j                  t        j                  |d       ||ft        j                  t        |       <   ||fS )zMReturns the row and column spans exposed via object attribute, or None, None.rowspancolspanz(AXTable: Row and col span attributes forrt   ,T)	r6   r   PRESENTABLE_SPANSr7   r   rK   r   r;   r   )rw   rN   r   r   r?   s        r   r   z&AXTable._get_cell_spans_from_attribute  s     :222,,00d<<,,T299Y'99Y'<dCSVX`a%**FD908(0B!!$t*-!!r   c                    t        |       t        j                  v r(t        j                  j                  t        |             S t        j	                  |       }|dk  ryt        j                  |       }|yt        j                  |      syt        j                  |      ry	 t        j                  j                  ||      }|d   sy|j"                  }t        j%                  |d      }||kD  r1d| | d	| g}t        j&                  t        j                   |d       d
}|j(                  }	t        j+                  |d      }
|	|
kD  r1d| |	 d|
 g}t        j&                  t        j                   |d       d
}	d| d| d|	 g}t        j&                  t        j                   |d       ||	ft        j                  t        |       <   ||	fS # t        $ r4}d| }t        j                  t        j                   |d       Y d}~yd}~ww xY w)zAReturns the row and column spans of cell via the table interface.r   r   N)r   r   z2AXTable: Exception in _get_cell_spans_from_table: TFz!AXTable: Table iface row span forz is greater than row count: r   z!AXTable: Table iface col span forz is greater than col count: zAXTable: Table iface spans forare rowspan: , colspan: )r6   r   r&   r7   r   	get_tabler   r5   r	   is_treer   r8   get_row_column_extents_at_indexr:   r   r   r   row_extentsrS   r;   col_extentsrG   )rw   r   r<   resultr>   r0   r   	row_countr?   r   	col_counts              r   r   z"AXTable._get_cell_spans_from_table  s    ::::4488dDD''-19!!$'=&&u- u%	[[@@NF ay%%))%7	i94!
">ykJLFe..=H%%,,UE:	i94!
">ykJLFe..=H2D!(;xjAC%**FD98@(8J))$t*5!!9  	FugNCu//d;	s   $ G 	H	*HH	c                 V   t        |       t        j                  v r(t        j                  j                  t        |             S t	        j
                  |       sy	 t        j                  j                  |       }t        j                  j                  |       }d| d| d| g}t        j                  t        j                  |d       ||ft        j                  t        |       <   ||fS # t        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)zFReturns the row and column spans of cell via the table cell interface.r   z7AXTable: Exception in _get_cell_spans_from_table_cell: TNz"AXTable: TableCell iface spans forr   r   )r6   r   r%   r7   r   r   r   	TableCellget_row_spanget_column_spanr:   r   r   r   r;   )rw   r   r   r>   r0   r?   s         r   r   z'AXTable._get_cell_spans_from_table_cell  s    :9993377T
CC++D1	 33D9H66t<H 7!(;xjAC%**FD97?7I((d4!!  	KE7SCu//d;	s   >C+ +	D(4*D##D(c                 p   t        j                  |       sg S |dk  rg S 	 t        j                  j	                  | |      }d| d| d|g}t        j                  t        j                  |d       ||gS g S # t
        $ r6}d| }t        j                  t        j                  |d       g cY d}~S d}~ww xY w)zIReturns the column headers of the indexed column via the table interface.r   z6AXTable: Exception in _get_column_headers_from_table: TNz'AXTable: Table iface header for column  ofr4   )
r   r5   r   r8   get_column_headerr:   r   r   r   r;   )r<   rv   headerr>   r0   r?   s         r   _get_column_headers_from_tablez&AXTable._get_column_headers_from_table  s     &&u-IA:I	[[225&AF <F83GPTV\]%**FD98O	  	J5'RCu//d;I	    A6 6	B5?+B0*B50B5c                 J   t        j                  |       sg S 	 t        j                  j	                  |       }d|g}t        j                  t        j                  |d       |S # t
        $ r6}d| }t        j                  t        j                  |d       g cY d}~S d}~ww xY w)zAReturns the column headers for cell via the table cell interface.z;AXTable: Exception in _get_column_headers_from_table_cell: TNz5AXTable: TableCell iface column headers for cell are:)
r   r   r   r   get_column_header_cellsr:   r   r   r   r;   rw   headersr>   r0   r?   s        r   #_get_column_headers_from_table_cellz+AXTable._get_column_headers_from_table_cell	  s     ++D1I	oo==dCG J7S%**FD9  	OPUwWCu//d;I	   A# #	B",+BB"B"c                 p   t        j                  |       sg S |dk  rg S 	 t        j                  j	                  | |      }d| d| d|g}t        j                  t        j                  |d       ||gS g S # t
        $ r6}d| }t        j                  t        j                  |d       g cY d}~S d}~ww xY w)zCReturns the row headers of the indexed row via the table interface.r   z3AXTable: Exception in _get_row_headers_from_table: TNz$AXTable: Table iface header for row r   r4   )
r   r5   r   r8   get_row_headerr:   r   r   r   r;   )r<   r]   r   r>   r0   r?   s         r   _get_row_headers_from_tablez#AXTable._get_row_headers_from_table  s     &&u-I7I	[[//s;F 9SA5$PVW%**FD98O	  	GwOCu//d;I	r   c                 J   t        j                  |       sg S 	 t        j                  j	                  |       }d|g}t        j                  t        j                  |d       |S # t
        $ r6}d| }t        j                  t        j                  |d       g cY d}~S d}~ww xY w)z>Returns the row headers for cell via the table cell interface.z8AXTable: Exception in _get_row_headers_from_table_cell: TNz2AXTable: TableCell iface row headers for cell are:)
r   r   r   r   get_row_header_cellsr:   r   r   r   r;   r   s        r    _get_row_headers_from_table_cellz(AXTable._get_row_headers_from_table_cell3  s     ++D1I	oo::4@G GP%**FD9  	LUGTCu//d;I	r   c                     t         j                  |       }||S t         j                  |      }t        t        |      j	                  t        |                  S )zCReturns row headers of cell that are not also headers of old_cell. )r   get_row_headerslistset
differencerw   old_cellr   old_headerss       r   get_new_row_headerszAXTable.get_new_row_headersE  sN     ))$/N--h7CL++C,<=>>r   c                     t         j                  |       }||S t         j                  |      }t        t        |      j	                  t        |                  S )zFReturns column headers of cell that are not also headers of old_cell. )r   get_column_headersr   r   r   r   s       r   get_new_column_headerszAXTable.get_new_column_headersP  sN     ,,T2N00:CL++C,<=>>r   c                 Z   t        j                  |       sg S t        j                  |       }||gS t        j                  j                  t        |             }||S t        j                  |       }t        |      dk7  r|t        j                  t        |       <   |S t        j                  |d         }t        |      dk(  rJ|d   |vrC|j                  d|d          t        j                  |d         }t        |      dk(  r|d   |vrC|t        j                  t        |       <   |S )zNReturns the row headers for cell, doing extra work to ensure we have them all.r   r   )
r	   is_table_cellr   get_dynamic_row_headerr.   r7   r6   _get_row_headersleninsertrw   dynamic_headerr   otherss       r   r   zAXTable.get_row_headers[  s    ((.I 77=%"## --11$t*=M))$/v;!7=G((d4M))&)4&kQ6!9F#:MM!VAY'--fQi8F &kQ6!9F#: 4:$$T$Z0r   c                 z   t        j                  |       rt        j                  |       S t        j	                  |       \  }}|dk  s|dk  rg S t        j                  |       }|g S g }t        j                  |       d   }t        |||z         D ]'  }|j                  t        j                  ||             ) |S )z!Returns the row headers for cell.r   )
r   r   r   r    _get_cell_coordinates_from_tabler   r   rW   extendr   )rw   r]   rv   r<   r   r   r   s          r   r   zAXTable._get_row_headers  s     ''-;;DAA>>tDV7fqjI!!$'=I44T:1=3g. 	NENN7>>ueLM	N r   c                     t        j                  |       syt        |dz   t        j	                  |             }t        |      D ]  }t        j                  | |      s y y)z<Returns True if table has any headers for rows 0-stop_after.Fr   T)r   r5   rX   r   rS   rW   r   r<   
stop_afteris      r   has_row_headerszAXTable.has_row_headers  s\     &&u-a)>)>u)EF
z" 	A225!<	 r   c                 Z   t        j                  |       sg S t        j                  |       }||gS t        j                  j                  t        |             }||S t        j                  |       }t        |      dk7  r|t        j                  t        |       <   |S t        j                  |d         }t        |      dk(  rJ|d   |vrC|j                  d|d          t        j                  |d         }t        |      dk(  r|d   |vrC|t        j                  t        |       <   |S )zQReturns the column headers for cell, doing extra work to ensure we have them all.r   r   )
r	   r   r   get_dynamic_column_headerr-   r7   r6   _get_column_headersr   r   r   s       r   r   zAXTable.get_column_headers  s    ((.I ::4@%"## 0044T$Z@M,,T2v;!:@G++DJ7M,,VAY7&kQ6!9F#:MM!VAY'00;F &kQ6!9F#: 7=''T
3r   c                 z   t        j                  |       rt        j                  |       S t        j	                  |       \  }}|dk  s|dk  rg S t        j                  |       }|g S g }t        j                  |       d   }t        |||z         D ]'  }|j                  t        j                  ||             ) |S )z$Returns the column headers for cell.r   r   )
r   r   r   r   r   r   r   rW   r   r   )rw   r]   rv   r<   r   r   r   s          r   r   zAXTable._get_column_headers  s     ''->>tDD>>tDV7fqjI!!$'=I44T:1=66G#34 	QENN7AA%OP	Q r   c                     t        j                  |       syt        |dz   t        j	                  |             }t        |      D ]  }t        j                  | |      s y y)z?Returns True if table has any headers for columns 0-stop_after.Fr   T)r   r5   rX   r   rG   rW   r   r   s      r   has_column_headerszAXTable.has_column_headers  s\     &&u-a)A)A%)HI
z" 	A55eQ?	 r   c                    t        j                  |       s&|r$t        j                  | t         j                        } t        j                  |       syt        j                  |       rt
        j                  |       \  }}nt
        j                  |       \  }}|s||fS t
        j                  |       \  }}|t        |      dz
  }|t        |      dz
  }||fS )z+Returns the 0-based row and column indices.r   r   )
r	   r   r   find_ancestorr   r   %_get_cell_coordinates_from_table_cellr   $_get_cell_coordinates_from_attributerL   )rw   rE   	find_cellr]   r^   	row_index	col_indexs          r   get_cell_coordinateszAXTable.get_cell_coordinates  s     2248Y))$0S0STD2248''-DDTJHC??EHC8O&KKDQ	9 i.1$C i.1$CCxr   c                    t        |       t        j                  v r(t        j                  j                  t        |             S t        j	                  |       }|dk  ryt        j                  |       }|*d| g}t        j                  t        j                  |d       y	 t        j                  j                  ||      }t        j                  j                  ||      }d| d| d	| g}t        j                  t        j                  |d       ||ft        j                  t        |       <   ||fS # t        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)
zCReturns the row and column indices of cell via the table interface.r   r   Nz6AXTable: Couldn't find table-implementing ancestor forTz8AXTable: Exception in _get_cell_coordinates_from_table: zAXTable: Table iface coords for	are row: , col: )r6   r   r$   r7   r   r   r   r;   r   r   r8   get_row_at_indexget_column_at_indexr:   r   )rw   r   r<   r?   r]   rv   r>   r0   s           r   r   z(AXTable._get_cell_coordinates_from_table  sG    :@@@::>>tDzJJ''-19!!$'=NPTUFe..=	++..ue<C[[44UEBF 4TYse7SYRZ;[\%**FD9>A6k//T
;F{  	LUGTCu//d;	s   !A D3 3	E0<*E++E0c                 &   t        |       t        j                  v r(t        j                  j                  t        |             S t	        j
                  |       sy	 t        j                  j                  |       \  }}}|syd| d| d| g}t        j                  t        j                  |d       ||ft        j                  t        |       <   ||fS # t        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)zHReturns the row and column indices of cell via the table cell interface.r   z=AXTable: Exception in _get_cell_coordinates_from_table_cell: TNz#AXTable: TableCell iface coords forr   r   )r6   r   r#   r7   r   r   r   r   get_positionr:   r   r   r   r;   )rw   successr]   rv   r>   r0   r?   s          r   r   z-AXTable._get_cell_coordinates_from_table_cell-  s     :???99==d4jII++D1	#(??#?#?#E GS& 73%wW]V^?_`%**FD9=@&[..tDz:F{  	QRWQXYCu//d;	s   #C 	D*DDc                    | yt        |       t        j                  v r(t        j                  j                  t        |             S t	        j
                  |       }|j                  d      }|j                  d      }d| d|d|g}t        j                  t        j                  |d       ||ft        j                  t        |       <   ||||fS t	        j                  | t        j                        }|||fS t	        j
                  |      }|j                  d|      }|j                  d|      }d|d||g}t        j                  t        j                  |d       ||ft        j                  t        |       <   ||fS )	zQReturns the 1-based indices for cell exposed via object attribute, or None, None.)NNrowindexcolindexz)AXTable: Row and col index attributes forrt   r   Tz$AXTable: Updated attributes based on)r6   r   r)   r7   r   rK   r   r;   r   r   r	   is_table_row)rw   rN   r   r   r?   r]   s         r   r   z,AXTable._get_cell_coordinates_from_attributeF  sd    <:8882266tDzBB,,T2IIj)	IIj)	=tS)UXZcd%**FD96?6J''T
3 Y%:i''$$T;+C+CD;i'',,S1IIj)4	IIj)4	8#sIyY%**FD96?6J''T
3)##r   c                 f   | yt        j                  |       r7	 t        j                  j	                  |       }t        j
                  |      r|S d } ||       r| S t        j                  | |      S # t        $ r4}d| }t        j                  t        j                  |d       Y d}~[d}~ww xY w)zJReturns obj if it is a table, otherwise returns the ancestor table of obj.Nz!AXTable: Exception in get_table: Tc                     t        j                  |       s*t        j                  |       st        j                  |       rt	        j
                  |       S y)NF)r	   is_tableis_tree_tabler   r   r5   )xs    r   r   z#AXTable.get_table.<locals>.is_tablex  s?    ##A&+*C*CA*F+J]J]^_J`..q11r   )r   r   r   r   r   r5   r:   r   r   r   r   )objr<   r>   r0   r   s        r   r   zAXTable.get_tableg  s     ;'',!11#6
 **51 L	
 C=J%%c844  @9%A""5#3#3S$??@s   A3 3	B0<*B++B0c                     t        j                  |       syt        j                  t        j                  |       t        j                  |             }t        j                  |       rt        j                   d| }|S )z@Returns an end-user-consumable string which describes the table.rz    )	r   r5   r   	tableSizer   rS   rG   r_   TABLE_NON_UNIFORM)r<   r   s     r   &get_table_description_for_presentationz.AXTable.get_table_description_for_presentation  sh     &&u-##G$9$9%$@'BZBZ[`Bab''. 2231VH=Fr   c                 :    d\  }}t         j                  | ||      S )z Returns the first cell in table.)r   r   )r   rx   r<   r]   r^   s      r   get_first_cellzAXTable.get_first_cell  s"     S""5#s33r   c                     t         j                  |       dz
  t         j                  |       dz
  }}t         j                  | ||      S )zReturns the last cell in table.r   )r   rS   rG   rx   r   s      r   get_last_cellzAXTable.get_last_cell  sC     ((/!3W5M5Me5TWX5XS""5#s33r   c                     t         j                  | d      \  }}|dz  }t         j                  t         j                  |       ||      S )z%Returns the cell above cell in table.Frp   r   r   r   rx   r   rw   r]   r^   s      r   get_cell_abovezAXTable.get_cell_above  F     //u/MSq""7#4#4T#:CEEr   c                     t         j                  | d      \  }}|t         j                  | d      d   z  }t         j                  t         j	                  |       ||      S )z%Returns the cell below cell in table.Frp   r   r   r   r   rx   r   r   s      r   get_cell_belowzAXTable.get_cell_below  \     //u/MSw%%dU%CAFF""7#4#4T#:CEEr   c                     t         j                  | d      \  }}|dz  }t         j                  t         j                  |       ||      S )zReturns the cell to the left.Frp   r   r   r   s      r   get_cell_on_leftzAXTable.get_cell_on_left  r  r   c                     t         j                  | d      \  }}|t         j                  | d      d   z  }t         j                  t         j	                  |       ||      S )zReturns the cell to the right.Frp   r   r  r   s      r   get_cell_on_rightzAXTable.get_cell_on_right  r  r   c                     t         j                  | d      d   }t         j                  t         j                  |       |d      S )z,Returns the cell at the start of cell's row.Frp   r   r   rw   r]   s     r   get_start_of_rowzAXTable.get_start_of_row  s>     **4%*HK""7#4#4T#:CCCr   c                     t         j                  | d      d   }t         j                  |       }t         j                  |      dz
  }t         j	                  t         j                  |       ||      S )z*Returns the cell at the end of cell's row.Frp   r   r   )r   r   r   rG   rx   )rw   r]   r<   r^   s       r   get_end_of_rowzAXTable.get_end_of_row  sc     **4%*HK!!$'&&u-1""7#4#4T#:CEEr   c                     t         j                  | d      d   }t         j                  t         j                  |       d|      S )z-Returns the cell at the top of cell's column.Frp   r   r   r   rw   r^   s     r   get_top_of_columnzAXTable.get_top_of_column  s>     **4%*HK""7#4#4T#:AsCCr   c                     t         j                  | d      d   }t         j                  |       }t         j                  |      dz
  }t         j	                  t         j                  |       ||      S )z0Returns the cell at the bottom of cell's column.Frp   r   )r   r   r   rS   rx   )rw   r^   r<   r]   s       r   get_bottom_of_columnzAXTable.get_bottom_of_column  sc     **4%*HK!!$'##E*Q.""7#4#4T#:CEEr   c                 r    t        j                  | d      }|j                  d|j                  d            S )z.Returns the formula associated with this cell.F)	use_cacheformulaFormula)r   rK   r7   )rw   rN   s     r   get_cell_formulazAXTable.get_cell_formula  s0     ,,TUCyyEIIi$899r   c                 N    t         j                  | d      \  }}|dk(  xr |dk(  S )z4Returns True if this is the first cell in its table.Frp   r   r   r   r   s      r   is_first_cellzAXTable.is_first_cell  s0     //u/MSax$C1H$r   c                     t         j                  | d      \  }}|dk  s|dk  ryt         j                  |       }|y|dz   t         j                  |d      k(  xr |dz   t         j	                  |d      k(  S )z3Returns True if this is the last cell in its table.Frp   r   r   )r   r   r   rS   rG   )rw   r]   r^   r<   s       r   is_last_cellzAXTable.is_last_cell  s     //u/MS7cAg!!$'=Qw'///NN Sa733EE3RR	Sr   c                 @    t         j                  | d      d   }|dk(  S )z2Returns True if this is the first cell in its row.Frp   r   r   r  r  s     r   is_start_of_rowzAXTable.is_start_of_row  '     **4%*HKaxr   c                     t         j                  | d      d   }|dk  ryt         j                  |       }|y|dz   t         j                  |d      k(  S )z1Returns True if this is the last cell in its row.Frp   r   r   )r   r   r   rG   )rw   r^   r<   s      r   is_end_of_rowzAXTable.is_end_of_row   s_     **4%*HK7!!$'=Qw'22552QQQr   c                 @    t         j                  | d      d   }|dk(  S )z5Returns True if this is the first cell in its column.Frp   r   r  r  s     r   is_top_of_columnzAXTable.is_top_of_column  r   r   c                     t         j                  | d      d   }|dk  ryt         j                  |       }|y|dz   t         j                  |d      k(  S )z4Returns True if this is the last cell in its column.Frp   r   r   )r   r   r   rS   )rw   r]   r<   s      r   is_bottom_of_columnzAXTable.is_bottom_of_column  s_     **4%*HK7!!$'=Qw'///NNNr   c                    d\  }}t        j                  |       }t        j                  |       r|j	                  d      dk(  rd\  }}nt        j
                  |       sd\  }}n|j	                  d      dk(  s|j	                  d      dk(  rd	\  }}nzt        j                  |       st        j                  |       rd
\  }}nJt        j                  |       st        j                  |       rd\  }}nt        j                  |       rd\  }}d| d| d| dg}t        j                  t        j                  |d       |S )z<Returns True if this table should be treated as layout only.)FzNot enough informationzlayout-guesstrue)Tz#The layout-guess attribute is true.)Tz Doesn't support table interface.z	xml-rolesr<   tag)Fz0Is a web table without layout-guess set to true.)FzHas headers)FzHas name or description)FzHas captionzAXTable:zis layout only: z ()T)r   rK   r	   r   r7   r5   r   r   r   get_nameget_descriptionr9   r   r;   r   )r<   r   r/   rN   r?   s        r   is_layout_tablezAXTable.is_layout_table#  s    9,,U3&yy(F2!L,,U3!I;'72eii6F'6Q!Z++E2g6M6Me6T!5""5)X-E-Ee-L!A$$U+!5e'7xr&%KL%**FD9r   c                    t        |       t        j                  v r(t        j                  j                  t        |             S t	        j
                  |       }d}|j                  d|j                  d            }|j                  d|j                  d            }||| | }d| d| g}t        j                  t        j                  |d       |t        j                  t        |       <   |r|S t	        j                  | t        j                        }||S t	        j
                  |      }|j                  d|j                  d|            }|j                  d|j                  d|            }||| | }d	|d| g}t        j                  t        j                  |d       |t        j                  t        |       <   |S )
zDReturns the text that should be used instead of the numeric indices.rz   colindextextcoltextrowindextextrowtextzAXTable: Coordinates label forz: Tz+AXTable: Updated coordinates label based on)r6   r   r*   r7   r   rK   r   r;   r   r   r	   r   )rw   rN   r   	col_label	row_labelr?   r]   s          r   get_label_for_cell_coordinatesz&AXTable.get_label_for_cell_coordinates;  s    :???99==d4jII,,T2 IIneii	.BC	IIneii	.BC	 Y%:!{9+.F2DBvh-H%**FD9=C..tDz:M$$T;+C+CD;M,,S1IIneii	9.MN	IIneii	9.MN	 Y%:!{9+.F?6(mT%**FD9=C..tDz:r   c                     t         j                  |       }t         j                  j                  t	        |            }|yt         j                  |       \  }}||k(  ryt         j                  |||      S )z)Returns the user-set row header for cell.N)r   r   DYNAMIC_ROW_HEADERS_COLUMNr7   r6   r   rx   )rw   r<   headers_columncell_rowcell_columns        r   r   zAXTable.get_dynamic_row_headera  sl     !!$' ;;??UL! ' < <T B+.(""5(NCCr   c                     t         j                  |       }t         j                  j                  t	        |            }|yt         j                  |       \  }}||k(  ryt         j                  |||      S )z,Returns the user-set column header for cell.N)r   r   DYNAMIC_COLUMN_HEADERS_ROWr7   r6   r   rx   )rw   r<   headers_rowr9  r:  s        r   r   z!AXTable.get_dynamic_column_headerp  sl     !!$'88<<T%[I ' < <T B+{"""5+{CCr   c                 <    |t         j                  t        |       <   y)z7Sets the dynamic row headers column of table to column.N)r   r7  r6   )r<   rv   s     r   set_dynamic_row_headers_columnz&AXTable.set_dynamic_row_headers_column  s     ;A**4;7r   c                 <    |t         j                  t        |       <   y)z4Sets the dynamic column headers row of table to row.N)r   r<  r6   )r<   r]   s     r   set_dynamic_column_headers_rowz&AXTable.set_dynamic_column_headers_row  s     ;>**4;7r   c                     t        |       t        j                  vryt        j                  j                  t        |              y)z/Clears the dynamic row headers column of table.N)r6   r   r7  popr<   s    r    clear_dynamic_row_headers_columnz(AXTable.clear_dynamic_row_headers_column  1     ;g@@@**..tE{;r   c                     t        |       t        j                  vryt        j                  j                  t        |              y)z/Clears the dynamic column headers row of table.N)r6   r   r<  rC  rD  s    r    clear_dynamic_column_headers_rowz(AXTable.clear_dynamic_column_headers_row  rF  r   N)rz   )T)   rI  )
   )TF)X__name__
__module____qualname____doc__r!   r#   r$   r%   r&   r'   r(   r)   r*   r   r+   r,   r-   r.   r<  r7  r   Lockr    staticmethodr   r   r   r2   r9   rG   rB   rS   rQ   r_   rc   rg   rk   rm   rr   rx   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  r	  r  r  r  r  r  r  r  r  r"  r$  r&  r-  r5  r   r   r?  rA  rE  rH  r   r   r   r   r   3   s   F H%'"&(#! " %'"!  "$!#INNE  . . 1 1* 0 0
  *  6  "  6  "  "  "  "  "  " @ @   $ 2 2  " ", " " 4" 4"l " "2  .  "  .  " ? ? ? ? & &P  *   & &P  *    2  :  0 $ $@ 5 54 	 	 4 4 4 4 F F F F F F F F D D F F D D F F : : % % S S   R R   O O  . # #J D D D D A A
 > >
 < < < <r   r   )rN  __id____version____date____copyright____license__r   r   girequire_versiongi.repositoryr   rz   r   r   	ax_objectr   ax_utilitiesr	   r   r   r   r   r   <module>r[     sl   , ;   	   7E "     %h< h<V#  # # %r   