
    g
f                         d Z dZdZdZdZdZddlZddlZddlZddl	Z	 e	j                  dd	       dd
lmZ ddlmZ  G d d      Zej!                          y)a  
Utilities for obtaining information about accessible objects.
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      )debugc                   t   e Zd ZdZi Zi Zi Zi Z ej                         Z
ed        ZedUd       ZedUd       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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dVd'       Z0ed(        Z1ed)        Z2ed*        Z3ed+        Z4ed,        Z5ed-        Z6ed.        Z7ed/        Z8ed0        Z9edWd1       Z:ed2        Z;ed3        Z<ed4        Z=ed5        Z>ed6        Z?ed7        Z@ed8        ZAed9        ZBed:        ZCed;        ZDedWd<       ZEed=        ZFedWd>       ZGed?        ZHed@        ZIedA        ZJedB        ZKedXdC       ZLedD        ZMedE        ZNedYdF       ZOedYdG       ZPedH        ZQedI        ZRedJ        ZSedK        ZTedL        ZUedM        ZVedN        ZWedO        ZXedP        ZYedQ        ZZedR        Z[edS        Z\edT        Z]y&)ZAXObjectz=Utilities for obtaining information about accessible objects.c                  X    	 t        j                  d       t        j                          *)z*Clears any data we have cached for objects<   )timesleepr   _clear_all_dictionaries     0/usr/lib/python3/dist-packages/orca/ax_object.py_clear_stored_datazAXObject._clear_stored_data:   s#     JJrN,,. r   c                    d}| r|d|  z  }t        j                  t         j                  |d       t        j                  5  dt        t        j                        dg}t        j                  t         j                  |d       t        j                  j                          dt        t        j                        dg}t        j                  t         j                  |d       t        j                  j                          dt        t        j                        dg}t        j                  t         j                  |d       t        j                  j                          d	t        t        j                        dg}t        j                  t         j                  |d       t        j                  j                          d d d        y # 1 sw Y   y xY w)
NzAXObject: Clearing local cache.	 Reason: Tz0AXObject: Clearing known dead-or-alive state forobjectszAXObject: Clearingzreal apps for mutter frameszreal frames for mutter framesz/AXObject: Clearing cached object attributes for)r   printMessage
LEVEL_INFOr   _locklen
KNOWN_DEADprintTokensclearREAL_APP_FOR_MUTTER_FRAMEREAL_FRAME_FOR_MUTTER_FRAMEOBJECT_ATTRIBUTES)reasonmsgtokenss      r   r   z AXObject._clear_all_dictionariesB   s`   /Yvh''C5++S$7^^ 	/HH//0)=Fe..=%%'*C0R0R,S57Fe..=..446*C0T0T,U79Fe..=00668GH667DFe..=&&,,.'	/ 	/ 	/s   E=GGc                 .    t         j                  |        y)z*Clears all cached information immediately.N)r   r   )r   s    r   clear_cache_nowzAXObject.clear_cache_now^   s     	((0r   c                  z    t        j                  t        j                        } d| _        | j                          y)z3Starts thread to periodically clear cached details.)targetTN)	threadingThreadr   r   daemonstart)threads    r   start_cache_clearing_threadz$AXObject.start_cache_clearing_threadd   s*     !!)D)DEr   c                    t         j                  |       t        j                  j                  k(  rt         j                  t         j                  |             t        j                  j                  k(  r\t        j                  j                  |       j                         dk(  r,d| dg}t        j                  t        j                  |dd       yy)z<Hack to ignore certain objects. All entries must have a bug.gecko	AXObject:z"is bogus. See mozilla bug 1879750.TF)r   get_roler   RoleSECTION
get_parentFRAME
Accessibleget_toolkit_namelowerr   r   r   )objr!   s     r   is_boguszAXObject.is_bogusl   s     S!UZZ%7%77  !4!4S!9:ejj>N>NN005;;=H!3(LMFe..dCr   c                 :    | du xs t         j                  |        S )z;Returns False if we know for certain this object is invalidN)r   object_is_known_deadr7   s    r   is_validzAXObject.is_valid}   s!     4KE8#@#@#EFFr   c                 ^    | xr* t         j                  j                  t        |             du S )z@Returns True if we know for certain this object no longer existsT)r   r   gethashr;   s    r   r:   zAXObject.object_is_known_dead   s)     Ax**..tCy9TAAr   c                 N   | yt         j                  j                  t        |             }||k(  ry|t         j                  t        |       <   |r)d}t	        j
                  t        j                  |dd       y|r+d| dg}t	        j                  t        j                  |d       yy)z$Updates the known-dead status of objNz&AXObject: Adding to known dead objectsTzAXObject: Removingzfrom known-dead objects)r   r   r>   r?   r   r   r   r   )r7   is_deadcurrent_statusr    r!   s        r   _set_known_dead_statuszAXObject._set_known_dead_status   s     ;!,,00c;W$)0DI&:Cu//dDA*C1JKFe..= r   c                     t        |      }t        j                  d|      r8|j                  |d      }t	        j
                  t        j                  |d       ntt        j                  d|      r8|j                  |d      }t	        j
                  t        j                  |d       n&t	        j
                  t        j                  |d       yt        j                  j                  t        |             du rt        j                  | d       yy)z?Parses the exception and potentially updates our status for objzaccessible/\d+ does not existzobject no longer existsTz The application no longer existszapp no longer existsNF)strresearchreplacer   r   r   r   r   r>   r?   rC   r7   errorr    s      r   handle_errorzAXObject.handle_error   s     E
995u=++e%>?Cu//d;YY:EB++e%;<Cu//d;u//d;""49-6++C6 7r   c                     t         j                  |       sy	 t        j                  j	                  |       }|duS # t
        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)z8Returns True if the action interface is supported on objFz0AXObject: Exception calling get_action_iface on : N)r   r<   r   r4   get_action_iface	ExceptionrK   r7   ifacerJ   r    s       r   supports_actionzAXObject.supports_action   sv       %	$$55c:E D    	DSEE7SC!!#uc2	   ; 	A-A((A-c                    t         j                  |       syt         j                  t         j                  |             }|dv r+d|dg}t	        j
                  t        j                  |d       y	 t        j                  j                  |       }|duS # t        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)	z<Returns True if the collection interface is supported on objF)sofficezAXObject: Treatingzas not supporting collection.Tz4AXObject: Exception calling get_collection_iface on rM   N)r   r<   get_nameget_applicationr   r   r   r   r4   get_collection_ifacerO   rK   )r7   app_namer!   rQ   rJ   r    s         r   supports_collectionzAXObject.supports_collection   s       %$$X%=%=c%BC{"*H6UVFe..=	$$99#>E D    	HRPUwWC!!#uc2	s   /B 	CB??Cc                     t         j                  |       sy	 t        j                  j	                  |       }|duS # t
        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)z;Returns True if the component interface is supported on objFz3AXObject: Exception calling get_component_iface on rM   N)r   r<   r   r4   get_component_ifacerO   rK   rP   s       r   supports_componentzAXObject.supports_component   v       %	$$88=E D    	GuBugVC!!#uc2	rS   c                     t         j                  |       sy	 t        j                  j	                  |       }|duS # t
        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)z:Returns True if the document interface is supported on objFz2AXObject: Exception calling get_document_iface on rM   N)r   r<   r   r4   get_document_ifacerO   rK   rP   s       r   supports_documentzAXObject.supports_document   sv       %	$$77<E D    	Fse2eWUC!!#uc2	rS   c                     t         j                  |       sy	 t        j                  j	                  |       }|duS # t
        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)z?Returns True if the editable-text interface is supported on objFz7AXObject: Exception calling get_editable_text_iface on rM   N)r   r<   r   r4   get_editable_text_ifacerO   rK   rP   s       r   supports_editable_textzAXObject.supports_editable_text   sy       %	$$<<SAE D    	KC5PRSXRYZC!!#uc2	rS   c                     t         j                  |       sy	 t        j                  j	                  |       }|duS # t
        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)z;Returns True if the hyperlink interface is supported on objFz-AXObject: Exception calling get_hyperlink on rM   N)r   r<   r   r4   get_hyperlinkrO   rK   rP   s       r   supports_hyperlinkzAXObject.supports_hyperlink  sv       %	$$2237E D    	A#bPC!!#uc2	rS   c                     t         j                  |       sy	 t        j                  j	                  |       }|duS # t
        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)z;Returns True if the hypertext interface is supported on objFz3AXObject: Exception calling get_hypertext_iface on rM   N)r   r<   r   r4   get_hypertext_ifacerO   rK   rP   s       r   supports_hypertextzAXObject.supports_hypertext  r^   rS   c                     t         j                  |       sy	 t        j                  j	                  |       }|duS # t
        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)z7Returns True if the image interface is supported on objFz/AXObject: Exception calling get_image_iface on rM   N)r   r<   r   r4   get_image_ifacerO   rK   rP   s       r   supports_imagezAXObject.supports_image'  v       %	$$44S9E D    	CC55'RC!!#uc2	rS   c                     t         j                  |       sy	 t        j                  j	                  |       }|duS # t
        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)z;Returns True if the selection interface is supported on objFz3AXObject: Exception calling get_selection_iface on rM   N)r   r<   r   r4   get_selection_ifacerO   rK   rP   s       r   supports_selectionzAXObject.supports_selection7  r^   rS   c                     t         j                  |       sy	 t        j                  j	                  |       }|duS # t
        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)z7Returns True if the table interface is supported on objFz/AXObject: Exception calling get_table_iface on rM   N)r   r<   r   r4   get_table_ifacerO   rK   rP   s       r   supports_tablezAXObject.supports_tableG  rn   rS   c                     t         j                  |       sy	 t        j                  j	                  |       }|duS # t
        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)z<Returns True if the table cell interface is supported on objFz.AXObject: Exception calling get_table_cell on rM   N)r   r<   r   r4   get_table_cellrO   rK   rP   s       r   supports_table_cellzAXObject.supports_table_cellW  sv       %	$$33C8E D    	B3%r%QC!!#uc2	rS   c                     t         j                  |       sy	 t        j                  j	                  |       }|duS # t
        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)z6Returns True if the text interface is supported on objFz.AXObject: Exception calling get_text_iface on rM   N)r   r<   r   r4   get_text_ifacerO   rK   rP   s       r   supports_textzAXObject.supports_textg  sv       %	$$33C8E
 D  	  	B3%r%QC!!#uc2	rS   c                     t         j                  |       sy	 t        j                  j	                  |       }|duS # t
        $ r)}d|  d| }t         j                  | ||       Y d}~yd}~ww xY w)z7Returns True if the value interface is supported on objFz/AXObject: Exception calling get_value_iface on rM   N)r   r<   r   r4   get_value_ifacerO   rK   rP   s       r   supports_valuezAXObject.supports_valuev  rn   rS   c                 T   t         j                  |       syt         j                  dft         j                  dft         j                  dft         j
                  dft         j                  dft         j                  dft         j                  dft         j                  d	ft         j                  d
ft         j                  dft         j                  dft         j                  dft         j                  dfg}|D cg c]  \  }} ||       s| }}}dj                  |      S c c}}w )z3Returns the supported interfaces of obj as a string Action
Collection	ComponentDocumentEditableText	Hyperlink	HypertextImage	SelectionTable	TableCellTextValue, )r   r<   rR   rZ   r]   ra   rd   rg   rj   rm   rq   rt   rw   rz   r}   join)r7   iface_checkscheckrQ   ifacess        r   supported_interfaces_as_stringz'AXObject.supported_interfaces_as_string  s      % %%x0))<8((+6''4,,n=((+6((+6$$g.((+6$$g.));7##V,$$g.
  -9GLE5E#J%GGyy   Hs   ;D$D$c                 \   t         j                  |       sg S g }| }|rG	 |j                  t        j                  j                  |             t         j                  |      }|rG|j                          |S # t        $ r+}d| d| }t         j                  |||       g cY d}~S d}~ww xY w)zAReturns the path from application to obj as list of child indicesz0AXObject: Exception getting index in parent for rM   N)
r   r<   appendr   r4   get_index_in_parentrO   rK   get_parent_checkedreverse)r7   pathaccrJ   r    s        r   get_pathzAXObject.get_path  s       %IE,,@@EF
 --c2C  	  HRPUwW%%c5#6	s   .A7 7	B+  B& B+&B+c                     t         j                  |       sy	 t        j                  j	                  |       }|S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z0Returns the child index of obj within its parentz,AXObject: Exception in get_index_in_parent: N)r   r<   r   r4   r   rO   rK   )r7   indexrJ   r    s       r   r   zAXObject.get_index_in_parent  sj       %	$$88=E   	@HC!!#uc2	   9 	A(A##A(c                     t         j                  |       sy	 t        j                  j	                  |       }|| k(  r+d| dg}t        j                  t        j                  |d       y|st         j                  |       t        j                  j                  t        j                  j                  fvr*d| dg}t        j                  t        j                  |d       |S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)zBReturns the accessible parent of obj. See also get_parent_checked.Nz#AXObject: Exception in get_parent: r.   zclaims to be its own parentTzclaims to have no parent)r   r<   r   r4   r2   rO   rK   r   r   r   r/   r0   INVALIDDESKTOP_FRAME)r7   parentrJ   r    r!   s        r   r2   zAXObject.get_parent  s       %	%%005F S=!3(EFFe..=>  %ejj.@.@%**BZBZ-[[!3(BCFe..=  	7w?C!!#uc2	s   C 	D'DDc           	      f   t         j                  |       syt         j                  |       }|t        j                  j
                  t        j                  j                  fv ryt         j                  |       }|yt        j                  t        j                  k  r|S t         j                  |       r|S t         j                  |       }t         j                  |      }|dk  s||k\  r2d| d|d|d|dg	}t        j                  t        j                  |d       |S t         j                  ||        |S )	z9Returns the parent of obj, doing checks for tree validityNr   r.   z	has indexz; parenthaschildrenT)r   r<   r/   r   r0   r   APPLICATIONr2   r   r   
debugLevelrA   r   get_child_countr   get_active_descendant_checked)r7   roler   r   
n_childrenr!   s         r   r   zAXObject.get_parent_checked  s      %  %EJJ&&

(>(>??$$S)>e...MC M,,S1--f5
19+!3U &%ZIFe..=M 	..vs;r   c                 *   t         j                  |       sy| g}t         j                  |       }|rc||v r,d|d|g}t        j                  t        j
                  |d       y ||      r|S |j                  |       t         j                  |      }|rcy)z8Returns the ancestor of obj if the function pred is trueNz4AXObject: Circular tree suspected in find_ancestor. zalready in: T)r   r<   r   r   r   r   r   )r7   predr   r   r!   s        r   find_ancestorzAXObject.find_ancestor   s       % %,,S1 P .';!!%"2"2FDAF|NN6"008F  r   c                     t         j                  |       syt         j                        syt         j                  | fd      duS )z.Returns true if ancestor is an ancestor of objFc                     | k(  S Nr   )xancestors    r   <lambda>z&AXObject.is_ancestor.<locals>.<lambda>#  s    Q(] r   N)r   r<   r   )r7   r   s    `r   is_ancestorzAXObject.is_ancestor  s@       %  *%%c+BC4OOr   c                    t         j                  |       syt         j                  |       }|dk  ry|dk(  r|dz
  }d|cxk  r|k  sy y	 t        j                  j                  | |      }|| k(  r+d| dg}t        j                  t        j                  |d       y|S # t        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)	z9Returns the nth child of obj. See also get_child_checked.Nr   r   r   z"AXObject: Exception in get_child: r.   zclaims to be its own childT)r   r<   r   r   r4   get_child_at_indexrO   rK   r   r   r   )r7   r   r   childrJ   r    r!   s          r   	get_childzAXObject.get_child%  s       %--c2
?B;NEE&J& '	$$77UCE C<!3(DEFe..=  	6ug>C!!#uc2	s    B 	C&CCc                 2   t         j                  |       syt         j                  | |      }t        j                  t        j
                  k  r|S t         j                  |      }| |k7  r-d| d|d|g}t        j                  t        j                  |d       |S )z<Returns the nth child of obj, doing checks for tree validityNr.   claimszas child; child's parent isT)r   r<   r   r   r   r   r2   r   )r7   r   r   r   r!   s        r   get_child_checkedzAXObject.get_child_checkedD  s       %""3.e...L$$U+&=!3%9VX^_Fe..=r   c                    t         j                  | t        j                  j                        s|S t         j                  |      }	 t        j                  j                  | |      }||k7  r1d| d| d|d|g}t        j                  t        j                  |d       |S # t        $ r(}d| }t         j                  | ||       |cY d}~S d}~ww xY w)zDChecks the reported active descendant and return the real/valid one.z6AXObject: Exception in get_active_descendant_checked: N
AXObject: z's child at z is z; not reported childT)r   	has_stater   	StateTypeMANAGES_DESCENDANTSr   r4   r   rO   rK   r   r   r   )	containerreported_childr   
real_childrJ   r    r!   s          r   r   z&AXObject.get_active_descendant_checkedV  s     !!)U__-P-PQ!!,,^<	"))<<YNJ '"IeWD/I:,n>Fe..=  	"J5'RC!!)UC8!!	"s    B 	C(CCCc                    t         j                  |       syt        t         j                  |             D ]K  }t         j	                  | |      }|r ||      r|c S t         j                  ||      }|s@ ||      sI|c S  y):Returns the descendant of obj if the function pred is trueN)r   r<   ranger   r   _find_descendant)r7   r   ir   s       r   r   zAXObject._find_descendantl  sy       %x//45 	A..sA6Ee--eT:Ee	 r   c                     t        j                          }t        j                  | |      }d|dt        j                          |z
  ddg}t        j                  t        j
                  |d       |S )r   z AXObject: find_descendant: foundzin .4fsT)r   r   r   r   r   r   )r7   r   r)   resultr!   s        r   find_descendantzAXObject.find_descendant~  sd     		**354fDIIKRWDWX[C\\]>^_%**FD9r   c                     t         j                  |       syt         j                  | t         j                  |       dz
        }|| S t         j	                  |      S )z%Returns the deepest descendant of objNr   )r   r<   r   r   find_deepest_descendant)r7   
last_childs     r   r   z AXObject.find_deepest_descendant  sS       %''X-E-Ec-JQ-NO
J//
;;r   c                 "   t         j                  |       syt         j                  |       }t        |      D ]V  }t         j	                  | |      }|r	 ||      r$|r ||      r|j                  |       t         j                  ||||       X y)IReturns all descendants which match the specified inclusion and exclusionN)r   r<   r   r   r   r   _find_all_descendants)r7   
include_if
exclude_ifmatcheschild_countr   r   s          r   r   zAXObject._find_all_descendants  s       %..s3{# 	SA&&sA.Ej/j/u%**5*j'R	Sr   Nc                     t        j                          }g }t        j                  | |||       dt        |       dt        j                          |z
  dd}t	        j
                  t        j                  |d       |S )r   z AXObject: find_all_descendants: z matches found in r   r   T)r   r   r   r   r   r   r   )rootr   r   r)   r   r    s         r   find_all_descendantszAXObject.find_all_descendants  sv     		&&tZWM.s7|n =  $		e 3C8; 	 	5++S$7r   c                 h   t         j                  |       st        j                  j                  S 	 t        j
                  j                  |       }t         j                  | d       |S # t        $ r@}d| }t         j                  | ||       t        j                  j                  cY d}~S d}~ww xY w)z"Returns the accessible role of objz!AXObject: Exception in get_role: NF)
r   r<   r   r0   r   r4   r/   rO   rK   rC   )r7   r   rJ   r    s       r   r/   zAXObject.get_role  s       %::%%%	&##,,S1D 	''U3  	&5eW=C!!#uc2::%%%	&s   A( (	B115B,&B1,B1c                     t         j                  |       sy	 t        j                  j	                  |       }|S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z'Returns the accessible role name of objr   z&AXObject: Exception in get_role_name: N)r   r<   r   r4   get_role_namerO   rK   )r7   	role_namerJ   r    s       r   r   zAXObject.get_role_name  sk       %	((66s;I   	:5'BC!!#uc2	r   c                    t         j                  |       sy	 t        j                  j	                  |       }t         j                  | d       |S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z"Returns the accessible name of objr   z!AXObject: Exception in get_name: NFr   r<   r   r4   rV   rO   rK   rC   )r7   namerJ   r    s       r   rV   zAXObject.get_name  sz       %	##,,S1D 	''U3  	5eW=C!!#uc2	   A 	A>A99A>c                 b    t         j                  |       }|sy|t         j                  |      k(  S )z;Returns true if obj1 and obj2 share the same non-empty nameF)r   rV   )obj1obj2name1s      r   has_same_non_empty_namez AXObject.has_same_non_empty_name  s0     !!$'))$///r   c                     t         j                  |       sy	 t        j                  j	                  |       }|S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z)Returns the accessible description of objr   z(AXObject: Exception in get_description: N)r   r<   r   r4   get_descriptionrO   rK   r7   descriptionrJ   r    s       r   r   zAXObject.get_description  sk       %	**::3?K   	<UGDC!!#uc2	r   c                     t         j                  |       sy	 t        j                  j	                  |       }|S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z/Returns the accessible image description of objr   z.AXObject: Exception in get_image_description: N)r   rm   r   r   get_image_descriptionrO   rK   r   s       r   r   zAXObject.get_image_description  si     &&s+	++;;C@K   	B5'JC!!#uc2	r   c                    t         j                  |       sy	 t        j                  j	                  |       }|j                  |j                  fS # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z3Returns a (width, height) tuple of the image in obj)r   r   z'AXObject: Exception in get_image_size: N)	r   rm   r   r   get_image_sizerO   rK   r   y)r7   r   rJ   r    s       r   r   zAXObject.get_image_size  sv     &&s+	[[//4F xx!!  	;E7CC!!#uc2	r   c                     t         j                  |       sy	 t        j                  j	                  |       }|S # t
        $ r t         j                  | d      xs d}Y |S w xY w)z'Returns the accessible help text of objr   helptext)r   r<   r   r4   get_help_textrO   get_attribute)r7   texts     r   r   zAXObject.get_help_text   sg       %	A##11#6D
 	  	A))#z:@bD		As   9 #A A c                     t         j                  |       sy	 t        j                  j	                  |       }|S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)zReturns the child count of objr   z(AXObject: Exception in get_child_count: N)r   r<   r   r4   r   rO   rK   r7   countrJ   r    s       r   r   zAXObject.get_child_count0  sj       %	$$44S9E   	<UGDC!!#uc2	r   c              #      K   t         j                  |       syt         j                  |       }t        |      D ]*  }t         j	                  | |      }||	 ||      s'| , yw)zGenerator to iterate through obj's children. If the function pred is
        specified, children for which pred is False will be skipped.N)r   r<   r   r   r   )r7   r   r   r   r   s        r   iter_childrenzAXObject.iter_children@  sd     
   %..s3;' 	E&&sE2E dld5k	s   AA'
A' A'c                 *   t         j                  |       syt         j                  |       }|yt         j                  |       }|dk  ryt         j	                  ||dz
        }|| k(  r+d| dg}t        j                  t
        j                  |d       y|S )z;Returns the previous sibling of obj, based on child indicesNr   r   r.   claims to be its own siblingTr   r<   r2   r   r   r   r   r   r7   r   r   siblingr!   s        r   get_previous_siblingzAXObject.get_previous_siblingN  s       %$$S)>,,S1A:$$VUQY7c>!3(FGFe..=r   c                 *   t         j                  |       syt         j                  |       }|yt         j                  |       }|dk  ryt         j	                  ||dz         }|| k(  r+d| dg}t        j                  t
        j                  |d       y|S )z7Returns the next sibling of obj, based on child indicesNr   r   r.   r   Tr   r   s        r   get_next_siblingzAXObject.get_next_siblinge  s       %$$S)>,,S119$$VUQY7c>!3(FGFe..=r   c                    t         j                  |       syt         j                  |       dz   }t         j                  |       }|rsd|cxk  rt         j	                  |      k  sUn |} t         j                  |       dz   }t         j                  |       }|r"d|cxk  rt         j	                  |      k  sPn S|yt         j                  ||      }|| k(  r+d| dg}t        j                  t        j                  |d       y|S )z?Returns the next object (depth first) in the accessibility treeNr   r   r.   z claims to be its own next objectT	r   r<   r   r2   r   r   r   r   r   )r7   r   r   next_objectr!   s        r   get_next_objectzAXObject.get_next_object|  s       %,,S1A5$$S)QI)A)A&)IIC0059E((-F QI)A)A&)II
 >((7#!3(JKFe..=r   c                    t         j                  |       syt         j                  |       dz
  }t         j                  |       }|ryd|cxk  rt         j	                  |      dz
  k  sXn |} t         j                  |       dz
  }t         j                  |       }|r%d|cxk  rt         j	                  |      dz
  k  sSn V|yt         j                  ||      }|| k(  r+d| dg}t        j                  t        j                  |d       y|S )zCReturns the previous object (depth first) in the accessibility treeNr   r   r.   z$claims to be its own previous objectTr  )r7   r   r   previous_objectr!   s        r   get_previous_objectzAXObject.get_previous_object  s       %,,S1A5$$S)Q%N(*B*B6*JQ*NNC0059E((-F Q%N(*B*B6*JQ*NN
 >",,VU;c!!3(NOFe..=r   c                 P   t         j                  |       st        j                         S 	 t        j                  j                  |       }t         j                  | d       |S # t        $ r:}d| }t         j                  | ||       t        j                         cY d}~S d}~ww xY w)z)Returns the state set associated with objz&AXObject: Exception in get_state_set: NF)	r   r<   r   StateSetr4   get_state_setrO   rK   rC   )r7   	state_setrJ   r    s       r   r  zAXObject.get_state_set  s       %>>##	$((66s;I 	''U3  	$:5'BC!!#uc2>>##	$s   A" "	B%+/B B% B%c                 v    t         j                  |       syt         j                  |       j                  |      S )z+Returns true if obj has the specified stateF)r   r<   r  contains)r7   states     r   r   zAXObject.has_state  s1       %%%c*33E::r   c                     t         j                  |       syd }dj                  t        |t         j	                  |       j                                     S )z5Returns the state set associated with obj as a stringr   c                 \    | j                   dd  j                  dd      j                         S )N   _-
value_namerH   r6   )r  s    r   	as_stringz/AXObject.state_set_as_string.<locals>.as_string  s+    ##BC(00c:@@BBr   r   )r   r<   r   mapr  
get_statesr7   r  s     r   state_set_as_stringzAXObject.state_set_as_string  sG       %	C yyY(>(>s(C(N(N(PQRRr   c                     t         j                  |       sg S 	 t        j                  j	                  |       }|S # t
        $ r(}d| }t         j                  | ||       g cY d}~S d}~ww xY w)z>Returns the list of Atspi.Relation objects associated with objz&AXObject: Exception in get_relations: N)r   r<   r   r4   get_relation_setrO   rK   )r7   	relationsrJ   r    s       r   get_relationszAXObject.get_relations  so       %I	((99#>I   	:5'BC!!#uc2I	s   : 	A+A& A+&A+c                     t         j                  |       syt         j                  |       D ]  }|s|j                         |k(  s|c S  y)z,Returns the specified Atspi.Relation for objN)r   r<   r!  get_relation_type)r7   relation_typerelations      r   get_relationzAXObject.get_relation  sL       % ..s3 	 HH668MI	  r   c                 ^    t         j                  |       syt         j                  | |      duS )z3Returns true if obj has the specified relation typeFN)r   r<   r&  )r7   r$  s     r   has_relationzAXObject.has_relation  s-       %$$S-8DDr   c                    t         j                  |       sg S t         j                  | |      }|g S t               }t	        |j                               D ]/  }|j                  |      }|	 ||      s|j                  |       1 t        j                  j                  g}||vrA| |v r=d| d|dg}t        j                  t        j                  |d       |j                  |        t        |      S )zReturns the list of targets with the specified relation type to obj.
        If pred is provided, a target will only be included if pred is true.r   zis in its ownztarget listT)r   r<   r&  setr   get_n_targets
get_targetaddr   RelationType	MEMBER_OFr   r   r   removelist)	r7   r$  r   r%  targetsr   r%   type_includes_objectr!   s	            r   get_relation_targetszAXObject.get_relation_targets  s    
   %I((m<I%x--/0 	$A((+F|tF|F#	$ !& 2 2 < <= 44"C-WFe..=NN3G}r   c                 p    t         j                         syd } fd}g }t         j                         D ]m  } ||j                               }t         j	                   |j                               }dj                  t        ||            }|j                  | d|        o dj                  |      S )z5Returns the relations associated with obj as a stringr   c                 \    | j                   dd  j                  dd      j                         S )N   r  r  r  )r   s    r   r  z/AXObject.relations_as_string.<locals>.as_string  s+    '',44S#>DDFFr   c                     t         j                        }t         j                        }|r	|d| dz  }|sd}d| dS )Nz: ''DEAD[])r   r   rV   )r   r   r   r7   s      r   obj_as_stringz3AXObject.relations_as_string.<locals>.obj_as_string  sN    ++C0F$$S)DCvQ-'vha= r   ,rM   ; )r   r<   r!  r#  r4  r   r  r   )r7   r  r=  resultsreltype_stringr2  target_strings   `       r   relations_as_stringzAXObject.relations_as_string  s       %	G	! ))#. 	>C#C$9$9$;<K33C9N9N9PQGHHS%@AMNNk]"]O<=		> yy!!r   c                    | 	 t         j                  j                  |       }t        j                  |      dk7  r|| fS t        j                  j                  t        |             }t        j                  j                  t        |             }||||fS d|d| g}t        j                  t        j                  |d       	 t        j                  d	      }t        j                  |       }t        j                  |      D ]R  }	t        j                  |	      dk(  rt        j                  |	      D ]  }
|t        j                  |
      k(  s|	}|
}! T d|d| g}t        j                  t        j                  |d       || k7  r'd}t        j                   t        j                  |d       |t        j                  t        |       <   |t        j                  t        |       <   ||fS # t        $ r)}d|  d| }t        j                  | ||       Y d}~yd}~ww xY w# t        $ r3}d
|g}t        j                  t        j                  |d       Y d}~yd}~ww xY w)z<Work around for window events coming from mutter-x11-frames.Nz+AXObject: Exception getting application of rM   NNmutter-x11-framesr.   zis not valid app forTr   z/AXObject: Exception getting desktop from Atspi:zis real app forz.AXObject: Updated frame to frame from real app)r   r4   rW   rO   r   rK   rV   r   r>   r?   r   r   r   r   get_desktopr   r   )r7   apprJ   r    real_app
real_framer!   desktopr   desktop_appframes              r   find_real_app_and_window_forz%AXObject.find_real_app_and_window_for2  s4    ;"&&66s; S!%888O5599$s)D99==d3iH
J$:Z''s$:C@%**FD9	''*G   %#11': 	'K  -1DD!//< '8,,U33*H!&J'	' x):C@%**FD9BCu//d;8@**495:D,,T#Y7##S  "CC55'R%%c5#6!"$  	GOFe..=	s/   G* H *	H3HH	I()IIc                    t         j                  |       syt         j                  j                  t	        |             }||S 	 t
        j                  j                  |       }t         j                  |      dk7  r|S t         j                  | |      d   }||}|S # t        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z6Returns the accessible application associated with objNz(AXObject: Exception in get_application: rG  r   )r   r<   r   r>   r?   r   r4   rW   rO   rK   rV   rO  )r7   rI  rJ   r    rJ  s        r   rW   zAXObject.get_applicationd  s       %0044T#Y??J	""2237C S!%88J88cB1EC
  	<UGDC!!#uc2	s   B 	C%CCc                     t         j                  |       syt         j                  |       }|y	 t        j                  j                  |      }|S # t        $ r3}d|g}t        j                  t        j                  |d       Y d}~yd}~ww xY w)z8Returns the toolkit name reported for obj's application.r   Nz4AXObject: Exception in get_application_toolkit_name:T)
r   r<   rW   r   r4   r5   rO   r   r   r   )r7   rI  r   rJ   r!   s        r   get_application_toolkit_namez%AXObject.get_application_toolkit_name  s       %&&s+;	##44S9D   	LeTFe..=	   A 	B)BBc                     t         j                  |       syt         j                  |       }|y	 t        j                  j                  |      }|S # t        $ r3}d|g}t        j                  t        j                  |d       Y d}~yd}~ww xY w)z;Returns the toolkit version reported for obj's application.r   Nz7AXObject: Exception in get_application_toolkit_version:T)
r   r<   rW   r   r4   get_toolkit_versionrO   r   r   r   )r7   rI  versionrJ   r!   s        r   get_application_toolkit_versionz(AXObject.get_application_toolkit_version  s       %&&s+;	&&::3?G   	OQVWFe..=	rS  c                     t         j                  |       syt         j                  |       }|yt         j                  |       dt         j	                  |        dt         j                  |        d}|S )z3Returns the application details of obj as a string.r    ( ))r   r<   rW   rV   rR  rW  )r7   rI  strings      r   application_as_stringzAXObject.application_as_string  s}       %&&s+;   %& '55c:;177<=Q@ 	
 r   c                    | yd| d| dg}|r|j                  d|        t        j                  t        j                  |d       |s!	 t        j
                  j                  |        y	 t        j
                  j                  |        y# t        $ r4}d| }t        j                  t        j                  |d       Y d}~yd}~ww xY w# t        $ r&}d| }t        j                  | ||       Y d}~yd}~ww xY w)	z7Clears the Atspi cached information associated with objNz"AXObject: Clearing AT-SPI cache onzRecursive: .r   Tz+AXObject: Exception in clear_cache_single: z$AXObject: Exception in clear_cache: )r   r   r   r   r   r4   clear_cache_singlerO   r   clear_cacher   rK   )r7   	recursiver   r!   rJ   r    s         r   ra  zAXObject.clear_cache  s     ;6{9+UV=WXMMIfX./%**FD9@  33C8 	3((-  @CE7K""5#3#3S$??@  	38@C!!#uc22	3s0   B ,C 	C	*CC		C;C66C;c                     t         j                  |       sy	 t        j                  j	                  |       }|S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z*Returns the process id associated with objr   z'AXObject: Exception in get_process_id: N)r   r<   r   r4   get_process_idrO   rK   )r7   pidrJ   r    s       r   rd  zAXObject.get_process_id  sj       %	""11#6C 
  	;E7CC!!#uc2	r   c                    | yt         j                  |       sy	 t        j                  j	                  |        t         j                  | d       y# t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z6Returns true of obj exists but is believed to be dead.NFTzAXObject: Accessible is dead: r   rI   s      r   rA   zAXObject.is_dead  s     ;  %	 %%c* 	''U3  	25':C!!#uc2	s   A 	B A;;B c                 x   t         j                  |       si S |r,t         j                  j                  t	        |             }|r|S 	 t
        j                  j                  |       }|i S |t         j                  t	        |       <   |S # t        $ r(}d| }t         j                  | ||       i cY d}~S d}~ww xY w)z5Returns the object attributes of obj as a dictionary.z,AXObject: Exception in get_attributes_dict: N)
r   r<   r   r>   r?   r   r4   get_attributesrO   rK   )r7   	use_cache
attributesrJ   r    s        r   get_attributes_dictzAXObject.get_attributes_dict  s       %I!3377S	BJ!!	))88=J I0:""49-  	@HC!!#uc2I	s   B 	B9B4.B94B9c                 ~    t         j                  |       syt         j                  | |      }|j                  |d      S )z9Returns the value of the specified attribute as a string.r   )r   r<   rk  r>   )r7   attribute_nameri  rj  s       r   r   zAXObject.get_attribute  s8       %11#yA
~~nb11r   c                     t         j                  |       syd }dj                  t        |t         j	                  |       j                                     S )z1Returns the object attributes of obj as a string.r   c                     | d    d| d    S )Nr   :r   r   )	attributes    r   r  z0AXObject.attributes_as_string.<locals>.as_string#  s    l^1Yq\N33r   r   )r   r<   r   r  rk  itemsr  s     r   attributes_as_stringzAXObject.attributes_as_string  sF       %	4 yyY(D(DS(I(O(O(QRSSr   c                     t         j                  |       sy	 t        j                  j	                  |       }|S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z/Returns the number of actions supported on obj.r   z&AXObject: Exception in get_n_actions: N)r   rR   r   r   get_n_actionsrO   rK   r   s       r   ru  zAXObject.get_n_actions(  sh     '',	LL..s3E   	:5'BC!!#uc2	r   c                     | syt        j                  dd|       j                         }t        j                  dd|      }|S )z?Adjusts the name to account for differences in implementations.r   z(?<=[a-z])([A-Z])z-\1z"[!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]r  )rF   subr6   )action_namer   s     r   _normalize_action_namezAXObject._normalize_action_name8  s>     vv*FK@FFHvv=sDIr   c                    d|cxk  rt         j                  |       k  sy y	 t        j                  j	                  | |      }t         j                  |      S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z,Returns the name of obj's action at index i.r   r   z(AXObject: Exception in get_action_name: N)r   ru  r   r   get_action_namerO   rK   ry  )r7   r   r   rJ   r    s        r   r{  zAXObject.get_action_nameC  s     A3..s33 4	<<//Q7D ..t44  	<UGDC!!#uc2	s    A 	B!BBc                     g }t        t        j                  |             D ],  }t        j                  | |      }|s|j	                  |       . |S )z-Returns the list of actions supported on obj.)r   r   ru  r{  r   )r7   r@  r   r   s       r   get_action_nameszAXObject.get_action_namesS  sP     x--c23 	%A++C3Dt$	% r   c                     d|cxk  rt         j                  |       k  sy y	 t        j                  j	                  | |      }|S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z3Returns the description of obj's action at index i.r   r   z/AXObject: Exception in get_action_description: N)r   ru  r   r   get_action_descriptionrO   rK   )r7   r   r   rJ   r    s        r   r  zAXObject.get_action_description^  s}     A3..s33 4	,,==c1EK   	CE7KC!!#uc2	    A 	A4A//A4c                     d|cxk  rt         j                  |       k  sy y	 t        j                  j	                  | |      }|S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z:Returns the key binding string of obj's action at index i.r   r   z/AXObject: Exception in get_action_key_binding: N)r   ru  r   r   get_key_bindingrO   rK   )r7   r   
keybindingrJ   r    s        r   get_action_key_bindingzAXObject.get_action_key_bindingn  s}     A3..s33 4	55c1=J   	CE7KC!!#uc2	r  c                 4    t         j                  | |      dk\  S )z5Returns true if the named action is supported on obj.r   )r   get_action_index)r7   rx  s     r   
has_actionzAXObject.has_action~  s     ((k:a??r   c                     t         j                  |      }t        t         j                  |             D ]  }|t         j	                  | |      k(  s|c S  y)z;Returns the index of the named action or -1 if unsupported.r   )r   ry  r   ru  r{  )r7   rx  r   s      r   r  zAXObject.get_action_index  sR     55kBx--c23 	Ah66sA>>	 r   c                     d|cxk  rt         j                  |       k  sy y	 t        j                  j	                  | |      }|S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)zInvokes obj's action at index i. The return value, if true, may be
        meaningless because most implementors return true without knowing if
        the action was successfully performed.r   Fz"AXObject: Exception in do_action: N)r   ru  r   r   	do_actionrO   rK   )r7   r   r   rJ   r    s        r   r  zAXObject.do_action  s|     A3..s33 4	\\++C3F   	6ug>C!!#uc2	r  c                     t         j                  | |      }|dk(  r,d|d| g}t        j                  t        j                  |d       yt         j                  | |      S )zInvokes the named action on obj. The return value, if true, may be
        meaningless because most implementors return true without knowing if
        the action was successfully performed.r   zINFO:znot an available action forTF)r   r  r   r   r   r  )r7   rx  r   r!   s       r   do_named_actionzAXObject.do_named_action  sZ     ))#{;B;{,I3OFe..=!!#u--r   c                     g }t        t        j                  |             D ]J  }t        j                  | |      }t        j	                  | |      }|r	|d| dz  }|j                  |       L dj                  |      S )z2Returns information about the actions as a string.rY  r[  r?  )r   r   ru  r{  r  r   r   )r7   r@  r   r   r  s        r   actions_as_stringzAXObject.actions_as_string  s     x--c23 	#A--c15F!88a@JBzl!,,NN6"	# yy!!r   c                    t         j                  |       sy	 t        j                  j	                  |       }t        j                  t        j                  k  r|S |rXt         j                  | t        j                  j                        s*d| dg}t        j                  t        j                  |d       |S # t
        $ r&}d| }t         j                  | ||       Y d}~yd}~ww xY w)z:Attempts to grab focus on obj. Returns true if successful.Fz#AXObject: Exception in grab_focus: Nr.   z$lacks focused state after focus grabT)r   r]   r   r   
grab_focusrO   rK   r   r   r   r   r   FOCUSEDr   )r7   r   rJ   r    r!   s        r   r  zAXObject.grab_focus  s     **3/	__//4F e...M(,,S%//2I2IJ!3(NOFe..=  	7w?C!!#uc2	s   B6 6	C%?C  C%)r   rF  r   )Fr   )T)^__name__
__module____qualname____doc__r   r   r   r   r&   Lockr   staticmethodr   r   r#   r+   r8   r<   r:   rC   rK   rR   rZ   r]   ra   rd   rg   rj   rm   rq   rt   rw   rz   r}   r   r   r   r2   r   r   r   r   r   r   r   r   r   r   r   r/   r   rV   r   r   r   r   r   r   r   r  r  r  r
  r  r   r  r!  r&  r(  r4  rD  rO  rW   rR  rW  r]  ra  rd  rA   rk  r   rs  ru  ry  r{  r}  r  r  r  r  r  r  r  r  r   r   r   r   r   0   s   GJ ""$INNE/ / / /6 1 1
      G G
 B B
 > >( 7 7" ! ! ! !* ! !  ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !2  (    2  @  0 	P 	P  <  "  *  "   
< 
< S S           0 0     " "         ,  ,  0  0    ; ; 	S 	S   
 
 E E  4 " "8 /$ /$b  4  &  &  " 3 32    *  0 2 2 	T 	T     5 5       @ @
    " . . " "  r   r   )r  __id____version____date____copyright____license__rF   r&   r   girequire_versiongi.repositoryr   r   r   r   r+   r   r   r   <module>r     sd   * 1 	   	   7E "  b bH- 	 $ $ &r   