+
    QiN  c                  s    R t ^ RIHt RtRtRtRtRt^ RIH	t	 ^RI
Ht ^R	IHt ^R
IHt ^RIHt ^RIHt ^RIHt ^RIHt ]	'       d$   ^ RIt]P2                  ! RR4       ^ RIHt ^RIHt  ! R R4      tR# )DHeuristic means to infer the functional/displayed label of a widget.)annotationsz$Id$z
$Revision$z$Date$z$Copyright (C) 2011-2013 Igalia, S.L.ZLGPL)TYPE_CHECKING)debug)AXComponent)AXHypertext)AXObject)AXTable)AXText)AXUtilitiesNAtspiz2.0)r
   )defaultc                  s   ] tR t^7tRtR R ltR(R R lltR R ltR R	 ltR
 R lt	R R lt
R R ltR R ltR R ltR R ltR)R R lltR R ltR*R R lltR+R R lltR,R R lltR-R  R! lltR-R" R# lltR.R$ R% lltR&tR'# )/LabelInferencer    c                    V ^8  d   QhRRRR/# )   scriptzdefault.ScriptreturnNone Zformat   "9/usr/lib/python3.14/site-packages/orca/label_inference.py__annotate__LabelInference.__annotate__:   s     4 4~ 4$ 4    c                	s<    Wn         / V n        / V n        / V n        R # N)_script_line_cache_extents_cache_is_widget_cache)selfr      &&r   __init__ZLabelInference.__init__:   s    TVUW13r   c               $    V ^8  d   QhRRRRRR/# )r   objAtspi.Accessiblefocused_onlyboolr   )tuple[str | None, list[Atspi.Accessible]]r   r   r   r   r   r   @   s(     9 99 9 
3	9r   c                s   RV.p\         P                  ! \         P                  VR4       V'       g   R. 3# V'       dL   \        P                  ! V4      '       g0   RVR.p\         P                  ! \         P                  VR4       R. 3# Rp. pV'       g>   V P                  V4      w  rE\         P                  ! \         P                  RV R2R4       V'       d   V P                  V4      '       dK   V P                  V4      pV^ ,          e   Vw  rE\         P                  ! \         P                  RV R2R4       V'       g>   V P                  V4      w  rE\         P                  ! \         P                  R	V R2R4       V'       g>   V P                  V4      w  rE\         P                  ! \         P                  R
V R2R4       V'       g>   V P                  V4      w  rE\         P                  ! \         P                  RV R2R4       V'       gB   \        P                  ! V4      . rT\         P                  ! \         P                  RV R2R4       V'       d#   VP                  4       pVP                  RR4      pV'       g@   V P                  V^R7      w  rE\         P                  ! \         P                  RV R2R4       V P!                  4        WE3# )z7Attempt to infer the functional/displayed label of obj.z LABEL INFERENCE: Infer label forTNzLABEL INFERENCE:zis not focusedzLABEL INFERENCE: Text Left: 'Z'zLABEL INFERENCE: Text Right: 'zLABEL INFERENCE: Table: 'zLABEL INFERENCE: Text Above: 'zLABEL INFERENCE: Text Below: 'zLABEL INFERENCE: Name: '
Z )	proximityz3LABEL INFERENCE: Text Left with proximity of 200: ')r   Zprint_tokensZ
LEVEL_INFOr	   Z
is_focused_infer_from_text_leftZprint_message_prefer_right_infer_from_text_right_infer_from_table_infer_from_text_above_infer_from_text_belowr   Zget_namestripZreplace_clear_cache)r   r"   r$   ZtokensresultobjectsZtemp_results   &&&    r   inferZLabelInference.infer@   ss    5c:5++VT:8O 6 6s ; ;(#/?@Fu//>8O!*,"88=OF 0 04QRXQYYZ2[]ab++C0055c:K1~)"- 0 04RSYRZZ[2\^bc"44S9OF 0 04MfXUV2WY]^"99#>OF 0 04RSYRZZ[2\^bc"99#>OF 0 04RSYRZZ[2\^bc &//4bG 0 04LVHTU2VX\]\\^F^^D#.F "888LOF  EfXQOQUW 	r   c               s    V ^8  d   QhRR/# )r   r   r   r   r   r   r   r   r   {   s     # #d #r   c                s0    / V n         / V n        / V n        R# )z5Dumps whatever we've stored for performance purposes.N)r   r   r   )r      &r   r0   ZLabelInference._clear_cache{   s       "r   c               r   r   r"   r#   r   r%   r   r   r   r   r   r      s     Q Q!1 Qd Qr   c                j    \         P                  ! V4      ;'       g    \         P                  ! V4      # )z3Returns True if we should prefer text on the right.)r	   Zis_check_boxZis_radio_buttonr   r"   r   r   r*   ZLabelInference._prefer_right   s(     '',PP0K0KC0PPr   c               r   r5   r   r   r   r   r   r      s     M M"2 Mt Mr   c                r6   )zQReturns True if we should not permit inference based on text to the right of obj.r	   Zis_combo_boxZis_list_boxr7   r   r   _prevent_rightZLabelInference._prevent_right   (     '',LL0G0G0LLr   c               r   r5   r   r   r   r   r   r      s     M M/ MD Mr   c                r6   )zGReturns True if we should prefer text above, rather than below for obj.r8   r7   r   r   _prefer_topZLabelInference._prefer_top   r:   r   c               r   r5   r   r   r   r   r   r      s     2 2"2 2t 2r   c                s8    \         P                  ! V4      '       * # )zGReturns True if we should not permit inference based on text below obj.)r	   is_text_inputr7   r   r   _prevent_belowZLabelInference._prevent_below   s     ,,S111r   c               r   r   r"   Atspi.Accessible | Noner   r%   r   r   r   r   r   r      s      %<  r   c                s    Vf   R# R R lp\        \        P                  ! W4      4      p\        V4      ^8  d   R# \        P
                  ! V4      P                  4       pVP                  R4      ^8  d   R# R# )z7Returns True if the given object has 'simple' contents.Fc               r   r   xr#   r   r%   r   r   r   r   r   Z6LabelInference._is_simple_object.<locals>.__annotate__   s     	P 	P( 	PT 	Pr   c                st    \         P                  ! V 4      ;'       d    \         P                  ! V 4      '       * # r   )r	   Zis_web_elementZis_link)rA   r4   r   is_matchZ2LabelInference._is_simple_object.<locals>.is_match   s)    --a0OO9L9LQ9O5OOr   u   ￼T)listr   Ziter_childrenlenr   Zget_all_textr/   Zcount)r   r"   rB   Zchildrenstrings   &&   r   _is_simple_objectZ LabelInference._is_simple_object   sh     ;	P ..s=>x=1$$S)//1<<!A%r   c               r   r>   r   r   r   r   r   r      s     	$ 	$!8 	$T 	$r   c                s    Vf   R# \         P                  ! V4      '       g   \         P                  ! V4      '       d   R# V P                  V4      # )zBReturns True if the given object should not be treated as a label.T)r	   Z
is_headingZis_list_item
_is_widgetr7   r   r   _cannot_labelZLabelInference._cannot_label   s?     ;!!#&&+*B*B3*G*Gs##r   c               r   r>   r   r   r   r   r   r      s      5 $ r   c                sH   Vf   R# V P                   P                  \        V4      4      pVe   V# \        P                  ! V4      ;'       g    \        P
                  ! V4      pV'       g   \        P                  ! V4      '       d   RpW0P                   \        V4      &   V# )z-Returns True if the given object is a widget.FT)r   gethashr	   	is_widgetZis_menu_relatedZis_editable)r   r"   rvrK   s   &&  r   rG   ZLabelInference._is_widget   s     ;""&&tCy1>I))#.RR+2M2Mc2R	[44S99I+4d3i(r   c               s(    V ^8  d   QhRRRRRRRR/# )r   r"   r?   start_offsetint
end_offsetr   ztuple[int, int, int, int]r   r   r   r   r   r      s2      $  	
 
#r   c                s   Vf   R# V P                   P                  \        V4      W#34      pV'       d   V# Rp\        P                  ! V4      '       d   \
        P                  ! V4      '       gc   VR8X  d   \        P                  ! V4      p\        P                  ! WV4      pVP                  VP                  VP                  VP                  3pV^,          '       d   V^,          '       gE   \        P                  ! V4      pVP                  VP                  VP                  VP                  3pWPP                   \        V4      W#3&   V# )z?Returns (x, y, width, height) of the text at the given offsets.)    rP   rP   rP   )r   rI   rJ   r   Zsupports_textr	   r<   r   Zget_character_countZget_range_rectrA   yZwidthheightr   Zget_rect)r   r"   rM   rO   rL   extentsZrectZexts   &&&&    r   _get_extentsZLabelInference._get_extents   s     ;  $$d3i%JKI!!#&&,,S11#!'!;!;C!@J,,S
K&&$&&$**dkkA

wqzz&&s+CeeSUUCIIszz9GELT#YABr   c               r   )r   r"   r#   r   r&   r   r   r   r   r   r      s     ) )) 
3)r   c                s   V P                  V4      '       g   R. 3# V P                  V4      '       d   R. 3# V P                  P                  P	                  VRR7      pV Uu. uF  q3^ ,          NK  	  pp\        \        V P                  V4      4      '       d   R. 3# V Uu. uF  q3^,          NK  	  ppRP                  V4      V3# u upi u upi )z>Gets the functional label text associated with the object obj.NF)Z	use_cache )	rF   rH   r   	utilitiesZget_object_contents_at_offsetrC   filterrG   join)r   r"   contentscontentr2   stringss   &&    r   _create_label_from_contentsZ*LabelInference._create_label_from_contents   s     %%c**8Oc""8O<<))GGW\G]-56X'1::X6t0118O-56X'1::X6www(( 7 7s   "C"Cc               r!   )r   r"   r#   startrN   r   z,list[tuple[Atspi.Accessible, int, int, str]]r   r   r   r   r   r      s(        
6	r   c                st   V P                   P                  \        V4      4      pV'       d   V# \        V4      pV P                  V4      '       d-   \        P
                  ! V4      p\        P                  ! V4      pV P                  P                  P                  WRR4      pVf   . pW0P                   V&   V# )zSGet the (obj, start_offset, end_offset, string) tuples for the line containing obj.TF)r   rI   rJ   rG   r   Zget_link_start_offsetr   
get_parentr   rW   Zget_line_contents_at_offset)r   r"   r^   rL   Zkeys   &&&  r   _get_line_contentsZ!LabelInference._get_line_contents   s     !!$s),I3i??355c:E%%c*C\\##??DRWX:B "	r   c               r!   r   r"   r#   r(   rN   r   r&   r   r   r   r   r   r     (     % %% % 
3	%r   c                s   V P                  V4      pV P                  V4      pV Uu. uF  qU^ ,          V8X  g   K  VNK  	  pp VP                  V^ ,          4      pV^ V p^ p	\        \	        V4      ^,
          RR4       FV  p
W,          w  rrV P                  V4      pV^ ,          V^ ,          8  g   V P                  V4      '       g   KM  V
^,           p	 M	  WR pV'       d   V^ ,          '       g   R. 3# VR,          w  rppV P                  WV4      pV^ ,          V^ ,          V^,          ,           ,
          p^ Tu;8:  d   V8:  d_   M R. 3# V Uu. uF  qf^,          NK  	  ppRP                  V4      P                  4       pV'       d   TV Uu. uF  qf^ ,          NK  	  up3# R. 3# u upi   \         d    \	        T4      p ELpi ; iu upi u upi )zQAttempt to infer the functional/displayed label of obj from contents on its left.NrV   rQ   )	rU   r`   index
IndexErrorrD   rangerH   rY   r/   )r   r"   r(   rT   rZ   or[   rc   Zon_leftr^   iZleft_objZ_left_startZ	_left_endZ_left_stringZleft_extentsend_stringdistancer\   r1   s   &&&                  r   r)   Z$LabelInference._infer_from_text_left  s    ##C(**3/&6hA$#+11h6	"NN71:.E 1U#s7|a'R0A=DZ:H9,,X6LA+t/A/A(/K/KA 1 &/GAJJ8O(/%g((#>1:a<?!BC%I% Rx 299gqzzG9WWW%++-F'B'w

'BBBRx9 7  	"ME	"( :  Cs(   F.F.F3 GG3GGc               r!   ra   r   r   r   r   r   r   5  s(     ( (( ( 
3	(r   c                s   V P                  V4      '       d   R. 3# V P                  V4      pV P                  V4      pV Uu. uF  qU^ ,          V8X  g   K  VNK  	  pp VP                  V^ ,          4      pV\        \        V4      V^,           4      R p\        V4      p	\        V4       FK  w  rV P                  V^ ,          4      '       g   K%  V P                  V4      '       g   R. 3u # V
^,           p	 M	  V^ V	 pV'       d   V^ ,          '       g   R. 3# V^ ,          w  rrV P                  WV	4      pV^ ,          V^ ,          V^,          ,           ,
          pVV8:  g   V P                  V4      '       dY   V Uu. uF  qf^,          NK  	  ppRP                  V4      P                  4       pV'       d   TV Uu. uF  qf^ ,          NK  	  up3# R. 3# u upi   \         d    \        T4      p ELi ; iu upi u upi )zRAttempt to infer the functional/displayed label of obj from contents on its right.NrV   )r9   rU   r`   rc   rd   rD   ZminZ	enumeraterH   r*   rY   r/   )r   r"   r(   rT   rZ   rf   r[   rc   Zon_rightrh   rg   ZitemZ	right_objr^   ri   Zright_extentsrj   r\   r1   s   &&&                r   r+   Z%LabelInference._infer_from_text_right5  s    s##8O##C(**3/&6hA$#+11h6	"NN71:.E CHuQw789(m *GA!!$q'**))#..8O!e + Ac?Xa[[8O(0%	#)))C@ #wqzGAJ'>?y D$6$6s$;$;19:gqzzG:WWW%++-F(C(w

(CCCRx9 7  	"ME	"( ;  Ds*   GGG  G:?G?G76G7c               r!   ra   r   r   r   r   r   r   _  rb   r   c                sV   V P                  V4      pV Uu. uF  qD^ ,          V8X  g   K  VNK  	  pp VP                  V^ ,          4      pT^ 8  d   R. 3# T P                  P                  P                  T^ ,          ^ ,          T^ ,          ^,          R4      w  rxT P                  Yx4      p	\        T	4      ^8w  d   R. 3# T	^ ,          w  rzrT P                  T4      '       d   R. 3# TP                  R4      '       d   TRR pT^,          pTP                  4       '       dl   T P                  YzT4      w  rppT P                  T4      w  ppppTTT,           ,
          p^ Tu;8:  d   T8:  d!   M R. 3# TT8:  d   TP                  4       T.3# R. 3# u upi   \         d    R. 3u # i ; i)zNAttempt to infer the functional/displayed label of obj from contents above it.NTr'   rQ   )r`   rc   rd   r   rW   Zprevious_contextrD   rH   Zendswithr/   rU   )r   r"   r(   	this_linerf   r[   rc   Zprev_objZprev_offsetZ	prev_liner^   rh   rE   rA   rR   _widthrS   obj_xobj_y
_obj_widthZ_obj_heightrj      &&&                   r   r-   Z%LabelInference._infer_from_text_above_  s    ++C0	'7iQ43;11i7	OOGAJ/E 198O $ 6 6 G GaLOYq\!_d!4++HB	y>Q8O'0|$h''8O??4  CR[F1HC<<>>#'#4#4Xc#J A&&484E4Ec4J1E5*kF
+HH)	) Rx /05j||~z11Rx; 8  	8O	s   FFF F('F(c               r!   ra   r   r   r   r   r   r     s(     $ $$ $ 
3	$r   c                sB   V P                  V4      '       d   R. 3# V P                  V4      pV Uu. uF  qD^ ,          V8X  g   K  VNK  	  pp VP                  V^ ,          4      pT^ 8  d   R. 3# T P                  P
                  P                  TR,          ^ ,          TR,          ^,          ^,
          R4      w  rxT P                  Yx4      p	\        T	4      ^8w  d   R. 3# T	^ ,          w  rzrT P                  T4      '       d   R. 3# TP                  4       '       de   T P                  YzT4      w  rppT P                  T4      w  ppppTTT,           ,
          p^ Tu;8:  d   T8:  d   M R. 3# TP                  4       T.3# R. 3# u upi   \         d    R. 3u # i ; i)zNAttempt to infer the functional/displayed label of obj from contents below it.NTrQ   )r=   r`   rc   rd   r   rW   Znext_contextrD   rH   r/   rU   )r   r"   r(   rk   rf   r[   rc   Znext_objZnext_offsetZ	next_liner^   rh   rE   Z_xrR   rl   _heightZ_obj_xrn   ro   
obj_heightrj   rp   r   r.   Z%LabelInference._infer_from_text_below  s    s##8O++C0	'7iQ43;11i7	OOGAJ/E 198O $ 6 6 C CbM!imA.2D!:++HB	y>Q8O'0|$h''8O<<>>%)%6%6x%L"B67484E4Ec4J1FE:zEJ./HH)	) Rx ||~z11Rx3 8  	8O	s   FFF FFc               r!   )r   r"   r#   proximity_for_rightrN   r   r&   r   r   r   r   r   r     s-     i ii !i 
3	ir   c                s  a \         P                  ! S\        P                  4      pV P	                  V4      '       g   R. 3# \         P
                  ! S4      pW4\         P
                  ! V4      39  d   R. 3# \         P                  ! V\        P                  4      pV'       g   R. 3# R;p;p;r\         P                  ! V\        P                  4      p
\        P                  ! VRR7      w  rVR8  d{   \        P                  ! W[V^,
          4      p\        P                  ! W[V^,           4      p\        P                  ! W[^,
          V4      p\        P                  ! W[^,           V4      p	EM1V
'       Ed)   \         P
                  ! V4      V
8X  Ed   \         P                  ! V4      p\         P                  ! W^,
          4      p\         P                  ! W^,           4      p\         P                  ! V
4      p\         P
                  ! V
4      pV^ 8  d4   \         P                  ! W^,
          4      p\         P                  ! W4      pV^,           \         P                  ! V4      8  d5   \         P                  ! W^,           4      p\         P                  ! VV4      p	V'       dF   V P                  S4      '       g/   V P                  V4      w  ppV'       d   VP!                  4       V3# V P#                  S4      w  ppppV'       d   V P%                  S4      '       gs   V P#                  V4      w  ppppVVV,           ,
          pVV8:  g   V P                  S4      '       d/   V P                  V4      w  ppV'       d   VP!                  4       V3# Rp. pV'       dF   V P                  V4      w  ppV'       d*   V P'                  S4      '       d   VP!                  4       V3# Rp. pV	'       d,   V P)                  S4      '       g   V P                  V	4      w  ppV'       d   V'       dx   V P#                  V4      w  p p!p"p#V P#                  V	4      w  p$p%p&p'VV!V#,           ,
          p(V%VV,           ,
          p)V(V)8:  d   VP!                  4       V3# VP!                  4       V3# V'       d   VP!                  4       V3# V'       d   VP!                  4       V3# \        P*                  ! V4      p*\-        V*4       U+u. uF  p+\        P                  ! V^ V+4      NK  	  p,p+V,'       d&   \/        \1        V P2                  V,4      4      '       d   R. 3# V^ 8  d   R. 3# R V3R llp-\        P4                  ! V4      p.\-        ^V.4       U+u. uF  p+\        P                  ! VV+V4      NK  	  p/p+\/        \1        V-V/4      4      '       d   R. 3# V P                  V,V,          4      w  ppV'       d   VP!                  4       V3# R. 3# u up+i u up+i )zNAttempt to infer the functional/displayed label of obj from neighboring cells.NF)Zprefer_attributec               r   r@   r   r   r   r   r   Z6LabelInference._infer_from_table.<locals>.__annotate__  s     	Q 	Q( 	QT 	Qr   c                s   < \         P                  ! V 4      '       g   R # \        P                  ! \         P                  ! V ^ 4      S4      '       * # )F)r   get_child_countr	   Zhave_same_role	get_child)rA   r"   s   &r   rB   Z2LabelInference._infer_from_table.<locals>.is_match  s:    ++A.."11(2D2DQ2JCPPPr   rQ   )r   Zfind_ancestorr	   Zis_table_cellrF   r_   Zis_tableZis_table_rowr   Zget_cell_coordinatesZget_cell_atZget_index_in_parentru   rt   r*   r]   r/   rU   r9   r;   r=   Zget_column_countre   rC   rX   rG   Zget_row_count)0r   r"   rs   ZcellZparentZgridZ	cell_leftZ
cell_rightZ
cell_aboveZ
cell_belowZgridrowZrowindexZcolindexZ	cellindexZgridrow_parentZ	row_aboveZ	row_belowZlabelZsourcesrm   rn   Z	obj_widthrr   rA   Z_yrl   rq   rj   Zlabel_aboveZsources_aboveZlabel_belowZsources_belowZ_above_xZabove_yZ_above_widthZabove_heightZ_below_xZbelow_yZ_below_widthZ_below_heightZdelta_aboveZdelta_belowZcolumnsrg   Z	first_rowrB   ZrowsZcellss0   &f&                                             r   r,   Z LabelInference._infer_from_table  s    %%c;+D+DE%%d++8O$$S) 3 3F ;<<8O%%dK,@,@A8O;??	?J?(({/G/GH$99$QVWb=++DHqLII ,,TX\JJ ,,Ta<JJ ,,Ta<JJW,,T2g= 44T:I **7MBI!++G]CJ33G<H%009N!|$..~!|L	%//	E
!|h66t<<$..~!|L	%//	9E
T//44!==iHNE7{{}g--.2.?.?.D+uid11#66%)%6%6z%B"Ar67EI-.H..$2D2DS2I2I!%!A!A*!Mw ;;='11"&02)-)I)I*)U&Kt//44"((*M99"&02d11#66)-)I)I*)U&K;<@<M<Mj<Y9Hg|\=A=N=Nz=Z:Hg|]7\#9:K!UZ%78Kk)"((*M99$$&55$$&55$$&55
 **40>CGnMnW((q!4n	MD!CDD8Oa<8O	Q 	Q
 $$T*AFq$PA$$T1h7Px'((8O99)H:MNw;;='))Rx+ N Qs   ;!X!X)r   r   r   r   N)T)rP   rQ   )rP   )iK   )i   )i   )i2   )Z__name__Z
__module__Z__qualname__Z__firstlineno____doc__r    r3   r0   r*   r9   r;   r=   rF   rH   rG   rU   r]   r`   r)   r+   r-   r.   r,   Z__static_attributes__r   r   r   r   r   7   sn    N49v#Q
M
M
2
&	$"<)(.%N(T%N$Li ir   r   )rv   Z
__future__r   Z__id__Z__version__Z__date__Z__copyright__Z__license__Ztypingr   rV   r   Zax_componentr   Zax_hypertextr   Z	ax_objectr   Zax_tabler   Zax_textr   Zax_utilitiesr	   ZgiZrequire_versionZgi.repositoryr
   Zscriptsr   r   r   r   r   <module>rw      si   8 K #6    % %    %w&# ^ ^r   