
    g
f                         d Z dZdZdZdZd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  G d d      Zy)a  
Utilities for obtaining information about accessible text.
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) 2024 Igalia, S.L.Copyright (c) 2024 GNOME Foundation Inc.LGPL    NAtspiz2.0)r      )debug)AXObject)AXUtilitiesc                   n   e Zd ZdZed7d       Zed        Zed7d       Zed7d       Zed        Z	ed7d       Z
ed7d	       Zed
        Zed7d       Zed7d       Zed        Zed7d       Zed        Zed7d       Zed        Zed7d       Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Z ed        Z!ed         Z"ed!        Z#ed"        Z$ed#        Z%ed$        Z&ed8d%       Z'ed&        Z(ed7d'       Z)ed9d(       Z*ed)        Z+ed7d*       Z,ed+        Z-ed,        Z.ed-        Z/ed.        Z0ed/        Z1ed0        Z2ed7d1       Z3ed2        Z4ed3        Z5ed4        Z6ed5        Z7ed6        Z8y):AXTextz:Utilities for obtaining information about accessible text.Nc           	         t         j                  |       }|sy|t         j                  |       }d|cxk  r|k  s.n d| d}t        j                  t        j
                  |d       y	 t        j                  j                  | |t        j                  j                        }|j                  j                  d	d
      }d| d| d| d|j                    d|j"                   dg}t        j$                  t        j
                  |d       |j                  |j                   |j"                  fS # t        $ r}	 t        j                  j                  | |t        j                  j                        }d| }t        j                  t        j
                  |d       nD# t        $ r8}d| }t        j                  t        j
                  |d       Y d}~Y d}~yd}~ww xY wY d}~Cd}~ww xY w)zJReturns the character, start, and end for the current or specified offset. r   r   Nr   zWARNING: Offset z, is not valid. No character can be provided.T<WARNING: String at offset failed; text at offset succeeded: z.AXText: Exception in get_character_at_offset: 
\nzAXText: Character at offset  in'' (-))r
   get_character_countget_caret_offsetr   printMessage
LEVEL_INFOr   Textget_string_at_offsetTextGranularityCHAR	Exceptionget_text_at_offsetTextBoundaryTypecontentreplacestart_offset
end_offsetprintTokens)	objoffsetlengthmsgresulterrorerror2debug_stringtokenss	            ./usr/lib/python3/dist-packages/orca/ax_text.pyget_character_at_offsetzAXText.get_character_at_offset2   s    ++C0>,,S1FF$f$$VH,XYCu//d;	@ZZ44S&%BWBWB\B\]F ~~--dE:0<cl^3v':':&;1V=N=N<OqQS%**FD9~~v22F4E4EEE!  
	@	@66sFEDZDZD_D_` UUZT[\""5#3#3S$?   FvhO""5#3#3S$?x  @
	@s<   *9D. .	G+89F1+G&	G%*GG&GG&&G+c                     t         j                  | ||      }d|cxk  rt         j                  |       k  sy yt         j                  | |      S )z=Returns the character, start, and end at the specified point.r   r   )r
   get_offset_at_pointr   r0   r&   xyr'   s       r/   get_character_at_pointzAXText.get_character_at_pointV   N     ++CA6F<V77<< =--c6::    c              #     K   |t         j                  |       }d}t         j                  |       }||k  rKt         j                  | |      \  }}}||sy|r|||f|k7  r|||f t	        ||dz         }|||f}||k  rJyyw)zOGenerator to iterate by character in obj starting with the character at offset.Nr   )r
   r   r   r0   max)r&   r'   last_resultr(   	characterstartends          r/   iter_characterzAXText.iter_character`         >,,S1F++C0vo$*$B$B3$O!Iuc"9i4C++fqj)F#UC/K vo   A=B Bc           	      x   t         j                  |       }|sy|t         j                  |       }t        t	        d|      |dz
        }	 t
        j                  j                  | |t
        j                  j                        }d| d	| d
|j"                   d|j$                   d|j&                   dg}t        j(                  t        j                   |d       |j"                  |j$                  |j&                  fS # t        $ r}	 t
        j                  j                  | |t
        j                  j                        }d| }t        j                  t        j                   |d       nD# t        $ r8}d| }t        j                  t        j                   |d       Y d}~Y d}~yd}~ww xY wY d}~1d}~ww xY w)zEReturns the word, start, and end for the current or specified offset.r   Nr   r   r   Tz)AXText: Exception in get_word_at_offset: zAXText: Word at offset r   r   r   r   r   )r
   r   r   minr:   r   r   r   r   WORDr   r   r    
WORD_STARTr   r   r   r!   r#   r$   r%   r&   r'   r(   r*   r+   r)   r,   r.   s           r/   get_word_at_offsetzAXText.get_word_at_offsetr   s    ++C0>,,S1FSF^VaZ0	@ZZ44S&%BWBWB\B\]F ,F837fnn%S)<)<(=Qv?P?P>QQRSU%**FD9~~v22F4E4EEE!  	@
@66!7!7!B!BD UUZT[\""5#3#3S$?   A&J""5#3#3S$?x  @	@<   
9C< <	F99E*?+F4*	F+3*F&F4&F++F44F9c                     t         j                  | ||      }d|cxk  rt         j                  |       k  sy yt         j                  | |      S )z8Returns the word, start, and end at the specified point.r   r   )r
   r2   r   rG   r3   s       r/   get_word_at_pointzAXText.get_word_at_point   N     ++CA6F<V77<< =((f55r8   c              #     K   |t         j                  |       }d}t         j                  |       }||k  rKt         j                  | |      \  }}}||sy|r|||f|k7  r|||f t	        ||dz         }|||f}||k  rJyyw)zEGenerator to iterate by word in obj starting with the word at offset.Nr   )r
   r   r   rG   r:   )r&   r'   r;   r(   wordr=   r>   s          r/   	iter_wordzAXText.iter_word         >,,S1F++C0vo%88fED%"4uc*k9E3&&fqj)Fs*K vorA   c           	         t         j                  |       }|sy|t         j                  |       }t        j                  |       st        t        d|      |dz
        }nt        d|      }	 t        j                  j                  | |t        j                  j                        }|j&                  j)                  dd	      }d
| d| d| d|j*                   d|j,                   dg}t!        j.                  t         j$                  |d       |j&                  |j*                  |j,                  fS # t        $ r}	 t        j                  j                  | |t        j                  j                        }d| }t!        j"                  t         j$                  |d       nD# t        $ r8}d| }t!        j"                  t         j$                  |d       Y d}~Y d}~yd}~ww xY wY d}~Cd}~ww xY w)zEReturns the line, start, and end for the current or specified offset.r   Nr   r   r   Tz)AXText: Exception in get_line_at_offset: r   r   zAXText: Line at offset r   r   r   r   r   )r
   r   r   r   is_multi_linerC   r:   r   r   r   r   LINEr   r   r    
LINE_STARTr   r   r   r!   r"   r#   r$   r%   )	r&   r'   r(   r*   r+   r)   r,   r-   r.   s	            r/   get_line_at_offsetzAXText.get_line_at_offset   s    ++C0>,,S1F ((-Q!4FF^F	@ZZ44S&%BWBWB\B\]F ~~--dE:+F837l^3v':':&;1V=N=N<OqQS%**FD9~~v22F4E4EEE#  	@
@66!7!7!B!BD UUZT[\""5#3#3S$?   A&J""5#3#3S$?x  @	@s<   ,9D0 0	G-:9F3+G(	G'*GG(GG((G-c                     t         j                  | ||      }d|cxk  rt         j                  |       k  sy yt         j                  | |      S )z8Returns the line, start, and end at the specified point.r   r   )r
   r2   r   rT   r3   s       r/   get_line_at_pointzAXText.get_line_at_point   rK   r8   c              #     K   |t         j                  |       }d}t         j                  |       }||k  rKt         j                  | |      \  }}}||sy|r|||f|k7  r|||f t	        ||dz         }|||f}||k  rJyyw)zEGenerator to iterate by line in obj starting with the line at offset.Nr   )r
   r   r   rT   r:   )r&   r'   r;   r(   liner=   r>   s          r/   	iter_linezAXText.iter_line   rO   rA   c           	      x   t         j                  |       }|sy|t         j                  |       }t        t	        d|      |dz
        }	 t
        j                  j                  | |t
        j                  j                        }d| d	| d
|j"                   d|j$                   d|j&                   dg}t        j(                  t        j                   |d       |j"                  |j$                  |j&                  fS # t        $ r}	 t
        j                  j                  | |t
        j                  j                        }d| }t        j                  t        j                   |d       nD# t        $ r8}d| }t        j                  t        j                   |d       Y d}~Y d}~yd}~ww xY wY d}~1d}~ww xY w)zIReturns the sentence, start, and end for the current or specified offset.r   Nr   r   r   Tz-AXText: Exception in get_sentence_at_offset: zAXText: Sentence at offset r   r   r   r   r   )r
   r   r   rC   r:   r   r   r   r   SENTENCEr   r   r    SENTENCE_STARTr   r   r   r!   r#   r$   r%   rF   s           r/   get_sentence_at_offsetzAXText.get_sentence_at_offset   s    ++C0>,,S1FSF^VaZ0	@ZZ44S&%BWBWB`B`aF 0xs;Sfnn%S)<)<(=Qv?P?P>QQRSU%**FD9~~v22F4E4EEE!  	@
@66!7!7!F!FH UUZT[\""5#3#3S$?   EfXN""5#3#3S$?x  @	@rH   c                     t         j                  | ||      }d|cxk  rt         j                  |       k  sy yt         j                  | |      S )z<Returns the sentence, start, and end at the specified point.r   r   )r
   r2   r   r]   r3   s       r/   get_sentence_at_pointzAXText.get_sentence_at_point  sN     ++CA6F<V77<< =,,S&99r8   c              #     K   |t         j                  |       }d}t         j                  |       }||k  rKt         j                  | |      \  }}}||sy|r|||f|k7  r|||f t	        ||dz         }|||f}||k  rJyyw)zMGenerator to iterate by sentence in obj starting with the sentence at offset.Nr   )r
   r   r   r]   r:   )r&   r'   r;   r(   sentencer=   r>   s          r/   iter_sentencezAXText.iter_sentence  s      >,,S1F++C0vo#)#@#@f#M HeS"8Xuc2kAs**fqj)F"E3.K vorA   c                     t        j                  |       syt        j                  | d      \  }}}|xr d|cxk  xr |k  nc }d| d| g}t	        j
                  t        j                  |d       |S )z7Returns True if sentence iteration is supported on obj.Fr   z'AXText: Sentence iteration supported on: T)r   supports_textr
   r]   r   r%   r   r&   stringr=   r>   r*   r.   s         r/   supports_sentence_iterationz"AXText.supports_sentence_iteration+  sq     %%c*#::3Bs,A,,;SBvh-P%**FD9r8   c           	      x   t         j                  |       }|sy|t         j                  |       }t        t	        d|      |dz
        }	 t
        j                  j                  | |t
        j                  j                        }d| d| d	|j                   d
|j                   d|j                    dg}t        j"                  t        j                  |d       |j                  |j                  |j                   fS # t        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)zJReturns the paragraph, start, and end for the current or specified offset.r   Nr   r   z.AXText: Exception in get_paragraph_at_offset: TzAXText: Paragraph at offset r   r   r   r   r   )r
   r   r   rC   r:   r   r   r   r   	PARAGRAPHr   r   r   r   r!   r#   r$   r%   )r&   r'   r(   r*   r+   r)   r.   s          r/   get_paragraph_at_offsetzAXText.get_paragraph_at_offset8  s     ++C0>,,S1FSF^VaZ0	ZZ44S&%BWBWBaBabF 1<cfnn%S)<)<(=Qv?P?P>QQRSU%**FD9~~v22F4E4EEE  	B5'JCu//d;	s   
9C< <	D9*D44D9c                     t         j                  | ||      }d|cxk  rt         j                  |       k  sy yt         j                  | |      S )z=Returns the paragraph, start, and end at the specified point.r   r   )r
   r2   r   rk   r3   s       r/   get_paragraph_at_pointzAXText.get_paragraph_at_pointP  r7   r8   c              #     K   |t         j                  |       }d}t         j                  |       }||k  rKt         j                  | |      \  }}}||sy|r|||f|k7  r|||f t	        ||dz         }|||f}||k  rJyyw)zOGenerator to iterate by paragraph in obj starting with the paragraph at offset.Nr   )r
   r   r   rk   r:   )r&   r'   r;   r(   	paragraphr=   r>   s          r/   iter_paragraphzAXText.iter_paragraphZ  r@   rA   c                     t        j                  |       syt        j                  | d      \  }}}|xr d|cxk  xr |k  nc }d| d| g}t	        j
                  t        j                  |d       |S )z8Returns True if paragraph iteration is supported on obj.Fr   z(AXText: Paragraph iteration supported onrd   T)r   re   r
   rk   r   r%   r   rf   s         r/   supports_paragraph_iterationz#AXText.supports_paragraph_iterationl  sq     %%c*#;;CCs,A,,<cRx=Q%**FD9r8   c                 N   t        j                  |       sy	 t        j                  j	                  |       }d| d| dg}t        j                  t        j                  |d       |S # t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)z#Returns the character count of obj.r   z*AXText: Exception in get_character_count: TNAXText:reports z characters.)
r   re   r   r   r   r   r   r   r   r%   )r&   countr+   r)   r.   s        r/   r   zAXText.get_character_county  s     %%c*	JJ2237E SHUG<"@A%**FD9  	>ugFCu//d;	   A' '	B$0*BB$c                 N   t        j                  |       sy	 t        j                  j	                  |       }d| d| dg}t        j                  t        j                  |d       |S # t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)z Returns the caret offset of obj.z'AXText: Exception in get_caret_offset: TNrt   zreports caret offset of .)
r   re   r   r   r   r   r   r   r   r%   )r&   r'   r+   r)   r.   s        r/   r   zAXText.get_caret_offset  s     %%c*	ZZ005F S$<VHA"FG%**FD9  	;E7CCu//d;	rw   c                 V   t        j                  |       sy	 t        j                  j	                  | |      }d| d| d| g}t        j                  t        j                  |d       |S # t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)PReturns False if we definitely failed to set the offset. True cannot be trusted.Fz'AXText: Exception in set_caret_offset: TNz-AXText: Reported result of setting offset to r   rd   )
r   re   r   r   set_caret_offsetr   r   r   r   r%   r&   r'   r*   r+   r)   r.   s         r/   r}   zAXText.set_caret_offset  s     %%c*	ZZ00f=F B&MsVXY_X`Tab%**FD9  	;E7CCu//d;	s    A+ +	B(4*B##B(c                 .    t         j                  | d      S )r|   r   )r
   r}   r&   s    r/   set_caret_offset_to_startz AXText.set_caret_offset_to_start  s     &&sA..r8   c                 T    t         j                  | t         j                  |             S )r|   )r
   r}   r   r   s    r/   set_caret_offset_to_endzAXText.set_caret_offset_to_end  s"     &&sF,F,Fs,KLLr8   c           	      ^   t        j                  |       sy	 t        j                  j	                  | ||      }d| d| d| d| d	g}t        j                  t        j                  |d       |S # t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)
z5Returns the text of obj within the specified offsets.r   z$AXText: Exception in get_substring: TNAXText: Text of(r   z): 'r   )
r   re   r   r   get_textr   r   r   r   r%   )r&   r#   r$   r*   r+   r)   r.   s          r/   get_substringzAXText.get_substring  s     %%c*	ZZ((lJGF $SAl^1ZLVHTU*VW%**FD9  	8@Cu//d;	s   !A/ /	B,8*B''B,c                    t         j                  |       }|sy	 t        j                  j	                  | d|      }|j                         }t        |      dkD  r,dj                  |dd        d	dj                  |d
d        }n|}|j                  dd      }d| d| dg}t        j                  t        j                  |d       |S # t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)z Returns the text content of obj.r   r   z#AXText: Exception in get_all_text: TN
        ... r   r   r   r   )r
   r   r   r   r   r   r   r   r   splitlenjoinr"   r%   )r&   r(   r*   r+   r)   wordsr-   r.   s           r/   get_all_textzAXText.get_all_text  s    ++C0	ZZ((a8F u:?!hhuRay12%rs8L7MNL!L#++D%8#SAl^1*=>%**FD9  	7w?Cu//d;	s   !C	 		D*DDc                 N   t        j                  |       sy	 t        j                  j	                  |       }d| d| dg}t        j                  t        j                  |d       |S # t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)z:Returns the number of reported selected substrings in obj.r   z(AXText: Exception in _get_n_selections: TNrt   ru   z selection(s).)
r   re   r   r   get_n_selectionsr   r   r   r   r%   )r&   r*   r+   r)   r.   s        r/   _get_n_selectionszAXText._get_n_selections  s     %%c*	ZZ005F SHVHN"CD%**FD9  	<UGDCu//d;	rw   c                     t        j                  |       sy	 t        j                  j	                  | |       y# t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)z+Attempts to remove the specified selection.Nz(AXText: Exception in _remove_selection: T)	r   re   r   r   remove_selectionr   r   r   r   )r&   selection_numberr+   r)   s       r/   _remove_selectionzAXText._remove_selection  sf     %%c*	JJ''-=> 	<UGDCu//d;	s    9 	A6*A11A6c                 >    t        t        j                  |             S )z&Returns True if obj has selected text.)boolr
   get_selected_rangesr   s    r/   has_selected_textzAXText.has_selected_text  s     F..s344r8   c                     t         j                  |       }|syt         j                  |       }|sy|d   d   dk(  xr |d   d   |k(  S )z0Returns True of all the text in obj is selected.Fr   ry   r   )r
   r   r   )r&   r(   rangess      r/   is_all_text_selectedzAXText.is_all_text_selected  sU     ++C0++C0ay|q <VBZ]f%<<r8   c                 v    t        t        j                  |             D ]  }t        j                  | |        y)z$Attempts to clear the selected text.N)ranger
   r   r   )r&   is     r/   clear_all_selected_textzAXText.clear_all_selected_text  s3     v//45 	-A$$S!,	-r8   c                 B    t         j                  |       }|r|d   d   S y)z1Returns the leftmost offset of the selected text.r   ry   r
   r   r&   r   s     r/   get_selection_start_offsetz!AXText.get_selection_start_offset"  s(     ++C0!9Q<r8   c                 B    t         j                  |       }|r|d   d   S y)z2Returns the rightmost offset of the selected text.ry   r   r   r   s     r/   get_selection_end_offsetzAXText.get_selection_end_offset,  s(     ++C0":a= r8   c                    t         j                  |       }|sg S g }t        |      D ]m  }	 t        j                  j                  | |      }d|j                  cxk  r|j                  k  sDn G|j                  |j                  |j                  f       o d| d| g}t        j                  t        j                  |d       |S # t        $ r5}d| }t        j                  t        j                  |d       Y d}~ hd}~ww xY w)zQReturns a list of (start_offset, end_offset) tuples reflecting the selected text.z*AXText: Exception in get_selected_ranges: TNr   rt   zreports selected ranges: )r
   r   r   r   r   get_selectionr   r   r   r   r#   r$   appendr%   )r&   rv   
selectionsr   r*   r+   r)   r.   s           r/   r   zAXText.get_selected_ranges6  s     ((-I
u 	LA11#q9
 F'';&*;*;;!!6#6#68I8I"JK	L S$=j\"JK%**FD9  B5'J""5#3#3S$?s    C	D*C??Dc           	          t         j                  |       }|syg }d}d}t        t        |            D ]4  }|j	                  t        j
                  | g|        |d   }|0|d   }6 dj                  |      }|j                         }t        |      dkD  r,dj                  |dd        ddj                  |d	d        }n|}d
| d| d| d| dg}	t        j                  t        j                  |	d       |||fS )z4Returns the selected string, start, and end for obj.r   Nr   r   r   r   r   r   r   zAXText: Selected text ofr   r   r   r   T)r
   r   sortedsetr   r   r   r   r   r   r%   r   )
r&   r   stringsr#   r$   	selectiontextr   r-   r.   s
             r/   get_selected_textzAXText.get_selected_textM  s    //4

J0 	,INN6//@i@A"1J#(|		, xx 

t9r>!hhuRay12%rs8L7MNLL,cl^3|nAj\CE%**FD9\:--r8   c                     t        j                  |       sy	 t        j                  j	                  | ||      }|S # t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)z7Creates a new selection for the specified range in obj.Fz%AXText: Exception in _add_selection: TN)	r   re   r   r   add_selectionr   r   r   r   )r&   r#   r$   r*   r+   r)   s         r/   _add_new_selectionzAXText._add_new_selectionj  sr     %%c*	ZZ--c<LF   	9%ACu//d;	s   !; 	A8*A33A8c                     t        j                  |       sy	 t        j                  j	                  | |||      }|S # t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)z;Modifies specified selection in obj to the specified range.Fz(AXText: Exception in set_selected_text: TN)	r   re   r   r   set_selectionr   r   r   r   )r&   r#   r$   r   r*   r+   r)   s          r/   _update_existing_selectionz!AXText._update_existing_selectionz  sv     %%c*	ZZ--c3C\S]^F   	<UGDCu//d;	s   "< 	A9*A44A9c                    t         j                  |       dkD  rt         j                  | ||      }nt         j                  | ||      }|r|t        j
                  t        j                  k\  r[t         j                  | ||      }t         j                  |       d   }||k7  r'd}t	        j                  t        j
                  |d       |S )zSReturns False if we definitely failed to set the selection. True cannot be trusted.r   z1AXText: Substring and selected text do not match.T)
r
   r   r   r   r   r   
debugLevelr   r   r   )r&   r#   r$   r*   	substringr   r)   s          r/   set_selected_textzAXText.set_selected_text  s     ##C(1,66sL*UF..sL*MFe&&%*:*::,,S,
KI005a8II%I""5#3#3S$?r8   c                    t        j                  |       si ddfS |t        j                  |       }	 t        j
                  j                  | |d      }d| d| d| g}t        j                  t        j                  |d       |d   xs i |d	   xs d|d
   xs t        j                  |       fS # t        $ rL}d| }t        j                  t        j                  |d       i dt        j                  |       fcY d}~S d}~ww xY w)zCReturns a (dict, start, end) tuple for attributes at offset in obj.r   NT)include_defaultsz4AXText: Exception in get_text_attributes_at_offset: zAXText: Attributes forz
at offset z : r      )r   re   r
   r   r   r   get_attribute_runr   r   r   r   r   r%   r~   s         r/   get_text_attributes_at_offsetz$AXText.get_text_attributes_at_offset  s    %%c*q!8O>,,S1F	:ZZ11#vPT1UF +C:fXS1QR%**FD9ayBq	Qq	0\V=W=WX[=\\\  	:HPCu//d;q&44S999	:s   "B2 2	D;AD<DDc                 B   t        j                  |       sg S |dk(  rt        j                  |       }d| d| d| g}t	        j
                  t        j                  |d       g }|}||k  rt        j                  | |      \  }}}||k  r|j                  t        ||      ||f       n-d| d| }	t	        j                  t        j                  |	d       t        ||dz         }||k  rd	t        |       d
}	t	        j                  t        j                  |	d       |S )z:Returns a list of (start, end, attrs dict) tuples for obj.ry   zAXText: Getting attributes forzchars: r   TzAXText: Start offset z > end offset r   zAXText: z attribute ranges found.)r   re   r
   r   r   r%   r   r   r   r:   r   r   )
r&   r#   r$   r.   rvr'   attrsr=   r>   r)   s
             r/   get_all_text_attributeszAXText.get_all_text_attributes  s'    %%c*I33C8J2C7<.PQR\Q]9^_%**FD9z! & D DS& QE5#|		3uf-sE:; .eWN3%H""5#3#3S$?fqj)F z! R	!9:5++S$7	r8   c                    t        j                  |       sy	 t        j                  j	                  | ||t        j
                  j                        }d| d| d| d| g}t        j                  t        j                  |d       |S # t        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)	z;Returns the character offset in obj at the specified point.ry   z*AXText: Exception in get_offset_at_point: TNzAXText: Offset inzat , z is )r   re   r   r   r2   	CoordTypeWINDOWr   r   r   r   r%   )r&   r4   r5   r'   r+   r)   r.   s          r/   r2   zAXText.get_offset_at_point  s     %%c*	ZZ33CAu?U?UVF &sc!BqcfX,FG%**FD9  	>ugFCu//d;	s   :B 	C*B??Cc                     t        j                  |       st        j                         S |t        j                  |       }	 t        j                  j                  | |t        j                  j                        }d| d| d|g}t        j                  t        j                  |d       |S # t        $ rH}d| }t        j                  t        j                  |d       t        j                         cY d}~S d}~ww xY w)zGReturns the Atspi rect of the character at the specified offset in obj.Nz)AXText: Exception in get_character_rect: TzAXText: Offset r   has rect)r   re   r   Rectr
   r   r   get_character_extentsr   r   r   r   r   r   r%   )r&   r'   rectr+   r)   r.   s         r/   get_character_rectzAXText.get_character_rect  s     %%c*::<>,,S1F	 ::33CAWAWXD $F83/j$G%**FD9  	 =eWECu//d;::<	 s   9B, ,	C=5=C82C=8C=c                    t        j                  |       st        j                         S 	 t        j                  j                  | ||t        j                  j                        }d| d| d| d|g}t        j                  t        j                  |d       |S # t        $ rK}d| d| g}t        j                  t        j                  |d       t        j                         cY d}~S d}~ww xY w)	zCReturns the Atspi rect of the string at the specified range in obj.z'AXText: Exception in get_range_rect for:TNzAXText: Range r   r   r   )r   re   r   r   r   get_range_extentsr   r   r   r   r%   r   )r&   r=   r>   r   r+   r.   s         r/   get_range_rectzAXText.get_range_rect  s     %%c*::<	 :://UCAWAWXD #5'3%s3S*dK%**FD9  	 ?5lSFe..=::<	 s   :B 	C-"A C("C-(C-c                 >   |j                   | j                   k  xr |j                  | j                  k  xrh |j                   |j                  z   | j                   | j                  z   k\  xr3 |j                  |j                  z   | j                  | j                  z   k\  S )z1Returns true if rect1 is fully contained in rect2)r4   r5   widthheight)rect1rect2s     r/   _rect_is_fully_contained_inz"AXText._rect_is_fully_contained_in
  s     ww%''! Aegg&8 A%++%5;;)>>A%,,&%''ELL*@@	Ar8   c                     t        d|j                        |_        | j                  | j                  dz  z   |j                  k  ry| j                  | j                  dz  z   |j                  |j                  z   kD  ryy)zFReturns -1 (line above), 1 (line below), or 0 (line inside) clip_rect.r   r   ry   r   )r:   r5   r   )	line_rect	clip_rects     r/   _line_comparisonzAXText._line_comparison  sj    
 !Y[[)	;;))A--	;;;))A--	i>N>N0NNr8   c           	         d| d|g}t        j                  t         j                  |d       t        j	                  | |      \  }}}|j                  dd      }d| d| d| d	| d
g}t        j                  t         j                  |d       |||fg}|}t        j                  | |      D ]L  \  }}}t        j                  | ||      }	t        j                  |	|      dkD  r n|j                  |||f       N |d   \  }}}|j                  dd      }d| d| d| d	| d
g}t        j                  t         j                  |d       |S )zIReturns a list of (string, start, end) for lines of obj inside clip_rect.z!AXText: Getting visible lines forinsideTr   r   zAXText: First visible line inzis: 'r   r   r   r   ry   zAXText: Last visible line in)
r   r%   r   r
   find_first_visible_liner"   rY   r   r   r   )
r&   r   r.   rX   r=   r>   r-   r*   r'   r   s
             r/   get_visible_lineszAXText.get_visible_lines!  sm    6sHiP%**FD9!99#yIeS||D%013%~SQVPWWXY\X]]^8_`%**FD9$% & 0 0f = 	.D%--c5#>I&&y)<q@MM4,-		. "":eS||D%00#|nCPUwVWX[W\\]7^_%**FD9r8   c                    d}t         j                  |       }d|}}||k  r ||z   dz  }t         j                  | |      \  }}}	|dk(  r|||	fS |dk  r/d|g}
t        j                  t        j
                  |
d       |dz   }f|||	f}t         j                  | |dz
        \  }}}|dk  r|dk  r|S t         j                  | ||	      }t         j                  ||      dk  r|dz   }t         j                  ||      dkD  r|}t         j                  | ||      }t         j                  ||      dk7  r|S |||f}|}||k  r |S )zLReturns the first (string, start, end) visible line of obj inside clip_rect.r   r   r   z(AXText: Treating invalid offset as aboveTr   r
   r   rT   r   r%   r   r   r   )r&   r   r*   r(   lowhighmidrX   r=   r>   r.   previous_lineprevious_startprevious_end	text_rectprevious_rects                   r/   r   zAXText.find_first_visible_line;  s|    ++C0vTDj:!#C%88cBD%zUC''qyDiP!!%"2"2FDAAg5#%F:@:S:STWY^abYb:c7M><"|q'8--c5#>I&&y)<q@Ag&&y)<q@"11#~|TM&&}i@AE"NL@FD? DjB r8   c                    d}t         j                  |       }d|}}||k  r||z   dz  }t         j                  | |      \  }}}	|	|k\  r|||	fS |	dk  r,d|g}
t        j                  t        j
                  |
d       |}c|||	f}t         j                  | |	      \  }}}|dk  r|dk  r|S t         j                  | ||	      }t         j                  ||      dk  r|dz   }t         j                  ||      dkD  r|}t         j                  | ||      }t         j                  ||      dk7  r|S |||f}|dz   }||k  r|S )zKReturns the last (string, start, end) visible line of obj inside clip_rect.r   r   r   z(AXText: Treating invalid offset as belowTr   r   )r&   r   r*   r(   r   r   r   rX   r=   r>   r.   	next_line
next_startnext_endr   	next_rects                   r/   find_last_visible_linezAXText.find_last_visible_linee  sr    ++C0vTDj:!#C%88cBD%f}UC''axDiP!!%"2"2FDA5#%F.4.G.GS.Q+Iz8Q8q=--c5#>I&&y)<q@Ag&&y)<q@--c:xHI&&y)<A
H4F'C? DjB r8   c                     t         j                  | |      d   }|j                  d      dk(  ry|j                  d      dk(  ry|j                  d      dv ryy	)
z>Returns True if the text attributes indicate a spelling error.r   invalidspellingTztext-spelling
misspelled	underline)r+   r   F)r
   r   get)r&   r'   
attributess      r/   is_word_misspelledzAXText.is_word_misspelled  s[     99#vFqI
>>)$
2>>/*l:>>+&*??r8   c                     | dk(  S )u@   Returns True if character is an embedded object character (￼).u   ￼ )r<   s    r/   is_eoczAXText.is_eoc  s     H$$r8   c                 T    t         j                  t         j                  | |            S )uG   Returns True if character in obj is an embedded object character (￼).)r
   r   r0   )r&   r'   s     r/   character_at_offset_is_eocz!AXText.character_at_offset_is_eoc  s      }}V;;CHIIr8   c                 v    t        j                  |       syt        j                  |       j	                          S )z<Returns True if obj lacks text, or contains only whitespace.T)r   re   r
   r   stripr   s    r/   is_whitespace_or_emptyzAXText.is_whitespace_or_empty  s2     %%c*&&s+11333r8   c                    t         j                  |       }|sy|d}||dz
  }	 t        j                  j	                  | ||t        j
                  j                  ||      }d| d| d	| d
| d| d| g}	t        j                  t        j                  |	d       |S # t        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)z.Attempts to scroll obj to the specified point.FNr   r   z0AXText: Exception in scroll_substring_to_point: TAXText: Scrolledsubstring (r   ) tor   rd   )r
   r   r   r   scroll_substring_to_pointr   r   r   r   r   r   r%   )
r&   r4   r5   r#   r$   r(   r*   r+   r)   r.   s
             r/   r
  z AXText.scroll_substring_to_point  s     ++C0L!J	ZZ99\:u/E/Eq!MF %c[a
|SW+XCr!Bvh')%**FD9  	DUGLCu//d;	s   <B 	C&*CCc                 ~   t         j                  |       }|sy|d}||dz
  }	 t        j                  j	                  | |||      }d| d| d	| d
|d| g}t        j                  t        j                  |d       |S # t
        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w)zLAttempts to scroll the substring to the specified Atspi.ScrollType location.FNr   r   z3AXText: Exception in scroll_substring_to_location: Tr  r  r   r	  rd   )
r
   r   r   r   scroll_substring_tor   r   r   r   r%   )	r&   locationr#   r$   r(   r*   r+   r)   r.   s	            r/   scroll_substring_to_locationz#AXText.scroll_substring_to_location  s     ++C0L!J	ZZ33CzS[\F %c[a
|SW+XbM+%**FD9  	GwOCu//d;	s   "A? ?	B<*B77B<)N)r   )r   ry   )9__name__
__module____qualname____doc__staticmethodr0   r6   r?   rG   rJ   rN   rT   rV   rY   r]   r_   rb   rh   rk   rm   rp   rr   r   r   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r2   r   r   r   r   r   r   r   r   r   r  r  r
  r  r   r8   r/   r
   r
   /   s)   D!F !FF ; ; 0 0" F F> 6 6 + +" "F "FH 6 6 + +" F F> : : / /" 
 
 F F. ; ; 0 0" 
 
  "  "  " / /
 M M
  "  2  "   5 5
 = = - -      , . .8      ( ] ](  8  "  (  " A A    2 ' 'R ' 'R 
 
 % %
 J J
 4 4  2  r8   r
   )r  __id____version____date____copyright____license__girequire_versiongi.repositoryr   r   r   	ax_objectr   ax_utilitiesr   r
   r   r8   r/   <module>r     sT   , ; 	   7E "    %s sr8   