%PDF- %PDF-
Mini Shell

Mini Shell

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

�

g
f�c���ddlZejdd�ddlmZddlZddlZddlZddlmZddlm	Z	ddlm
Z
dd	lmZdd
lmZddlm
Z
ddlmZdd
lmZddlmZddlmZddlmZdZdZdZdZdZdZdZGd�d�ZGd�d�Zy)�N�Atspiz2.0)r)�GLib�)�cmdnames)�debug)�
focus_manager)�keybindings)�messages)�input_event)�settings_manager)�AXCollection)�AXObject)�AXText������-�	c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�
PriorityQueuez� This class represents a thread **UNSAFE** priority queue where priority
    is determined by the given integer priority.  The entries are also
    maintained in chronological order.

    TODO: experiment with Queue.Queue to make thread safe
    c��g|_y�N��queue��selfs �2/usr/lib/python3/dist-packages/orca/liveregions.py�__init__zPriorityQueue.__init__*s	����
�c�p�tj|j|tj�||f�y)zS Add a new element to the queue according to 1) priority and
        2) timestamp. N)�bisect�insort_leftr�time)r�data�priority�objs    r�enqueuezPriorityQueue.enqueue-s'��	���4�:�:��$�)�)�+�t�S�'I�Jrc�8�|jjd�S)z2get the highest priority element from the queue.  r)r�poprs r�dequeuezPriorityQueue.dequeue2s���z�z�~�~�a� � rc��g|_y)z Clear the queue Nrrs r�clearzPriorityQueue.clear6s	����
rc���tj���fd�}tt||j��|_y)zC Purge items from the queue that are older than the keepalive time c�*��|xr|dtz�kDS)Nr)�MSG_KEEPALIVE_TIME)�item�currenttimes �r�myfilterz0PriorityQueue.purgeByKeepAlive.<locals>.myfilter>s����F�D��G�&8�8�;�F�FrN)r#�list�filterr)rr2r1s  @r�purgeByKeepAlivezPriorityQueue.purgeByKeepAlive:s-����i�i�k��	G��&��4�:�:�6�7��
rc�X���fd�}tt||j��|_y)ze Purge items from the queue that have a lower than or equal priority
        than the given argument c���|xr|d�kDS�Nr�)r0r%s �rr2z/PriorityQueue.purgeByPriority.<locals>.myfilterGs����.�D��G�h�.�.rN)r3r4r)rr%r2s ` r�purgeByPriorityzPriorityQueue.purgeByPriorityCs!���	/��&��4�:�:�6�7��
rc�,�t|j�S)z  Return the length of the queue )�lenrrs r�__len__zPriorityQueue.__len__Ls���4�:�:��rN)�__name__�
__module__�__qualname__�__doc__rr'r*r,r5r:r=r9rrrr#s+����K�
!��8�8�rrc���eZdZd�Zd d�Zd!d�Zd�Zd�Zd"d�Zd"d�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd#d�Zd�Zd�Zd�Zd�Z y)$�LiveRegionManagerc��||_t�|_d|_|j	d�|_t
j�|_|j|j|j|jg|_
g|_d|_d|_d|_d|_|j'�|j(j+|j,�|j(j/|j&�y)NFT)�_scriptr�	msg_queue�
_suspended�get_handlers�	_handlersr	�KeyBindings�	_bindings�advancePoliteness�setLivePolitenessOff�toggleMonitoring�reviewLiveAnnouncement�	functions�	msg_cache�_politenessOverrides�_restoreOverrides�lastliveobj�
monitoring�bookmarkLoadHandler�	bookmarks�addSaveObserver�bookmarkSaveHandler�addLoadObserver)r�scripts  rrzLiveRegionManager.__init__Rs������&���� ����*�*�4�0���$�0�0�2����0�0��3�3��/�/��5�5�7������%)��!�!%��� ������	
� � �"����(�(��)A�)A�B����(�(��)A�)A�Brc��|rCd}tjtj|d�|j�|jS|jj�r|j�|jS)z,Returns the live-region-manager keybindings.z)LIVE REGION MANAGER: Refreshing bindings.T)r�printMessage�
LEVEL_INFO�_setup_bindingsrK�isEmpty)r�refresh�
is_desktop�msgs    r�get_bindingszLiveRegionManager.get_bindingssd���=�C����u�/�/��d�;�� � �"��~�~���^�^�
#�
#�
%�� � �"��~�~�rc��|r7d}tjtj|d�|j�|jS)z)Returns the live-region-manager handlers.z)LIVE REGION MANAGER: Refreshing handlers.T)rr]r^�_setup_handlersrI)rrarcs   rrHzLiveRegionManager.get_handlers�s:���=�C����u�/�/��d�;�� � �"��~�~�rc��i|_tj|jtj
|j��|jd<tj|jtj|j��|jd<tj|jtj|j��|jd<tj|jtj|j��|jd<d|j��}tjtj|d�y)	z5Sets up the live-region-manager input event handlers.)�enabled�advanceLivePolitenessrM�monitorLiveRegionsrOz1LIVE REGION MANAGER: Handlers set up. Suspended: TN)rIr�InputEventHandlerrLr�LIVE_REGIONS_ADVANCE_POLITENESSrGrM�LIVE_REGIONS_SET_POLITENESS_OFFrN�LIVE_REGIONS_MONITORrO�LIVE_REGIONS_REVIEWrr]r^)rrcs  rrfz!LiveRegionManager._setup_handlers�s#�����
�)�)��&�&��8�8�"�o�o�-�
/�	
���.�/�
�)�)��)�)��8�8�"�o�o�-�
/�	
���-�.�
�)�)��%�%��-�-�"�o�o�-�
/�	
���+�,�
�)�)��+�+��,�,�"�o�o�-�
/�	
���/�0�B�$�/�/�AR�S��
���5�+�+�S�$�7rc�$�tj�|_|jjtjdtj
tj|jjd�d|j��|jjtjdtj
tj|jjd�d|j��|jjtjdtj
tj|jjd�d|j��dD]u}|jjtj|tj
tj|jjd�d|j���wtj�j|j|jd�|_d	|j��}t!j"t j$|d
�|jg}t!j&t j$|d
�y)z-Sets up the live-region-manager key bindings.�	backslashrirrMrj)	�F1�F2�F3�F4�F5�F6�F7�F8�F9rOFz1LIVE REGION MANAGER: Bindings set up. Suspended: TN)r	rJrK�add�
KeyBinding�defaultModifierMask�NO_MODIFIER_MASKrI�getrG�SHIFT_MODIFIER_MASK�ORCA_SHIFT_MODIFIER_MASK�ORCA_MODIFIER_MASKr�
getManager�overrideKeyBindingsrr]r^�printTokens)r�keyrc�tokenss    rr_z!LiveRegionManager._setup_bindings�s���%�0�0�2���������"�"���/�/��,�,����"�"�#:�;���O�O�#�

%�	&�	
������"�"���/�/��/�/����"�"�#9�:���O�O�#�

%�	&�	
������"�"���/�/��4�4����"�"�#7�8���O�O�#�

%�	&�J�	*�C��N�N����&�&���3�3��2�2��N�N�&�&�'?�@�����'�
)�
*�	*�*�4�4�6�J�J��N�N�D�N�N�E�3���B�$�/�/�AR�S��
���5�+�+�S�$�7��.�.�!��
���%�*�*�F�D�9rc��d}|r|d|��z
}tjtj|d�|jjD]}|jj|d���!|j
d�|_|jd�|_|jjD]*}|jj||j���,y)z4Refreshes live region bindings and grabs for script.z2LIVE REGION MANAGER: Refreshing bindings and grabs�: T)�includeGrabsN)rr]r^rK�keyBindings�removerHrIrdr{rG)rr[�reasonrc�bindings     r�refresh_bindings_and_grabsz,LiveRegionManager.refresh_bindings_and_grabs�s���C����R��x�=� �C�
���5�+�+�S�$�7��~�~�1�1�	B�G����%�%�g�D�%�A�	B��*�*�4�0����*�*�4�0����~�~�1�1�	N�G����"�"�7�T�_�_�9L�"�M�	Nrc���||jk(ryd|��}|r|d|��z
}tjtj|d�||_|j	|d|���y)zASuspends live region commands independent of the enabled setting.Nz)LIVE REGION MANAGER: Commands suspended: r�TzSuspended changed to )rGrr]r^r�)rr[�	suspendedr�rcs     r�suspend_commandsz"LiveRegionManager.suspend_commands�si������'��9�)��E����R��x�=� �C�
���5�+�+�S�$�7�#����'�'��2G�	�{�0S�Trc���i}|jjj�}|jj	�D]\}}|d|k(s
|t
k7s�|||<�||_yr8)rErW�	getURIKeyrR�items�	LIVE_NONE)r�
newpoliteness�
currenturir��values     r�resetzLiveRegionManager.resetsj���
��\�\�+�+�5�5�7�
��3�3�9�9�;�	+�J�C���1�v��#�u�	�'9�%*�
�c�"�	+�%2��!rc�f�|jjj|jd��y)zBookmark save callback�
politeness��filenameN)rErW�saveBookmarksToDiskrRrs rrYz%LiveRegionManager.bookmarkSaveHandlers+�������2�2�4�3L�3L�=I�	3�	Krc�b�|jjjd��xsi|_y)zBookmark load callbackr�r�N)rErW�readBookmarksFromDiskrRrs rrVz%LiveRegionManager.bookmarkLoadHandlers/��
	
�����4�4�l�4�K�	�
�	
�!rc��|j|j�}|tk(ry|tk(r
|js\y|t
k(rnQ|tk(r |jjt
�n(|tk(r|jjt�|j|�}|r`t|j�dk(r tjd|j�|jj|||j�yy)zMain live region event handlerNr�d)�_getLiveType�source�LIVE_OFFr�rU�LIVE_POLITE�LIVE_ASSERTIVErFr:�	LIVE_RUDE�_getMessager<r�timeout_add�pumpMessagesr')r�eventr��messages    r�handleEventzLiveRegionManager.handleEvents����&�&�u�|�|�4�
���!����"��?�?��
�;�
&��
�N�
*��N�N�*�*�;�7�
�9�
$��N�N�*�*�>�:��"�"�5�)����4�>�>�"�a�'�� � ��d�&7�&7�8��N�N�"�"�7�J����E�rc�0�t|j�dkDr�tjtjd�|jj�|jj
�\}}}}|d|dk(r|d}n|d|dz}|jr|jj|�n'd}tjtj|d�||_|j|�|js|jj�dt|j���}tjtj|d�tjtjd�t|j�dkDS)	z� Main gobject callback for live region support.  Handles both
        purging the message queue and outputting any queued messages that
        were queued up in the handleEvent() method.
        rz(
vvvvv PRESENT LIVE REGION MESSAGE vvvvv�labels�contentz6INFO: Not presenting message because monitoring is offTz!LIVE REGIONS: messages in queue: z(^^^^^ PRESENT LIVE REGION MESSAGE ^^^^^
)
r<rFrr]�eventDebugLevelr5r*rUrE�presentMessager^rT�
_cacheMessage)rr��	timestampr�r&�uttsrcs       rr�zLiveRegionManager.pumpMessages7sM���t�~�~���"����u�4�4�6a�b��N�N�+�+�-�26�.�.�2H�2H�2J�/�J�	�7�C��x� �G�I�$6�6��y�)���x�(�7�9�+=�=��������+�+�D�1�N���"�"�5�#3�#3�S�$�?� #�D��
���t�$�����N�N�+�+�-�1�#�d�n�n�2E�1F�G��
���5�+�+�S�$�7�
���5�0�0�2]�^��4�>�>�"�Q�&�&rc��g}|jjj�}|jD]P\}}||k(s�t	|t
�s�|j
|jjj|���R|S)zXReturn the live objects that are registered and have a politeness
        of LIVE_NONE. )rErWr�rR�
isinstance�tuple�append�	pathToObj)r�retvalr��uri�objectids     r�getLiveNoneObjectsz$LiveRegionManager.getLiveNoneObjects`su�����\�\�+�+�5�5�7�
�!�6�6�	J�M�C���j� �Z��%�%@��
�
�d�l�l�4�4�>�>�x�H�I�	J��
rc��tj�jd�s*|jj	t
j�ytj�j�}|j|�}|jjj�}	|j||f}|tk(s	|t k(r?t"|j||f<|jj	t
j$�y|t"k(r?t&|j||f<|jj	t
j(�y|t&k(r?t*|j||f<|jj	t
j,�y|t*k(r?t|j||f<|jj	t
j.�yy#t$r|j|�}Y��GwxYw)z0Advance the politeness level of the given object�inferLiveRegionsN)rr��
getSettingrEr�r
�LIVE_REGIONS_OFFr�get_locus_of_focus�_getObjectIdrWr�rR�KeyError�_liveStringToTyper�r�r��LIVE_REGIONS_LEVEL_POLITEr��LIVE_REGIONS_LEVEL_ASSERTIVEr��LIVE_REGIONS_LEVEL_RUDE�LIVE_REGIONS_LEVEL_OFF)rr[�
inputEventr&r�r��cur_prioritys       rrLz#LiveRegionManager.advancePolitenessjs��� �*�*�,�7�7�8J�K��L�L�'�'��(A�(A�B���&�&�(�;�;�=���$�$�S�)���l�l�$�$�.�.�0��	7�
 �4�4�c�8�_�E�L��8�#�|�y�'@�9D�D�%�%�s�H�o�6��L�L�'�'��(J�(J�K�
�[�
(�9G�D�%�%�s�H�o�6��L�L�'�'��(M�(M�N�
�^�
+�9B�D�%�%�s�H�o�6��L�L�'�'��(H�(H�I�
�Y�
&�9A�D�%�%�s�H�o�6��L�L�'�'��(G�(G�H�'���	7��1�1�#�6�L�	7�s�&G!�!G?�>G?c��|jrz|jjj|jd�|jj	|jjj|jd��yy)z^Move the caret to the last announced live region and speak the
        contents of that objectrN)rTrE�	utilities�setCaretPosition�
speakContents�getObjectContentsAtOffsetrs r�goLastLiveRegionz"LiveRegionManager.goLastLiveRegion�sf������L�L�"�"�3�3�D�4D�4D�a�H��L�L�&�&�t�|�|�'=�'=�'W�'W�'+�'7�'7��(<�
=�rc��t|jdd�}tj�j	d�s*|j
j
tj�y|t|j�kDr*|j
j
tj�y|j
j
|j|�y)z%Speak the given number cached messagerNr�)�int�event_stringrr�r�rEr�r
r�r<rQ�LIVE_REGIONS_NO_MESSAGE)rr[r��msgnums    rrOz(LiveRegionManager.reviewLiveAnnouncement�s����Z�,�,�Q�R�0�1���*�*�,�7�7�8J�K��L�L�'�'��(A�(A�B���C����'�'��L�L�'�'��(H�(H�I��L�L�'�'�����w�(?�@rc���tj�jd�s*|jj	t
j�y|jjj�}|jjj�}|jr�|jj	t
j�|jj�tj|j �|_|j j%�D]}t&|j |<�|j)|�}|D](}|j+|�}t&|j ||f<�*d|_y|j"j-�D]\}	}
|
|j |	<�|jj	t
j.�d|_y)z]User toggle to set all live regions to LIVE_OFF or back to their
        original politeness.r�NFT)rr�r�rEr�r
r�r��
documentFramerWr�rU�LIVE_REGIONS_ALL_OFFrFr,�copyrRrS�keysr��getAllLiveRegionsr�r��LIVE_REGIONS_ALL_RESTORED)rr[r��docframer��override�matches�matchr�r�r�s           rrMz&LiveRegionManager.setLivePolitenessOff�s��� �*�*�,�7�7�8J�K��L�L�'�'��(A�(A�B���<�<�)�)�7�7�9���l�l�$�$�.�.�0���?�?��L�L�'�'��(E�(E�F��N�N� � �"�&*�Y�Y�t�/H�/H�%I�D�"�!�5�5�:�:�<�
?��6>��)�)�(�3�
?��,�,�X�6�G� �
F���,�,�U�3��=E��)�)�3��/�:�
F�
$�D�O�#�4�4�:�:�<�
7�
��U�16��)�)�#�.�
7��L�L�'�'��(J�(J�K�"�D�Orc��g}gd�}|D]}|jd|z��tj|��}tj||�}dt	|��d�}tjt
j|d�|S)N)�off�polite�	assertivezcontainer-live:)�
attributeszLIVE REGIONS: z regions foundT)r�r
�create_match_rule�get_all_matchesr<rr]r^)r�document�attrs�levels�level�rule�resultrcs        rr�z#LiveRegionManager.getAllLiveRegions�s�����/���	4�E��L�L�*�U�2�3�	4��-�-��?���-�-�h��=���s�6�{�m�>�:��
���5�+�+�S�$�7��
rc�d�|j|�}|jjj�}g}t	j
|tjj�}|rk|jd�}tj|�}|j�t	j|�j�k7r|j|�	|j||f}	|j!|	�}
|s|
dk7r"|jt$j&|
z�|S#t"$rd}
Y�8wxYw)znUsed in conjunction with whereAmI to output description and
        politeness of the given live region objectr�none)r�rErWr�r�get_relationr�RelationType�DESCRIBED_BY�
get_targetr�get_all_text�strip�get_descriptionr�rR�_liveTypeToStringr�r
�LIVE_REGIONS_LEVEL)rr&�argsr�r��results�relation�	targetobj�description�livepriority�liveprioritystrs           r�generateLiveRegionDescriptionz/LiveRegionManager.generateLiveRegionDescription�s���$�$�S�)���l�l�$�$�.�.�0�����(�(��e�.@�.@�.M�.M�N��� �+�+�A�.�I�
!�-�-�i�8�K�� � �"�h�&>�&>�s�&C�&I�&I�&K�K����{�+�	%��4�4�c�8�_�E�L�"�4�4�\�B�O��o��/��N�N�8�6�6��H�I�����	%�$�O�	%�s�"D!�!D/�.D/c�N���fd�}||�r|Stj||�S)Nc�D���j|�jd�S)N�atomic)�_getAttrDictionaryr)�xrs �r�isContainerz5LiveRegionManager._findContainer.<locals>.isContainer�s����*�*�1�-�1�1�(�;�;r)r�
find_ancestor)rr&r
s`  r�_findContainerz LiveRegionManager._findContainer�s*���	<��s���J��%�%�c�;�7�7rc��|j|j�}d}d}|jjd�ru|j	d�dk(r1|j
jj|j�}�n
|j
jj|j�}n�|jjd�r�|j	d�dk7rnd|jvr
|j}n�|j
jj|j|j|j|jz�}n@|j|j�}|j
jj|�}|sy|j�}tj|j�xstj|j�j�}|r||k7r|}|j	d�d	k(r;||z}|j
j!�|j
j#|�y|g|gd
�S)z4Gets the message associated with a given live event.�zobject:children-changed:addzcontainer-atomic�truezobject:text-changed:insertuN�channel�notify)r�r�)rr��type�
startswithrrEr��
expandEOCs�any_data�detail1�detail2rr�r�get_namer��presentationInterruptr�)rr�r�r�r��	container�namer�s        rr�zLiveRegionManager._getMessages����'�'����5������
�:�:� � �!>�?��y�y�+�,��6��,�,�0�0�;�;�E�L�L�I���,�,�0�0�;�;�E�N�N�K��
�Z�Z�
"�
"�#?�
@��y�y�+�,��6��5�>�>�1�#�n�n�G�"�l�l�4�4�?�?����e�m�m�U�]�]�U�]�]�5R�T�G�!�/�/����=�	��,�,�0�0�;�;�I�F�����-�-�/��
�!�!�%�,�,�/�Y�8�3K�3K�E�L�L�3Y�`�`�b���D�G�O��F��9�9�Y��8�+��G�#�D��L�L�.�.�0��L�L�'�'��-��"�)�v�h�7�7rc�8�|jj�yr)rFr,rs r�
flushMessageszLiveRegionManager.flushMessages5s�������rc��|jj|�t|j�tkDr|jj	d�yy)z6Cache a message in our cache list of length CACHE_SIZErN)rQr�r<�
CACHE_SIZEr))rr�s  rr�zLiveRegionManager._cacheMessage8s<�������d�#��t�~�~���+��N�N���q�!�,rc� �|j|�}|jjj�}||f|jvr|j||fS|j|�}|tk(r|jr||j||f<|S)z�Returns the live politeness setting for a given object. Also,
        registers LIVE_NONE objects in politeness overrides when monitoring.)r�rErWr�rRr�r�rU)rr&r�r��livetypes     rr�zLiveRegionManager._getLiveType>s����$�$�S�)���l�l�$�$�.�.�0����?�d�7�7�7��,�,�c�8�_�=�=��-�-�c�2�H��9�$����=E��)�)�3��/�:��Orc��|j|�}|�|j|�S	|dS#t$r|j|�cYSwxYw)zRReturns the HTML 'id' or a path to the object is an HTML id is
        unavailable�id)r�_getPathr�)rr&r�s   rr�zLiveRegionManager._getObjectIdOsU���'�'��,���=��=�=��%�%�	&���;����	&��=�=��%�%�	&�s�+�A�ANc���|xs|j|�}	|ddk(rtS|ddk(rtS|ddk(rtS|ddk(rtSt
S#t$r	t
cYSwxYw)z.Returns the politeness enum for a given objectzcontainer-liver�r�r��rude)rr�r�r�r�r�r�)rr&r�r�s    rr�z#LiveRegionManager._liveStringToTypeZs����:�d�5�5�c�:��	��%�&�%�/����'�(�H�4�"�"��'�(�K�7�%�%��'�(�F�2� � � � ���	���	�s'�
A�
A�
A�
A�A�A'�&A'c�h�|tk(ry|tk(ry|tk(ry|tk(ry|tk(ryy)z@Returns the politeness level as a string given a politeness enumr�r�r�r&r��unknown)r�r�r�r�r�)rr�s  rr�z#LiveRegionManager._liveTypeToStringks<����!��
�;�
&��
�>�
)��
�9�
$��
�9�
$��rc�,�tj|�Sr)r�get_attributes_dict)rr&s  rrz$LiveRegionManager._getAttrDictionaryzs���+�+�C�0�0rc�.�|jjj�}g}	||k(stj|��|j�t
|�S|jtj|��tj|�}�o)z_ Returns, as a tuple of integers, the path from the given object
        to the document frame.)	rEr�r�r�
get_parent�reverser�r��get_index_in_parent)rr&r��paths    rr$zLiveRegionManager._getPath}sz���<�<�)�)�7�7�9������h��(�"5�"5�c�":�"B������T�{�"��K�K��4�4�S�9�:��%�%�c�*�C�rc��tj�jd�sNtj�jdd�|jjtj�ytj�jdd�|j�|jjtj�y)Nr�TF)
rr�r��
setSettingrEr�r
�LIVE_REGIONS_MONITORING_ONr�LIVE_REGIONS_MONITORING_OFF)rr[r�s   rrNz"LiveRegionManager.toggleMonitoring�s����*�*�,�7�7�8J�K��'�'�)�4�4�5G��N��L�L�'�'��(K�(K�L��'�'�)�4�4�5G��O���� ��L�L�'�'��(L�(L�Mr)FT)F)rr)!r>r?r@rrdrHrfr_r�r�r�rYrVr�r�r�rLr�rOrMr�rrr�rr�r�r�r�r�rr$rNr9rrrCrCQs���+C�Z
��8�@2:�hN�"U�2�K�
�F�2''�R�I�D=�A�+#�Z� �D8�-8�^�"��"	&��"
�1�
+�NrrC)�gi�require_version�
gi.repositoryrr!r�r#rrrrrr	r
rr�
ax_collectionr
�	ax_objectr�ax_textrr�r�r�r�r�r/rrrCr9rr�<module>r:s���	�����7�E�"��
�����������'������	������	����
�+�+�\N�Nr

Zerion Mini Shell 1.0