%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/orca/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/orca/__pycache__/label_inference.cpython-312.pyc

�

g
f8Q���dZdZdZdZdZdZddlZejdd	�dd
lm	Z	ddl
mZdd
lm
Z
ddlmZddlmZddlmZddlmZddlmZGd�d�Zy)zDHeuristic means to infer the functional/displayed label of a widget.z$Id$z
$Revision$z$Date$z$Copyright (C) 2011-2013 Igalia, S.L.�LGPL�N�Atspiz2.0)r�)�debug)�AXComponent)�AXHypertext)�AXObject)�AXTable)�AXText)�AXUtilitiesc��eZdZd�Zdd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zdd�Z
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zd�Zd�Zd�Zd�Zd�Zdd�Zy) �LabelInferencec�<�||_i|_i|_i|_y)z�Creates an instance of the LabelInference class.

        Arguments:
        - script: the script with which this instance is associated.
        N)�_script�
_lineCache�
_extentsCache�_isWidgetCache)�self�scripts  �6/usr/lib/python3/dist-packages/orca/label_inference.py�__init__zLabelInference.__init__,s"����������� ���c��d|g}tjtj|d�|sdgfS|rCtj|�s.d|dg}tjtj|d�dgfSdg}}|s=|j|�\}}tjtjd|�d�d�|r|j|�rA|j|�xs|\}}tjtjd|�d�d�|s=|j|�\}}tjtjd	|�d�d�|s=|j|�\}}tjtjd
|�d�d�|s=|j|�\}}tjtjd|�d�d�|s@tj|�g}}tjtjd|�d�d�|r"|j�}|jd
d�}|s?|j|d��\}}tjtjd|�d�d�|j!�||fS)z�Attempt to infer the functional/displayed label of obj.

        Arguments
        - obj: the unlabeled widget
        - focusedOnly: If True, only infer if the widget has focus.

        Returns the text which we think is the label, or None.
        z LABEL INFERENCE: Infer label forTNzLABEL INFERENCE:zis not focusedzLABEL INFERENCE: Text Left: '�'zLABEL INFERENCE: Text Right: 'zLABEL INFERENCE: Table: 'zLABEL INFERENCE: Text Above: 'zLABEL INFERENCE: Text Below: 'zLABEL INFERENCE: Name: '�
� ��)�	proximityz3LABEL INFERENCE: Text Left with proximity of 200: ')r�printTokens�
LEVEL_INFOr�
is_focused�inferFromTextLeft�printMessage�_preferRight�inferFromTextRight�inferFromTable�inferFromTextAbove�inferFromTextBelowr	�get_name�strip�replace�
clearCache)r�obj�focusedOnly�tokens�result�objectss      r�inferzLabelInference.infer8sp��5�c�:��
���%�*�*�F�D�9����8�O��{�5�5�c�:�(�#�/?�@�F����e�.�.���=���8�O������"�4�4�S�9�O�F�G����u�/�/�3P�QW�PX�XY�1Z�\`�a���*�*�3�/�"�5�5�c�:�D�f�O�F�G����u�/�/�3Q�RX�QY�YZ�1[�]a�b��"�1�1�#�6�O�F�G����u�/�/�3L�V�H�TU�1V�X\�]��"�5�5�c�:�O�F�G����u�/�/�3Q�RX�QY�YZ�1[�]a�b��"�5�5�c�:�O�F�G����u�/�/�3Q�RX�QY�YZ�1[�]a�b��&�/�/��4�b�G�F����u�/�/�3K�F�8�ST�1U�W[�\���\�\�^�F��^�^�D�#�.�F��"�4�4�S�C�4�H�O�F�G����� � �E�f�X�Q�O�QU�
W�	
�����w��rc�.�i|_i|_i|_y)z5Dumps whatever we've stored for performance purposes.N)rrr)rs rr,zLabelInference.clearCachess�������� ��rc�Z�tj|�xstj|�S)zeReturns True if we should prefer text on the right, rather than the
        left, for the object obj.)r�is_check_box�is_radio_button�rr-s  rr$zLabelInference._preferRightzs%���'�'��,�P��0K�0K�C�0P�Prc�Z�tj|�xstj|�S)zeReturns True if we should not permit inference based on text to
        the right for the object obj.�r�is_combo_box�is_list_boxr7s  r�
_preventRightzLabelInference._preventRight��%���'�'��,�L��0G�0G��0L�Lrc�Z�tj|�xstj|�S)zZReturns True if we should prefer text above, rather than below for
        the object obj.r9r7s  r�
_preferTopzLabelInference._preferTop�r=rc�.�tj|�S)zZReturns True if we should not permit inference based on text below
        the object obj.)r�
is_text_inputr7s  r�
_preventBelowzLabelInference._preventBelow�s���,�,�S�1�1�1rc���|�y�fd�}tj||�D�cgc]}|��}}t|�dkDrytj|�j�}|j
�jj�dkDryycc}w)z�Returns True if the given object has 'simple' contents, such as text
        without embedded objects or a single embedded object without text.Fc���|duxr>�jjj|�xrtj|�S)N)r�	utilities�isStaticTextLeafr�is_link)�xrs �r�isMatchz/LabelInference._isSimpleObject.<locals>.isMatch�sE����D�=�1��,�,�0�0�A�A�!�D�D�1�%�-�-�a�0�0�
1rrT)	r	�
iter_children�lenr�get_all_textr*�countr�EMBEDDED_OBJECT_CHARACTER)rr-rI�child�children�strings`     r�_isSimpleObjectzLabelInference._isSimpleObject�s�����;��	1�
(0�'=�'=�c�7�'K�L�e�E�L��L��x�=�1����$�$�S�)�/�/�1���<�<����>�>�?�!�C����Ms�	B	c��|�ytj|�stj|�ry|j|�S)zBReturns True if the given object should not be treated as a label.T)r�
is_heading�is_list_item�	_isWidgetr7s  r�_cannotLabelzLabelInference._cannotLabel�s9���;���!�!�#�&�+�*B�*B�3�*G���~�~�c�"�"rc��|�y|jjt|��}|�|Stjj
tjjtjjtjjtjjtjjtjjtjjtjjtjjtjjg}t!j"|�|v}|st%j&|�rd}||jt|�<|S)z-Returns True if the given object is a widget.FT)r�get�hashr�Role�	CHECK_BOX�RADIO_BUTTON�
TOGGLE_BUTTON�	COMBO_BOX�LIST�LIST_BOX�MENU�	MENU_ITEM�ENTRY�
PASSWORD_TEXT�PUSH_BUTTONr	�get_roler�is_editable)rr-�rv�widgetRoles�isWidgets     rrVzLabelInference._isWidget�s���;��
�
 �
 �
$�
$�T�#�Y�
/��
�>��I��z�z�+�+��z�z�.�.��z�z�/�/��z�z�+�+��z�z����z�z�*�*��z�z����z�z�+�+��z�z�'�'��z�z�/�/��z�z�-�-�
/���$�$�S�)�[�8���K�3�3�C�8��H�)1����D��I�&��rc�H�|sy|jjt|�||f�}|r|Sd}tj|�rttj|�s_|dk(rtj|�}tj|||�}|j|j|j|jf}|dr|dsCtj|�}|j|j|j|jf}||jt|�||f<|S)z�Returns (x, y, width, height) of the text at the given offsets
        if the object implements accessible text, or just the extents of
        the object if it doesn't implement accessible text.)rrrr�����)rrYrZr	�
supports_textrrAr�get_character_count�get_range_rectrH�y�width�heightr�get_rect)rr-�startOffset�	endOffsetri�extents�rect�exts        r�_getExtentszLabelInference._getExtents�s���
��
�
�
�
#�
#�T�#�Y��Y�$G�
H��
��I����!�!�#�&��,�,�S�1���?� &� :� :�3� ?�I��,�,�S�+�y�I���&�&�$�&�&�$�*�*�d�k�k�A����
�w�q�z��&�&�s�+�C��e�e�S�U�U�C�I�I�s�z�z�9�G�BI����D��I�{�I�>�?��rc�l�|j|�sdgfS|j|�rdgfS|jjj	|d��}|D�cgc]}|d��	}}tt
|j|��rdgfS|D�cgc]}|d��	}}dj|�|fScc}wcc}w)z>Gets the functional label text associated with the object obj.NF)�useCacherro�)	rRrWrrE�getObjectContentsAtOffset�list�filterrV�join)rr-�contents�contentr1�stringss      r�_createLabelFromContentsz'LabelInference._createLabelFromContents�s����#�#�C�(���8�O����S�!���8�O��<�<�)�)�C�C�C�RW�C�X��-5�6�'�7�1�:�6��6���t�~�~�w�/�0���8�O�-5�6�'�7�1�:�6��6��w�w�w���(�(��7��7s�B,�B1c�P�|jjt|��}|r|St|�}|j|�r*t	j
|�}t
j|�}|jjj||dd�}||j|<|S)zeGet the (obj, startOffset, endOffset, string) tuples for the line
        containing the object, obj.TF)rrYrZrVr�get_link_start_offsetr	�
get_parentrrE�getLineContentsAtOffset)rr-�startri�keys     r�_getLineContentszLabelInference._getLineContents�s����_�_�
 �
 ��c��
+��
��I��3�i���>�>�#���5�5�c�:�E��%�%�c�*�C�
�\�\�
#�
#�
;�
;�C���e�
T��!�������	rc���|j|�}|j|�}|D�cgc]
}|d|k(s�|��}}	|j|d�}|d|}d}	tt	|�dz
dd�D]@}
||
\}}}
}|j|�}|d|dkDs|j
|�s�;|
dz}	n||	d}|r|dsdgfS|d\}}	}}|j||	|�}|d|d|dzz
}d|cxkr|krNndgfS|D�cgc]}|d��	}}dj|�j�}|r||D�cgc]}|d��	c}fSdgfScc}w#t$rt	|�}Y��wxYwcc}wcc}w)aLAttempt to infer the functional/displayed label of obj by
        looking at the contents of the current line, which are to the
        left of this object

        Arguments
        - obj: the unlabeled widget
        - proximity: pixels expected for a match

        Returns the text which we think is the label, or None.
        rrrmNrnror)	r|r��index�
IndexErrorrK�rangerWr�r*)rr-rryr��or�r��onLeftr��i�lObj�lStart�lEnd�lString�lExtents�endrQ�distancer�r0s                     rr"z LabelInference.inferFromTextLefts����"�"�3�'���(�(��-��&�6��!�A�$�#�+�1�6��6�	"��N�N�7�1�:�.�E��!�E�"�����s�6�{�Q���B�/�	�A�*0��)�'�D�&�$���'�'��-�H���{�W�Q�Z�'�4�+<�+<�T�+B��A����	�������6�!�9���8�O�#)�"�:� ��e�S�&��#�#�D�%��5���1�:��!��x��{�!:�;����%�I�%��R�x��28�8�g�w�q�z�8�G�8��W�W�W�%�+�+�-�F���&�A�w���
�A�A�A��R�x���97���	"���M�E�	"��(9�� Bs'�
E�E�E�E.�:E3�E+�*E+c�4�|j|�rdgfS|j|�}|j|�}|D�cgc]
}|d|k(s�|��}}	|j|d�}|t
t|�|dz�d}t|�}	t|�D]7\}
}|j|d�s�|j|�sdgfcS|
dz}	n|d|	}|r|dsdgfS|d\}}
}	}|j||
|	�}|d|d|dzz
}||ks|j|�rH|D�cgc]}|d��	}}dj|�j�}|r||D�cgc]}|d��	c}fSdgfScc}w#t$rt|�}Y��'wxYwcc}wcc}w)aMAttempt to infer the functional/displayed label of obj by
        looking at the contents of the current line, which are to the
        right of this object

        Arguments
        - obj: the unlabeled widget
        - proximity: pixels expected for a match

        Returns the text which we think is the label, or None.
        Nrrrnror)r<r|r�r�r�rK�min�	enumeraterWr$r�r*)rr-rryr�r�r�r��onRightr�r��item�rObjr�rQ�rExtentsr�r�r0s                   rr%z!LabelInference.inferFromTextRight:s������c�"���8�O��"�"�3�'���(�(��-��&�6��!�A�$�#�+�1�6��6�	"��N�N�7�1�:�.�E��3�s�8�}�e�A�g�6�7�8���'�l�� ��)�	�G�A�t�� � ��a��)��(�(��-���8�O��!�e���	��!�C�.���G�A�J���8�O�#*�1�:� ��e�S�&��#�#�D�%��5���A�;�'�!�*�w�q�z�"9�:���y� �D�$5�$5�c�$:�18�9�g�w�q�z�9�G�9��W�W�W�%�+�+�-�F���'�B�w���
�B�B�B��R�x���97���	"���M�E�	"��(:�� Cs)�
E0�
E0�E5�(F�F�5F
�F
c��|j|�}|D�cgc]
}|d|k(s�|��}}	|j|d�}|dkDrdgfS|jjj|dd|ddd�\}}|j||�}	t
|	�dk7rdgfS|	d\}}
}}|j|�rdgfS|j�r_|j||
|�\}
}}}|j|�\}}}}|||zz
}d|cxkr|krndgfS|
|kr|j�|gfSdgfScc}w#t$rdgfcYSwxYw)�HAttempt to infer the functional/displayed label of obj by
        looking at the contents of the line above the line containing
        the object obj.

        Arguments
        - obj: the unlabeled widget
        - proximity: pixels expected for a match

        Returns the text which we think is the label, or None.
        rNrT)
r�r�r�rrE�previousContextrKrWr*r|)rr-r�thisLiner�r�r��prevObj�
prevOffset�prevLiner�r�rQrHrsrtru�objX�objY�objWidth�	objHeightr�s                      rr'z!LabelInference.inferFromTextAboveis����(�(��-��&�6��!�A�$�#�+�1�6��6�	��N�N�7�1�:�.�E��1�9���8�O�"�l�l�4�4�D�D��Q�K��N�H�Q�K��N�D�2�����(�(��*�=���x�=�A����8�O�&.�q�k�#����V����W�%���8�O��<�<�>�"&�"2�"2�7�E�3�"G��A�q�%��.2�.>�.>�s�.C�+�D�$��)��q�6�z�*�H��H�)�	�)��R�x��/0�4�i��|�|�~��y�0�0��R�x���37���	���8�O�	�s�
D4�D4�D9�9
E	�E	c��|j|�rdgfS|j|�}|D�cgc]
}|d|k(s�|��}}	|j|d�}|dkDrdgfS|jj
j
|dd|dddz
d�\}}|j||�}	t|	�dk7rdgfS|	d\}}
}}|j|�rdgfS|j�rZ|j||
|�\}
}}}|j|�\}}}}|||zz
}d|cxkr|krndgfS|j�|gfSdgfScc}w#t$rdgfcYSwxYw)r�NrrmrnrT)rBr�r�r�rrE�nextContextrKrWr*r|)rr-rr�r�r�r��nextObj�
nextOffset�nextLiner�r�rQrHrsrtrur�r�r�r�r�s                      rr(z!LabelInference.inferFromTextBelow�s������c�"���8�O��(�(��-��&�6��!�A�$�#�+�1�6��6�	��N�N�7�1�:�.�E��1�9���8�O�"�l�l�4�4�@�@��R�L��O�X�b�\�!�_�q�0�$�8�����(�(��*�=���x�=�A����8�O�&.�q�k�#����V����W�%���8�O��<�<�>�"&�"2�"2�7�E�3�"G��A�q�%��.2�.>�.>�s�.C�+�D�$��)��D�9�,�-�H��H�)�	�)��R�x���|�|�~��y�0�0��R�x���37���	���8�O�	�s�
E�E�E�
E�Ec�V�tj|�ry|j|�dk(S)NT�table)r�is_table�_getTagr7s  r�_isTablezLabelInference._isTable�s'������$���|�|�C� �G�+�+rc�V�tj|�ry|j|�dk(S)NT�tr)r�is_table_rowr�r7s  r�_isRowzLabelInference._isRow�s'���#�#�C�(���|�|�C� �D�(�(rc�T�tj|�ry|j|�dvS)NT)�td�th)r�
is_table_cellr�r7s  r�_isCellzLabelInference._isCell�s'���$�$�S�)���|�|�C� �L�0�0rc�N�d|cxkrtj|�kr||Syy)Nr)r	�get_child_count)r�row�colindexs   r�_getCellFromRowzLabelInference._getCellFromRow�s.����8�8�3�3�C�8�8��x�=� �9�rc�N�tj|�}|jd�S)N�tag)r	�get_attributes_dictrY)rr-�attrss   rr�zLabelInference._getTag�s!���,�,�S�1���y�y���rc��	��tj�|j�}|j|�sdgfStj��}||tj|�fvrdgfStj||j
�}|sdgfSdx}x}x}}	tj||j�}
tj|d��\}}|dkDritj|||dz
�}tj|||dz�}tj||dz
|�}tj||dz|�}	n�|
r�tj|�|
k(r�tj|�}
|j|
|
dz
�}|j|
|
dz�}tj|
�}tj|
�}|dkDr+tj||dz
�}|j||
�}|dztj|�kr+tj||dz�}|j||
�}	|r9|j��s(|j|�\}}|r|j!�|fS|j#��\}}}}|rm|j%��s\|j#|�\}}}}|||zz
}||ks|j��r(|j|�\}}|r|j!�|fSdx}}|r9|j|�\}}|r#|j'��r|j!�|fS|	r%|j)��s|j|	�\}}|rg|re|j#|�\} }!}"}#|j#|	�\}$}%}&}'||!|#zz
}(|%||zz
})|(|)kr|j!�fS|j!�fS|r|j!�fS|r|j!�fStj*|�}*t-|*�D�+cgc]}+tj|d|+���},}+|,rt/t1|j2|,��rdgfS|dkrdgfS�fd�}-tj4|�}.t-d|.�D�+cgc]}+tj||+|���}/}+t/t1|-|/��rdgfS|j|,|�\}}|r|j!�|fSdgfScc}+wcc}+w)anAttempt to infer the functional/displayed label of obj by looking
        at the contents of the surrounding table cells. Note that this approach
        assumes a simple table in which the widget is the sole occupant of its
        cell.

        Arguments
        - obj: the unlabeled widget

        Returns the text which we think is the label, or None.
        NF)�prefer_attributermrrc���tj|�sytjtj|d���S)NFr)r	r�r�have_same_role�	get_child)rHr-s �rrIz.LabelInference.inferFromTable.<locals>.isMatch7s7����+�+�A�.��"�1�1�(�2D�2D�Q��2J�C�P�P�Pr)r	�
find_ancestorr�rRr�r�r�r
�get_cell_coordinates�get_cell_at�get_index_in_parentr�r�r�r$r�r*r|r<r?rB�get_column_countr�r�r�rV�
get_row_count)0rr-�proximityForRight�cell�parent�grid�cellLeft�	cellRight�	cellAbove�	cellBelow�gridrow�rowindexr��	cellindex�
gridrowParent�rowAbove�rowBelow�label�sourcesr�r�r�r�rHrsrtrur��
labelAbove�
labelBelow�sourcesAbove�sourcesBelow�aboveX�aboveY�
aboveWidth�aboveHeight�belowX�belowY�
belowWidth�belowHeight�dAbove�dBelow�columnsr��firstRowrI�rows�cellss0 `                                              rr&zLabelInference.inferFromTable�s�����%�%�c�4�<�<�8���#�#�D�)���8�O��$�$�S�)����� 3� 3�F� ;�<�<���8�O��%�%�d�D�M�M�:�����8�O�7;�;��;�9�;�y�9��(�(��t�{�{�;��$�9�9�$�QV�W���(��b�=��*�*�4��8�a�<�H�H��+�+�D�(�H�q�L�I�I��+�+�D�(�Q�,��I�I��+�+�D�(�Q�,��I�I�
��,�,�T�2�g�=� �4�4�T�:�I��+�+�G�Y��]�C�H��,�,�W�i�!�m�D�I��3�3�G�<�H�$�/�/��8�M��!�|�#�-�-�m�X��\�J�� �0�0��9�E�	��!�|�h�6�6�t�<�<�#�-�-�m�X��\�J�� �0�0��9�E�	��D�-�-�c�2�!�:�:�8�D�N�E�7���{�{�}�g�-�-�*.�*:�*:�3�*?�'��d�H�i��T�/�/��4�"&�"2�"2�9�"=��A�q�%���D�8�O�,�H��,�,��0A�0A�#�0F�!%�!>�!>�y�!I���w�� �;�;�=�'�1�1�"&�&�
�Z��'+�'D�'D�Y�'O�$�J���d�o�o�c�2�!�'�'�)�<�7�7��T�/�/��4�'+�'D�'D�Y�'O�$�J���*�6:�6F�6F�y�6Q�3�F�F�J��6:�6F�6F�y�6Q�3�F�F�J���V�k�1�2�F��t�i�/�0�F����!�'�'�)�<�7�7��#�#�%�|�3�3���#�#�%�|�3�3���#�#�%�|�3�3��*�*�4�0��=B�7�^�L��G�'�'��a��3�L��L��4��t�~�~�x� @�A���8�O��a�<���8�O�	Q�
�$�$�T�*��AF�q�$��P�A��$�$�T�1�h�7�P��P���w��&�'���8�O��6�6�x��7I�J���w���;�;�=�'�)�)��R�x���+M��Qs�S/�S4N)T)rrm)r)�K)�)�)�2)�__name__�
__module__�__qualname__rr2r,r$r<r?rBrRrWrVr|r�r�r"r%r'r(r�r�r�r�r�r&�rrrr*s~��
!�9�v!�Q�M�M�2��,	#��:�6)�"�$*�X-�^&�P)�V,�)�1�� �mrr)�__doc__�__id__�__version__�__date__�
__copyright__�__license__�gi�require_version�
gi.repositoryrrr�ax_componentr�ax_hypertextr�	ax_objectr	�ax_tabler
�ax_textr�ax_utilitiesrrr�rr�<module>rs]��,K�������6�
���	�����7�E�"���%�%����%�[�[r

Zerion Mini Shell 1.0