
    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  G d d      Zy)a  
Utilities for obtaining objects via the collection interface.
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)AXObjectc            
       L   e Zd ZdZeg ej                  j                  g ej                  j                  g ej                  j                  g ej                  j                  df	d       Z	eej                  j                  fd       Zeej                  j                  fd       Zy)AXCollectionz=Utilities for obtaining objects via the collection interface.Fc	                    t        j                         }	| r| D ]  }
|	j                  |
        i }|rF|D ]A  }|j                  dd      \  }}|j	                  dd      }||v r||   dz   |z   ||<   =|||<   C 	 t         j
                  j                  |	||||||||	      }|S # t        $ r3}d|g}t        j                  t        j                  |d       Y d}~yd}~ww xY w)z4Creates a match rule based on the supplied criteria.:r   z\:z-AXCollection: Exception in create_match_rule:TN)r   StateSetaddsplitreplace	MatchRulenew	Exceptionr   printTokens
LEVEL_INFO)statesstate_match_type
attributesattribute_match_typerolesrole_match_type
interfacesinterface_match_typeinvert	state_setstateattributes_dictattrkeyvalueruleerrortokenss                     4/usr/lib/python3/dist-packages/orca/ax_collection.pycreate_match_rulezAXCollection.create_match_rule5   s    NN$	 %e$% " 1!ZZQ/
Uc51/)+:3+?#+E+MOC(+0OC(1	??&&y'7'6';','6'1';'-/D   	EuMFe..=	s   :'B# #	C,)CCc                    t        j                  |       sg S |g S t        j                         }	 t        j                  j                  | ||dd      }dt        |       dt        j                         |z
  dd}t        j                  t        j                  |d       |S # t        $ r5}d|g}t        j                  t        j                  |d       g cY d}~S d}~ww xY w)	z6Returns a list of objects matching the specified rule.Nr   Tz+AXCollection: Exception in get_all_matches:zAXCollection: z match(es) found in .4fs)r   supports_collectiontimer   
Collectionget_matchesr   r   r   r   lenprintMessage)objr$   orderstartmatchesr%   r&   msgs           r'   get_all_matcheszAXCollection.get_all_matchesb   s     ++C0I<I			 &&223eQMG s7|n,@uATUX@YYZ[5++S$7  	CUKFe..=I	s   #B# #	C!,*CC!C!c                    t        j                  |       sy|yt        j                         }	 t        j                  j                  | ||dd      }d}|r|d   }d|dt        j                         |z
  dd	g}t        j                  t        j                  |d       |S # t        $ r3}d|g}t        j                  t        j                  |d       Y d}~yd}~ww xY w)
z5Returns the first object matching the specified rule.Nr   Tz+AXCollection: Exception in get_first_match:r   zAXCollection: foundzin r*   r+   )
r   r,   r-   r   r.   r/   r   r   r   r   )r2   r$   r3   r4   r5   r%   r&   matchs           r'   get_first_matchzAXCollection.get_first_matchz   s     ++C0<			 &&223eQMG AJE'#diikE6I#5Na0PQ%**FD9  	CUKFe..=	s   #B! !	C*)CCN)__name__
__module____qualname____doc__staticmethodr   CollectionMatchTypeALLANYr(   CollectionSortOrder	CANONICALr7   r:        r'   r	   r	   /   s    G
 !#+0+D+D+H+H%'/4/H/H/L/L "*/*C*C*G*G%'/4/H/H/L/L!&) )X ).)B)B)L)L  . ).)B)B)L)L  rF   r	   )r>   __id____version____date____copyright____license__r-   girequire_versiongi.repositoryr    r   	ax_objectr   r	   rE   rF   r'   <module>rQ      sR   * 1  	   7E "   e erF   