3
WYK7                 @   s  d dl Zd dlmZ d dljZd dljZddddddd	d
ddddddddddddgZdd Z	dd Z
dd Zdd Zdd Zdd Zdd	 Zdd
 Zdd Zd d Zd3d"dZd#d$ Zd%d& Zd'd Zd(d) Zd*d Zd+d Zd,d Zd-d Zd.d Zd/d ZG d0d1 d1eZd2d Z dS )4    N)allModifierssetCacheLevelgetCacheLevel
clearCache
printCachegetInterfaceIIDgetInterfaceNamelistInterfacesstringToConststateToStringrelationToStringr   findDescendantfindAllDescendantsfindAncestorgetPathpointToList
rectToListattributeListToHashhashToAttributeListgetBoundingBoxc             C   s   d S )N )levelr   r   //usr/lib/python3/dist-packages/pyatspi/utils.pyr   4   s    c               C   s   d S )Nr   r   r   r   r   r   7   s    c               C   s   d S )Nr   r   r   r   r   r   :   s    c               C   s   t d d S )Nz"Print cache function is deprecated)printr   r   r   r   r   =   s    c             C   s   dS )a  
        Gets the ID of an interface class or object in string format for use in
        queryInterface.

        @param obj: Class representing an AT-SPI interface or instance
        @type obj: object
        @return: IID for the interface
        @rtype: string
        @raise AttributeError: When the parameter does not provide typecode info

        WARNING!! DEPRECATED!!

        In current D-Bus version of pyatspi this simply returns a null string.
         r   )objr   r   r   r   @   s    c             C   s   | j jdS )aX  
        Gets the human readable name of an interface class or object in string
        format.

        @param obj: Class representing an AT-SPI interface or instance
        @type obj: class
        @return: Name of the interface
        @rtype: string
        @raise AttributeError: When the parameter does not provide typecode info
        zorg.a11y.atspi.)Z_dbus_interfacelstrip)r   r   r   r   r   Q   s    c             C   s   | j  S )a   
        Gets a list of the names of all interfaces supported by this object. The
        names are the short-hand interface names like "Accessible" and "Component",
        not the full interface identifiers.

        @param obj: Arbitrary object to query for all accessibility related
        interfaces. Must provide a queryInterface method.
        @type obj: object
        @return: Set of supported interface names
        @rtype: set
        @raise AttributeError: If the object provide does not implement
        queryInterface
        )Zget_interfaces)r   r   r   r   r	   ^   s    c             C   s(   | j  d |j  jdd }tt||S )a  
        Maps a string name to an AT-SPI constant. The rules for the mapping are as 
        follows:
                - The prefix is captalized and has an _ appended to it.
                - All spaces in the suffix are mapped to the _ character. 
                - All alpha characters in the suffix are mapped to their uppercase.

        The resulting name is used with getattr to look up a constant with that name
        in the L{constants} module. If such a constant does not exist, the string
        suffix is returned instead.

        This method allows strings to be used to refer to roles, relations, etc.
        without direct access to the constants. It also supports the future expansion
        of roles, relations, etc. by allowing arbitrary strings which may or may not
        map to the current standard set of roles, relations, etc., but may still
        match some non-standard role, relation, etc. being reported by an
        application.

        @param prefix: Prefix of the constant name such as role, relation, state, 
                text, modifier, key
        @type prefix: string
        @param suffix: Name of the role, relation, etc. to use to lookup the constant
        @type suffix: string
        @return: The matching constant value
        @rtype: object
        _ )upperreplacegetattrZ	constants)prefixsuffixnamer   r   r   r
   n   s    c             C   s   t jj| S )aD  
        Converts a state value to a string based on the name of the state constant in
        the L{constants} module that has the given value.

        @param value: An AT-SPI state
        @type value: Accessibility.StateType
        @return: Human readable, untranslated name of the state
        @rtype: string
        )stateZSTATE_VALUE_TO_NAMEget)valuer   r   r   r      s    
c             C   s   t jjj| S )aP  
        Converts a relation value to a string based on the name of the state constant
        in the L{constants} module that has the given value.

        @param value: An AT-SPI relation
        @type value: Accessibility.RelationType
        @return: Human readable, untranslated name of the relation
        @rtype: string
        )pyatspiZAccessibilityZRELATION_VALUE_TO_NAMEr&   )r'   r   r   r   r      s    
Fc             C   sT   |rt | |S x@| D ]8}yt| |}W n tk
r>   d}Y nX |dk	r|S qW dS )a  
        Searches for a descendant node satisfying the given predicate starting at 
        this node. The search is performed in depth-first order by default or
        in breadth first order if breadth_first is True. For example,

        my_win = findDescendant(lambda x: x.name == 'My Window')

        will search all descendants of x until one is located with the name 'My
        Window' or all nodes are exausted. Calls L{_findDescendantDepth} or
        L{_findDescendantBreadth} to start the recursive search.

        @param acc: Root accessible of the search
        @type acc: Accessibility.Accessible
        @param pred: Search predicate returning True if accessible matches the 
                        search criteria or False otherwise
        @type pred: callable
        @param breadth_first: Search breadth first (True) or depth first (False)?
        @type breadth_first: boolean
        @return: Accessible matching the criteria or None if not found
        @rtype: Accessibility.Accessible or None
        N)_findDescendantBreadth_findDescendantDepth	Exception)accpredZbreadth_firstchildretr   r   r   r      s    


 c             C   sz   x2| D ]*}y||r|S W q t k
r.   Y qX qW x@| D ]8}yt||}W n t k
rd   d}Y nX |dk	r:|S q:W dS )a  
        Internal function for locating one descendant. Called by L{findDescendant} to
        start the search.

        @param acc: Root accessible of the search
        @type acc: Accessibility.Accessible
        @param pred: Search predicate returning True if accessible matches the 
                        search criteria or False otherwise
        @type pred: callable
        @return: Matching node or None to keep searching
        @rtype: Accessibility.Accessible or None
        N)r+   r)   )r,   r-   r.   r/   r   r   r   r)      s    
 


 r)   c             C   sl   y|| r| S W n t k
r$   Y nX x@| D ]8}yt||}W n t k
rV   d}Y nX |dk	r,|S q,W dS )a  
        Internal function for locating one descendant. Called by L{findDescendant} to
        start the search.

        @param acc: Root accessible of the search
        @type acc: Accessibility.Accessible
        @param pred: Search predicate returning True if accessible matches the 
                search criteria or False otherwise
        @type pred: callable
        @return: Matching node or None to keep searching
        @rtype: Accessibility.Accessible or None
        N)r+   r*   )r,   r-   r.   r/   r   r   r   r*      s     

 r*   c             C   s   g }t | || |S )a  
        Searches for all descendant nodes satisfying the given predicate starting at 
        this node. Does an in-order traversal. For example,

        pred = lambda x: x.getRole() == pyatspi.ROLE_PUSH_BUTTON
        buttons = pyatspi.findAllDescendants(node, pred)

        will locate all push button descendants of node.

        @param acc: Root accessible of the search
        @type acc: Accessibility.Accessible
        @param pred: Search predicate returning True if accessible matches the 
                        search criteria or False otherwise
        @type pred: callable
        @return: All nodes matching the search criteria
        @rtype: list
        )_findAllDescendants)r,   r-   matchesr   r   r   r      s    c             C   sJ   xD| D ]<}y||r|j | W n tk
r4   Y nX t||| qW dS )z
        Internal method for collecting all descendants. Reuses the same matches
        list so a new one does not need to be built on each recursive step.
        N)appendr+   r0   )r,   r-   r1   r.   r   r   r   r0     s    
 r0   c             C   sT   | dkrdS xB| j dkrdS y|| j r.| j S W n tk
rD   Y nX | j } qW dS )a  
        Searches for an ancestor satisfying the given predicate. Note that the
        AT-SPI hierarchy is not always doubly linked. Node A may consider node B its
        child, but B is not guaranteed to have node A as its parent (i.e. its parent
        may be set to None). This means some searches may never make it all the way
        up the hierarchy to the desktop level.

        @param acc: Starting accessible object
        @type acc: Accessibility.Accessible
        @param pred: Search predicate returning True if accessible matches the 
                search criteria or False otherwise
        @type pred: callable
        @return: Node matching the criteria or None if not found
        @rtype: Accessibility.Accessible
        N)parentr+   )r,   r-   r   r   r   r     s    

 
c             C   sV   g }xL| j dkr|j  |S y|j| j  W n tk
rF   tY nX | j } qW dS )am  
        Gets the path from the application ancestor to the given accessible in
        terms of its child index at each level.

        @param acc: Target accessible
        @type acc: Accessibility.Accessible
        @return: Path to the target
        @rtype: list of integer
        @raise LookupError: When the application accessible cannot be reached
        N)r3   reverser2   ZgetIndexInParentr+   LookupError)r,   pathr   r   r   r   6  s    

c             C   s   | j | jfS )N)xy)Zpointr   r   r   r   L  s    c             C   s   | j | j| j| jfS )N)r7   r8   widthheight)rectr   r   r   r   O  s    c             C   sZ   t  }xN| D ]F}|jd\}}|jdd}|j|rJ|| d | ||< q|||< qW |S )N:z\:)dictsplitr    __contains__)listr/   itemkeyvalr   r   r   r   R  s    

c                s    fdd j  D S )Nc                s   g | ]}|d   |  qS )r<   r   ).0r7   )hr   r   
<listcomp>^  s    z'hashToAttributeList.<locals>.<listcomp>)keys)rE   r   )rE   r   r   ]  s    c               @   s   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZeeedZ	dd Z
dd Zee
edZdd Zdd ZeeedZdd Zdd ZeeedZdS )BoundingBoxc             C   s   t j| ||||fS )N)r@   __new__)clsr7   r8   r9   r:   r   r   r   rI   a  s    zBoundingBox.__new__c             C   s   t j| ||||f d S )N)r@   __init__)selfr7   r8   r9   r:   r   r   r   rK   c  s    zBoundingBox.__init__c             C   s   d| j | j| j| jf S )Nz(%d, %d, %d, %d))r7   r8   r9   r:   )rL   r   r   r   __str__f  s    zBoundingBox.__str__c             C   s   | d S )Nr   r   )rL   r   r   r   _get_xi  s    zBoundingBox._get_xc             C   s   || d< d S )Nr   r   )rL   rC   r   r   r   _set_xk  s    zBoundingBox._set_x)fgetfsetc             C   s   | d S )N   r   )rL   r   r   r   _get_yn  s    zBoundingBox._get_yc             C   s   || d< d S )NrR   r   )rL   rC   r   r   r   _set_yp  s    zBoundingBox._set_yc             C   s   | d S )N   r   )rL   r   r   r   
_get_widths  s    zBoundingBox._get_widthc             C   s   || d< d S )NrU   r   )rL   rC   r   r   r   
_set_widthu  s    zBoundingBox._set_widthc             C   s   | d S )N   r   )rL   r   r   r   _get_heightx  s    zBoundingBox._get_heightc             C   s   || d< d S )NrX   r   )rL   rC   r   r   r   _set_heightz  s    zBoundingBox._set_heightN)__name__
__module____qualname__rI   rK   rM   rN   rO   propertyr7   rS   rT   r8   rV   rW   r9   rY   rZ   r:   r   r   r   r   rH   `  s   rH   c             C   s   t | j| j| j| jS )N)rH   r7   r8   r9   r:   )r;   r   r   r   r   ~  s    )F)!Zpyatspi.Accessibilityr(   Zpyatspi.deviceeventr   Zpyatspi.stater%   Zpyatspi.registryregistry__all__r   r   r   r   r   r   r	   r
   r   r   r   r)   r*   r   r0   r   r   r   r   r   r   r@   rH   r   r   r   r   r   <module>   s\   


 