
    g
f#                        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
 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,                  eej.                        D ]  \  ZZ eeee         ej,                  eej.                        D ]  \  ZZ eeee         ej,                  eej.                        D ]!  \  ZZej7                  d      s eeee       # y)a  
Utilities for performing tasks related to accessibility inspection.
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$zCopyright (c) 2023 Igalia, S.L.LGPL    NAtspiz2.0)r      )debug)AXObject)AXUtilitiesCollection)AXUtilitiesRole)AXUtilitiesStatec                       e Zd ZdZdZed        Zedd       Zed        Zed        Z	ed        Z
edd       Zed	        Zed
        Zed        Zed        Zy)AXUtilitieszCUtilities for performing tasks related to accessibility inspection.Fc                      	 t        j                  d      } | S # t        $ r3}d|g}t        j                  t        j
                  |d       Y d}~yd}~ww xY w)zReturns the accessible desktopr   z,ERROR: Exception getting desktop from Atspi:TN)r   get_desktop	Exceptionr   printTokens
LEVEL_INFO)desktoperrortokenss      3/usr/lib/python3/dist-packages/orca/ax_utilities.pyr   zAXUtilities.get_desktop7   sU    	''*G   	DeLFe..=	s    	A)AAc                 |     t         j                         }|g S  fd}t        t        j                  ||            S )zReturns a list of running applications known to Atspi, filtering out
        those which have no child windows if must_have_window is True.c                 :    rt        j                  |       dkD  S y)Nr   T)r   get_child_count)objmust_have_windows    r   predz.AXUtilities.get_all_applications.<locals>.predM   s    //4q88    )r   r   listr   iter_children)r   r   r   s   `  r   get_all_applicationsz AXUtilities.get_all_applicationsD   s<    
 ))+?I	
 H**7D9::r   c                     t         j                         }|yt        j                  |      D ]	  }|| k(  s	 y d| d|g}t	        j
                  t        j                  |d       y)z%Returns true if app is known to AtspiFTzWARNING:	is not in)r   r   r   r   r   r   r   )appr   childr   s       r   is_application_in_desktopz%AXUtilities.is_application_in_desktopT   si     ))+?++G4 	E|	 c;8%**FD9r   c                     t         j                         }|yt        j                  |      D ]  }t        j                  |      | k(  s|c S  d| d|g}t        j                  t
        j                  |d       y)z9Returns the accessible application with the specified pidNzWARNING: app with pidr!   T)r   r   r   r   get_process_idr   r   r   )pidr   r"   r   s       r   get_application_with_pidz$AXUtilities.get_application_with_pidd   sw     ))+?))'2 	C&&s+s2
	 *3WE%**FD9r   c                 ,   t         j                  j                  t         j                  j                  gd d}t	        j
                  |       r)t        j                  |       }t        j                  s|S fd}t	        j                  | |      S )zBReturns all the descendants of obj that are static text leaf nodesc                 2    t        j                  | d      dv S )Ntag)N br)r   get_attribute)accs    r   is_not_elementzBAXUtilities.get_all_static_text_leaf_nodes.<locals>.is_not_elementy   s    ))#u59IIIr   Nc                 F    t        j                  |       v xr  |       S )N)r   get_role)r/   r0   roless    r   is_matchz<AXUtilities.get_all_static_text_leaf_nodes.<locals>.is_match   s#    $$S)U2J~c7JJr   )r   RoleSTATICTEXTr   supports_collectionr   find_all_with_roler   COMPARE_COLLECTION_PERFORMANCEfind_all_descendants)r   resultr4   r0   r3   s      @@r   get_all_static_text_leaf_nodesz*AXUtilities.get_all_static_text_leaf_nodest   sy     ""EJJOO4	J '',*==c5.YF==	K ,,S(;;r   c                    t        j                         |rEt        j                  j                  v r)j                  t        j                  j                         d}t        j                  |       rvst        j                  |       }nKt        j                  j                  t        j                  j                  g}t        j                  | |      }t        j                  s|S fd}t        j                   | |      S )z5Returns all the descendants of obj with a widget roleNc                     t        j                  |       vryr,t        j                  |       xr t        j                  |       S y)NFT)r   r2   r
   
is_showing
is_visible)r/   must_be_showing_and_visibler3   s    r   r4   z-AXUtilities.get_all_widgets.<locals>.is_match   sB      %U2*'2237\<L<W<WX[<\\r   )r	   get_widget_rolesr   r5   PUSH_BUTTONremover   r8   r   r9   	StateTypeSHOWINGVISIBLE!find_all_with_role_and_all_statesr   r:   r;   )r   rB   exclude_push_buttonr<   statesr4   r3   s    `    @r   get_all_widgetszAXUtilities.get_all_widgets   s      0025::#9#9U#BLL//0'',..AA#uM//115??3J3JK.PP( ==	 ,,S(;;r   c                     d}t        j                  |       r't        j                  |       }t        j
                  s|S t        j                  | t        j                        S )z,Returns the default button descendant of objN)	r   r8   r   find_default_buttonr   r:   find_descendantr	   is_default_buttonr   r<   s     r   get_default_buttonzAXUtilities.get_default_button   sN     '',*>>sCF==''_-N-NOOr   c                     d}t        j                  |       r't        j                  |       }t        j
                  s|S t        j                  | t        j                        S )z%Returns the focused descendant of objN)	r   r8   r   find_focused_objectr   r:   rO   r
   
is_focusedrQ   s     r   get_focused_objectzAXUtilities.get_focused_object   sO     '',*>>sCF==''-=-H-HIIr   c                     d}t        j                  |       r't        j                  |       }t        j
                  s|S t        j                  | t        j                        S )z(Returns the status bar descendant of objN)	r   r8   r   find_status_barr   r:   rO   r	   is_status_barrQ   s     r   get_status_barzAXUtilities.get_status_bar   sN     '',*::3?F==''_-J-JKKr   c                 b   t        j                  |       syt        j                  |       st        j                  | d      }| S t        j                  |       r+d| dg}t        j                  t        j                  |d       yt        j                  |       r+d| dg}t        j                  t        j                  |d       yt        j                  |       r+d| dg}t        j                  t        j                  |d       yt        j                  |       r+d| dg}t        j                  t        j                  |d       yt        j                  |       r+d| d	g}t        j                  t        j                  |d       yd| d
g}t        j                  t        j                  |d       y)zJReturns True if obj is a dialog that should be treated as a message dialogFT)rJ   zAXUtilities:z(is not a message dialog: has scroll panez'is not a message dialog: has split panez/is not a message dialog: has tree or tree tablez2is not a message dialog: has combo box or list boxz,is not a message dialog: has editable objectz"is believed to be a message dialog)r	   is_dialog_or_alertr   r8   r   rL   r   has_scroll_paner   r   r   has_split_panehas_tree_or_tree_tablehas_combo_box_or_list_boxhas_editable_object)r   widgetsr   s      r   is_message_dialogzAXUtilities.is_message_dialog   sv    11#6++C0!11#41PG; 005$c+UVFe..= //4$c+TUFe..= 77<$c+\]Fe..= ::3?$c+_`Fe..= 44S9$c+YZFe..= #'KL%**FD9r   N)F)TF)__name__
__module____qualname____doc__r:   staticmethodr   r   r$   r(   r=   rL   rR   rV   rZ   rc    r   r   r   r   2   s    M%*"
 
 ; ;     < <$ < <8 	P 	P 	J 	J 	L 	L % %r   r   )	predicatefind)rg   __id____version____date____copyright____license__inspectgirequire_versiongi.repositoryr   r,   r   	ax_objectr   ax_utilities_collectionr   ax_utilities_roler	   ax_utilities_stater
   r   
getmembers
isfunctionnamemethodsetattr
startswithri   r   r   <module>r      s  * 1  	   7E "    : . 0| |~ 'G&&'BTBTU 'LD&Kv&' 'G&&'77CUCUV 'LD&Kv&' 'G&&'<HZHZ[ +LD&vT6*+r   