
    g
f%A                         d Z dZdZdZdZdZddlZddlZ ej                  dd	       dd
l	m
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 ddlmZ ddlmZ  G d d      Z e       Zd Zy):Provides support for synthesizing accessible input events.z$Id$z
$Revision$z$Date$zQCopyright (c) 2005-2008 Sun Microsystems Inc.Copyright (c) 2018-2023 Igalia, S.L.LGPL    NAtspiz2.0)r   Gtkz3.0)r      )debug)focus_manager)AXComponent)AXObject)AXText)AXUtilitiesc                   P   e Zd ZdZ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$d       Zed$d       Zed$d       Zed$d       Zed$d       Zed$d       Zed$d       Zed$d       Zed$d       Zed$d       Zed$d       Zed$d       Zed%d       Zed%d       Zed%d       Zed        Zed        Zed&d       Zed%d       Z ed%d       Z!ed%d       Z"ed%d        Z#ed%d!       Z$ed%d"       Z%ed#        Z&y)'AXEventSynthesizerr   Nc                    t        j                         j                         }|+d}t        j                  t        j
                  |d       | |fS 	 t        j                  j                  |t        j                  j                        }d|j                   d|j                   }t        j                  t        j
                  |d       t        j                         j!                         j                         }|j#                         }|j$                  |j'                         z
  }d| d}t        j                  t        j
                  |d       | |j                  z   }	||j                  z   |z   }
d|  d	|	 d
| d	|
 }t        j                  t        j
                  |d       |	|
fS # t        $ r8}d| }t        j                  t        j
                  |d       | |fcY d }~S d }~ww xY w)NzEAXEventSynthesizer: Could not get active window to adjust coordinatesTz7AXEventSynthesizer: Exception in calling get_position: z,AXEventSynthesizer: Active window position: z, z5AXEventSynthesizer: Title bar height believed to be: pxzAXEventSynthesizer: x: z->z, y: )r	   
getManagerget_active_windowr   printMessage
LEVEL_INFOr   	Componentget_position	CoordTypeSCREEN	Exceptionxyr   Window
get_screenget_frame_extentsheight
get_height)r   r   active_windowmsgpointerror
gdk_windowframe_extentstitle_bar_heightnew_xnew_ys              ;/usr/lib/python3/dist-packages/orca/ax_event_synthesizer.py)_window_coordinates_to_screen_coordinatesz<AXEventSynthesizer._window_coordinates_to_screen_coordinates4   s    &002DDF YCu//d;a4K	OO00@V@VWE =UWWIRyQ5++S$7 ZZ\,,.@@B
"446(//*2G2G2IIEFVEWWYZ5++S$7EGGEGG..'s"UG52eWE5++S$7e|+  	KE7SCu//d;a4K	s   8F* *	G+3-G& G+&G+c                      t        j                         j                         j                         } | j	                         \  }}}}d|d|g}t        j                  t
        j                  |d       ||fS )z&Returns the current mouse coordinates.z&AXEventSynthesizer: Mouse coordinates:,T)r   r   r   get_root_windowget_pointerr   printTokensr   )root_windowwindowx_coordy_coord	modifierstokenss         r+   _get_mouse_coordinatesz)AXEventSynthesizer._get_mouse_coordinatesW   si     jjl--/??A.9.E.E.G+):GS'R%**FD9    c                    t         j                         \  }}d|d| d|g}t        j                  t        j                  |d       t         j                  | |      \  }}	 t        j                  |||      }d|g}t        j                  t        j                  |d       t        j                  d	       t         j                         \  }
}||
k(  r6||k(  r1||f||fk7  r(d
}t        j                  t        j                  |d       yy# t        $ r5}	d|	g}t        j                  t        j                  |d       d}Y d}	~	d}	~	ww xY w)z9Synthesize a mouse event at a specific screen coordinate.zAXEventSynthesizer: Generatingzmouse event atr.   Tz7AXEventSynthesizer: Atspi.generate_mouse_event returnedz7AXEventSynthesizer: Exception in _generate_mouse_event:FNr   zEAXEventSynthesizer: Mouse event possible failure. Pointer didn't move)r   r8   r   r1   r   r,   r   generate_mouse_eventr   timesleepprintln)r4   r5   eventold_xold_yr7   screen_xscreen_ysuccessr%   r)   r*   r#   s                r+   _generate_mouse_eventz(AXEventSynthesizer._generate_mouse_eventa   s3    *@@Bu2E;KWVY[bc%**FD9/YYW(	>008UKG PQXYFe..= 	

1)@@BuE>eun%HhCW1WYCMM%**C6%  	OQVWFe..=G	s   D 	E+E  Ec                     t        j                  |       }t        j                  |      ryt        j                  |       }t        j
                  ||      }t        j                  |      r.d| d|d|g}t        j                  t        j                  |d       yt        |j                  |j                  |j                  dz  z   dz
        }|j                  |j                  dz  z   }t        j                  |||      S )zCPerforms the specified mouse event on the current character in obj.FAXEventSynthesizer:z's caretz
not in objT   r   )r   get_character_rectr
   is_empty_rectget_rectget_rect_intersectionr   r1   r   maxr   r   widthr    r   rE   )objr?   extentsrectintersectionr7   r4   r5   s           r+   _mouse_event_on_characterz,AXEventSynthesizer._mouse_event_on_character   s     ++C0$$W-##C("88$G$$\2+S*g|UYZFe..=giigmma.?!@1!DE))gnnq00!77%PPr9   c                 `    t        j                  |       \  }}t        j                  |||      S )z*Performs the specified mouse event on obj.)r
   get_center_pointr   rE   )rO   r?   r4   r5   s       r+   _mouse_event_on_objectz)AXEventSynthesizer._mouse_event_on_object   s.     '77<!77%PPr9   c                     d| g}t        j                  t         j                  |d       t        j	                  | d      S )z3Routes the pointer to the current character in obj.z7AXEventSynthesizer: Attempting to route to character inTabs)r   r1   r   r   rS   rO   r7   s     r+   route_to_characterz%AXEventSynthesizer.route_to_character   s:     LSQ%**FD9!;;CGGr9   c                     d| g}t        j                  t         j                  |d       t        j	                  | d      S )z-Moves the mouse pointer to the center of obj.z*AXEventSynthesizer: Attempting to route toTrX   )r   r1   r   r   rV   rY   s     r+   route_to_objectz"AXEventSynthesizer.route_to_object   s9     ?D%**FD9!88eDDr9   c                 0    t         j                  | |d      S )z0Routes the pointer to the specified coordinates.rX   r   rE   )r4   r5   s     r+   route_to_pointz!AXEventSynthesizer.route_to_point   s     "77%PPr9   c                 6    t         j                  | d| d      S )zHSingle click on the current character in obj using the specified button.bcr   rS   rO   buttons     r+   click_characterz"AXEventSynthesizer.click_character        ";;C1VHAOOr9   c                 6    t         j                  | d| d      S )z/Single click on obj using the specified button.ra   rb   r   rV   rd   s     r+   click_objectzAXEventSynthesizer.click_object        "88&mLLr9   c                 8    t         j                  | |d| d      S )z;Single click on the given point using the specified button.ra   rb   r^   r4   r5   re   s      r+   click_pointzAXEventSynthesizer.click_point   "     "77AfXUV-XXr9   c                 6    t         j                  | d| d      S )zHDouble click on the current character in obj using the specified button.ra   drc   rd   s     r+   double_click_characterz)AXEventSynthesizer.double_click_character   rg   r9   c                 6    t         j                  | d| d      S )z/Double click on obj using the specified button.ra   rq   ri   rd   s     r+   double_click_objectz&AXEventSynthesizer.double_click_object   rk   r9   c                 8    t         j                  | |d| d      S )z;Double click on the given point using the specified button.ra   rq   r^   rm   s      r+   double_click_pointz%AXEventSynthesizer.double_click_point   ro   r9   c                 6    t         j                  | d| d      S )zLPerforms a press on the current character in obj using the specified button.ra   prc   rd   s     r+   press_at_characterz%AXEventSynthesizer.press_at_character   rg   r9   c                 6    t         j                  | d| d      S )z3Performs a press on obj using the specified button.ra   rx   ri   rd   s     r+   press_at_objectz"AXEventSynthesizer.press_at_object   rk   r9   c                 8    t         j                  | |d| d      S )z?Performs a press on the given point using the specified button.ra   rx   r^   rm   s      r+   press_at_pointz!AXEventSynthesizer.press_at_point   ro   r9   c                 6    t         j                  | d| d      S )zNPerforms a release on the current character in obj using the specified button.ra   rrc   rd   s     r+   release_at_characterz'AXEventSynthesizer.release_at_character   rg   r9   c                 6    t         j                  | d| d      S )z5Performs a release on obj using the specified button.ra   r   ri   rd   s     r+   release_at_objectz$AXEventSynthesizer.release_at_object   rk   r9   c                 8    t         j                  | |d| d      S )zAPerforms a release on the given point using the specified button.ra   r   r^   rm   s      r+   release_at_pointz#AXEventSynthesizer.release_at_point   ro   r9   c                 
   t        j                  |       }t        j                  | |||      st        j                  | |       t        j                  |       }d|d|g}t        j                  t
        j                  |d       y)z-Attempts to scroll to the specified location."AXEventSynthesizer: Before scroll:After scroll:TN)r
   r   r   scroll_substring_to_locationscroll_object_to_locationr   r1   r   )rO   locationstart_offset
end_offsetbeforeafterr7   s          r+   _scroll_to_locationz&AXEventSynthesizer._scroll_to_location   sp     ))#.223,PZ[11#x@((-6QVW%**FD9r9   c                    t        j                  |       }t        j                  | ||||      st        j                  | ||       t        j                  |       }d|d|g}t        j                  t
        j                  |d       y)z.Attempts to scroll obj to the specified point.r   r   TN)r
   r   r   scroll_substring_to_pointscroll_object_to_pointr   r1   r   )rO   r4   r5   r   r   r   r   r7   s           r+   _scroll_to_pointz#AXEventSynthesizer._scroll_to_point  st     ))#.//Wg|U_`..sGWE((-6QVW%**FD9r9   c                 d    t         j                  | t        j                  j                  ||       y)z!Attempts to scroll obj into view.N)r   r   r   
ScrollTypeANYWHERErO   r   r   s      r+   scroll_into_viewz#AXEventSynthesizer.scroll_into_view  (     	..!!**L*	Fr9   c                     t        j                  | t        j                        }|r3t        j                  |t        j                        }|||k(  r	 |S |}|r3|S )z#Returns the document containing obj)r   find_ancestorr   is_document)rO   documentancestors      r+   _containing_documentz'AXEventSynthesizer._containing_document  sa     ))#{/F/FG--h8O8OPH8x#7   H	  r9   c                    t         j                  |       }|s+d| dg}t        j                  t        j                  |d       yt        j                  |      s+d| dg}t        j                  t        j                  |d       yt        j                  |       }t        j                  |      }t        j                  ||j                  |j                        }t        j                  ||j                  |j                  z   |j                        }|r|r||cxk(  r|k7  s,n d| g}t        j                  t        j                  |d       yd| d|g}t        j                  t        j                  |d       |S )z,"Returns the banner obscuring obj from view.z1AXEventSynthesizer: No obscuring banner found forz. No document.TNz. No doc iface.rG   z!believed to be obscured by banner)r   r   r   r1   r   r   supports_componentr
   rK   get_descendant_at_pointr   r   rN   )rO   r   r7   obj_rectdoc_rectleftrights          r+   _get_obscuring_bannerz(AXEventSynthesizer._get_obscuring_banner&  s<    &::3?I3P`aFe..=**84I3PabFe..='',''1228XZZT33hjj8>>18::?45#<H#<I3OFe..='.QSWX%**FD9r9   c                 $   t        j                  |       }t        j                  |      }d|g}t        j                  t        j                  |d       t
        j                  | |j                  |j                  |j                  z   |z   ||       y)z$Attempts to scroll obj below banner.z'AXEventSynthesizer: Extents of banner: TN)
r
   rK   r   r1   r   r   r   r   r   r    )rO   bannerr   r   marginr   banner_rectr7   s           r+   _scroll_below_bannerz'AXEventSynthesizer._scroll_below_bannerC  sy     '',!**62;[I%**FD9++[]][-?-??&H,Xb	dr9   c                    t         j                  rt        j                  t         j                        s_dt         j                   }t	        j
                  t        j                  |d       t         j                  | t         j                  ||       yt         j                  | t        j                  j                  ||       t         j                  |       t         _        t         j                  rRd|  d}t         j                  | t         j                  ||       t	        j
                  t        j                  |d       yy)z'Attempts to scroll obj to the top edge.z5AXEventSynthesizer: Suspected existing banner found: TNz!AXEventSynthesizer: Re-scrolling z due to banner)r   _bannerr   is_deadr   r>   r   r   r   r   r   TOP_EDGEr   )rO   r   r   r#   s       r+   scroll_to_top_edgez%AXEventSynthesizer.scroll_to_top_edgeO  s     %%h.>.>?Q?Y?Y.ZG%--.0  MM%**C633'//zK..!!**L*	F &8%M%Mc%R"%%5cU.IC33'//zKMM%**C6	 &r9   c                 d    t         j                  | t        j                  j                  ||       y)z'Attempts to scroll obj to the top left.N)r   r   r   r   TOP_LEFTr   s      r+   scroll_to_top_leftz%AXEventSynthesizer.scroll_to_top_leftg  r   r9   c                 d    t         j                  | t        j                  j                  ||       y)z(Attempts to scroll obj to the left edge.N)r   r   r   r   	LEFT_EDGEr   s      r+   scroll_to_left_edgez&AXEventSynthesizer.scroll_to_left_edgen  s(     	..!!++\:	Gr9   c                 d    t         j                  | t        j                  j                  ||       y)z*Attempts to scroll obj to the bottom edge.N)r   r   r   r   BOTTOM_EDGEr   s      r+   scroll_to_bottom_edgez(AXEventSynthesizer.scroll_to_bottom_edgeu  s(     	..!!--|Z	Ir9   c                 d    t         j                  | t        j                  j                  ||       y)z+Attempts to scroll obj to the bottom right.N)r   r   r   r   BOTTOM_RIGHTr   s      r+   scroll_to_bottom_rightz)AXEventSynthesizer.scroll_to_bottom_right|  s(     	..!!..j	Jr9   c                 d    t         j                  | t        j                  j                  ||       y)z)Attempts to scroll obj to the right edge.N)r   r   r   r   
RIGHT_EDGEr   s      r+   scroll_to_right_edgez'AXEventSynthesizer.scroll_to_right_edge  s(     	..!!,,lJ	Hr9   c                 b   g d}|D ]F  }t        j                  | |      sd|d| dg}t        j                  t        j                  |d        y t        j                  t        j
                  k  ryd| dt        j                  |       g}t        j                  t        j                  |d       y)	z<Attempts to perform a click-like action if one is available.)clickpressjumpopenzAXEventSynthesizer: 'z' onzperformed successfullyTFzAXEventSynthesizer: Actions on:)r   do_named_actionr   r1   r   
debugLevelactions_as_string)rO   actionsactionr7   s       r+   try_all_clickable_actionsz,AXEventSynthesizer.try_all_clickable_actions  s     5 	F''V41663H`a!!%"2"2FDA		 e...2Ch>X>XY\>]^%**FD9r9   )r   )NN)   )'__name__
__module____qualname____doc__r   staticmethodr,   r8   rE   rS   rV   rZ   r\   r_   rf   rj   rn   rr   rt   rv   ry   r{   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r9   r+   r   r   /   s   DG   D      @ Q Q$ Q Q H H E E Q Q
 P P
 M M
 Y Y
 P P
 M M
 Y Y
 P P
 M M
 Y Y
 P P
 M M
 Y Y
 	: 	: 	: 	: F F 
 
  8 	d 	d 7 7. F F G G I I J J H H  r9   r   c                      t         S )N)_synthesizerr   r9   r+   getSynthesizerr     s    r9   )r   __id____version____date____copyright____license__r<   girequire_versiongi.repositoryr   r    r   r	   ax_componentr
   	ax_objectr   ax_textr   ax_utilitiesr   r   r   r   r   r9   r+   <module>r      s   * A7  	   7E "    5%      %   %k kZ "#r9   