%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__/bookmarks.cpython-312.pyc

�

g
f�/���dZddlZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
dd	lmZdd
lm
Z
ddlmZGd�d
�Zy)z:Provides the default implementation for bookmarks in Orca.�N�)�cmdnames)�debug)�keybindings)�input_event)�messages)�settings_manager)�
AXDocument)�AXObjectc��eZdZdZd�Zdd�Zdd�Zd�Zd�Zd�Z	d�Z
dd
�Zd�Zd�Z
d
�Zd�Zd�Zdd�Zdd�Zd�Zd�Zd�Zd�Zdd�Zy	)�	Bookmarksz&Represents a default bookmark handler.c���||_i|_g|_g|_|j	�d|_|j
d�|_tj�|_
y)NT)�_script�
_bookmarks�_saveObservers�_loadObservers�_loadBookmarks�_currentbookmarkindex�get_handlers�	_handlersr�KeyBindings�	_bindings)�self�scripts  �0/usr/lib/python3/dist-packages/orca/bookmarks.py�__init__zBookmarks.__init__&sV�������� ��� �������%)��"��*�*�4�0���$�0�0�2���c��|rCd}tjtj|d�|j�|jS|jj�r|j�|jS)z!Returns the bookmark keybindings.zBOOKMARKS: Refreshing bindings.T)r�printMessage�
LEVEL_INFO�_setup_bindingsr�isEmpty)r�refresh�
is_desktop�msgs    r�get_bindingszBookmarks.get_bindings0sd���3�C����u�/�/��d�;�� � �"��~�~���^�^�
#�
#�
%�� � �"��~�~�rc��|r7d}tjtj|d�|j�|jS)zReturns the bookmark handlers.zBOOKMARKS: Refreshing handlers.T)rrr �_setup_handlersr)rr#r%s   rrzBookmarks.get_handlers<s:���3�C����u�/�/��d�;�� � �"��~�~�rc��i|_tj|jtj
�|jd<tj|jtj�|jd<tj|jtj�|jd<tj|jtj�|jd<tj|jtj�|jd<d}tjtj |d�y)	z*Sets up the bookmark input event handlers.�goToPrevBookmark�goToNextBookmark�goToBookmark�addBookmark�
saveBookmarkszBOOKMARKS: Handlers set up.TN)rr�InputEventHandlerr*r�BOOKMARK_GO_TO_PREVIOUSr+�BOOKMARK_GO_TO_NEXTr,�BOOKMARK_GO_TOr-�BOOKMARK_ADDr.�
BOOKMARK_SAVErrr )rr%s  rr(zBookmarks._setup_handlersFs�����
�)�)��%�%��0�0�
2�	
���)�*�
�)�)��%�%��,�,�
.�	
���)�*�
�)�)��!�!��'�'�
)�	
���~�&�
�)�)�� � ��%�%�
'�	
���}�%�
�)�)��"�"��&�&�
(�	
����'�
,��
���5�+�+�S�$�7rc���tj�|_|jjtjdtj
tj|jjd���|jjtjdtj
tj|jjd���|jjtjdtj
tj|jjd���td�D]�}|jjtjt|dz�tj
tj|jjd���|jjtjt|dz�tj
tj|jjd�����d	}tjtj|d
�y)z"Sets up the bookmark key bindings.�br+r*r.�rr,r-zBOOKMARKS: Bindings set up.TN)rrr�add�
KeyBinding�defaultModifierMask�ORCA_MODIFIER_MASKr�get�ORCA_SHIFT_MODIFIER_MASK�ORCA_ALT_MODIFIER_MASK�range�strrrr )r�ir%s   rr!zBookmarks._setup_bindingsgs���%�0�0�2���������"�"���/�/��.�.����"�"�#5�6�	
8�	9�	
������"�"���/�/��4�4����"�"�#5�6�	
8�	9�	
������"�"���/�/��2�2����"�"�?�3�	
5�	6��q��
	8�A��N�N����&�&���A��J��3�3��2�2��N�N�&�&�~�6�	8�
9�
�N�N����&�&���A��J��3�3��6�6��N�N�&�&�}�5�	7�
8�
	8�,��
���5�+�+�S�$�7rc�:�|jj|�y�N)r�append�r�observers  r�addSaveObserverzBookmarks.addSaveObserver�������"�"�8�,rc�:�|jj|�yrC)rrDrEs  r�addLoadObserverzBookmarks.addLoadObserver�rHrNc��|xs|j}	|jj�}|j|}|j	|d|d|d|d�||j|<|jjj||�||_y#t
$r,|jj
tj�YywxYw)z2 Go to the bookmark indexed by inputEvent.hw_code �line�zone�word�charN)�hw_coder�getFlatReviewContextr�
setCurrent�KeyError�presentMessager�BOOKMARK_NOT_FOUND�flatReviewPresenter�present_itemr)rr�
inputEvent�index�context�context_infos      rr,zBookmarks.goToBookmark�s����+��+�+��	��l�l�7�7�9�G��?�?�5�1�L����|�F�3�\�&�5I� ,�V� 4�l�6�6J�
L�%1�D�O�O�E�"�
	
���(�(�5�5�f�j�I�&+��"���	��L�L�'�'��(C�(C�D��	�s�AB�2C
�C
c���|jj�}|j|�|j|j<|jjtj�y)z9 Add an in-page accessible object bookmark for this key. N)rrQ�_contextToBookmarkrrPrTr�BOOKMARK_ENTERED)rrrXrZs    rr-zBookmarks.addBookmark�sK���,�,�3�3�5��.2�.E�.E�g�.N����
�*�*�+����#�#�H�$=�$=�>rc�.�	|j|j�|jjtj
�|jD]	}|��y#t$r,|jjtj�Y�MwxYw)z% Save the bookmarks for this script. N)	�saveBookmarksToDiskrrrTr�BOOKMARKS_SAVED�IOError�BOOKMARKS_SAVED_FAILUREr)rrrX�os    rr.zBookmarks.saveBookmarks�sy��	J��$�$�T�_�_�5��L�L�'�'��(@�(@�A�
�$�$�	�A�
�C�	��	�	J��L�L�'�'��(H�(H�I�	J�s�AA�2B�Bc���t|jj��}t|�dk(r*|jjtj�yt|�dk(s|j�|jd|d��y	|j|j�}|jd||dz��y#tttf$r|jd|d��YywxYw)zu Go to the next bookmark location.  If no bookmark has yet to be
        selected, the first bookmark will be used.  rNr�rY��sortedr�keys�lenrrTr�BOOKMARKS_NOT_FOUNDrr,rY�
ValueErrorrS�
IndexError�rrrX�hwkeysrYs     rr+zBookmarks.goToNextBookmark�s���
����,�,�.�/���v�;�!���L�L�'�'��(D�(D�E��
��[�A�
��!;�!;�!C����d�&��)��4��	5��L�L��!;�!;�<�E����d�&��q��/��:���H�j�1�	5����d�&��)��4�	5���4C�*C0�/C0c���t|jj��}t|�dk(r*|jjtj�yt|�dk(s|j�|jd|d��y	|j|j�}|jd||dz
��y#tttf$r|jd|d��YywxYw)Nrrrfrgrns     rr*zBookmarks.goToPrevBookmark�s�������,�,�.�/���v�;�!���L�L�'�'��(D�(D�E��
��[�A�
��!;�!;�!C����d�&��)��4��	5��L�L��!;�!;�<�E����d�&��q��/��:���H�j�1�	5����d�&��)��4�	5�rpc�f�|j�xsi|_|jD]	}|��y)z# Load this scripts saved bookmarks.N)�readBookmarksFromDiskrr)rrds  rrzBookmarks._loadBookmarks�s3���4�4�6�<�"����$�$�	�A�
�C�	rc���|xs(|jjjd�d}tj�j�}|sytjj|d�}	ttjj||�d��d�}tj|j�}|j�|S#ttt f$rYywxYw)zc Read saved bookmarks from disk.  Currently an unpickled object
        that represents a bookmark � rN�	bookmarks�.pkl�r)r�name�splitr	�
getManager�getPrefsDir�os�path�join�open�pickle�load�buffer�closerb�EOFError�OSError)r�filename�orcaDir�orcaBookmarksDir�	inputFilervs      rrszBookmarks.readBookmarksFromDisk�s����>�t�|�|�0�0�6�6�s�;�A�>��"�-�-�/�;�;�=�����7�7�<�<���=��	��b�g�g�l�l�,<�#�*�D�)�+�,/�1�I����I�$4�$4�5�I��O�O�������7�+�	��	�s�3AC�C(�'C(c�,�|xs(|jjjd�d}tj�j�}tjj|d�}	t
j|�ttjj||�d��dtj�}tj||j �|j#�y#t$rt
j|�Y��wxYw)zN Write bookmarks to disk.  bookmarksObj must be a pickleable 
        object. rurrvrw�wN)rryrzr	r{r|r}r~r�statr��mkdirr��O_CREATr��dumpr�r�)r�bookmarksObjr�r�r��outputs      rr`zBookmarks.saveBookmarksToDisks����>�t�|�|�0�0�6�6�s�;�A�>��"�-�-�/�;�;�=���7�7�<�<���=��	'��G�G�$�%��r�w�w�|�|�%5��j��%�'�(+�R�Z�Z�9�����L�&�-�-�0�������	'��H�H�%�&�	'�s�0C2�2D�Dc��i}|j|d<|j|d<|j|d<|j|d<|S)z6Converts a flat_review.Context object into a bookmark.rMrOrNrL)�	zoneIndex�	charIndex�	wordIndex�	lineIndex)rrZr[s   rr]zBookmarks._contextToBookmarksM����&�0�0��V��&�0�0��V��&�0�0��V��&�0�0��V���rc�z�|jj�}|j|d|d|d|d�|S)z6Converts a bookmark into a flat_review.Context object.rLrMrNrO)rrQrR)r�bookmarkrZs   r�_bookmarkToContextzBookmarks._bookmarkToContextsD���,�,�3�3�5�����8�F�+�X�f�-=�#�F�+�X�f�-=�	?��rc���tj|jjj	��}|r3t
jj|�}dj|dd�Sy)zpReturns the URI key for a given page as a URI stripped of
        parameters?query#fragment as seen in urlparse.�r�N)	r
�get_urir�	utilities�
documentFrame�urllib�parse�urlparser)r�uri�
parsed_uris   r�	getURIKeyzBookmarks.getURIKey&sV��� � ����!7�!7�!E�!E�!G�H������.�.�s�3�J��7�7�:�a��?�+�+�rc��|jjj�}|D]}tj||�}|r�|S|S)zPReturn the object with the given path (relative to the
        document frame). )rr�r�r�	get_child)rr~�	returnobj�childnumbers    r�	pathToObjzBookmarks.pathToObj0sQ���L�L�*�*�8�8�:�	��	�K� �*�*�9�k�B�I�����	�
�rc��|s'|jjj�\}}|sgS|jjj|�rgSg}|j	tj|��tj|�}|rs|jjj|�r|j�|S|j	tj|��tj|�}|r�sgS)z�Given an object, return it's path from the root accessible.  If obj
        is not provided, the current caret context is used. )	rr��getCaretContext�
isDocumentrDr�get_index_in_parent�
get_parent�reverse)r�	start_obj�characterOffsetr~�ps     r�
_objToPathzBookmarks._objToPath;s����+/�<�<�+A�+A�+Q�+Q�+S�(�Y����I��<�<�!�!�,�,�Y�7��I������H�0�0��;�<����	�*����|�|�%�%�0�0��3��������K�K��4�4�Q�7�8��#�#�A�&�A���	r)FT)FrC)�__name__�
__module__�__qualname__�__doc__rr&rr(r!rGrJr,r-r.r+r*rrsr`r]r�r�r�r��rrr
r
$sk��0�3�
��8�B*8�X-�-�+�(?�
�5�05�*��$� ���	�rr
)r�r�r}�urllib.parser�r�rrrrrr	�ax_documentr
�	ax_objectrr
r�rr�<module>r�s8��(A�
�	��������#��m�mr

Zerion Mini Shell 1.0