Mini Shell

Direktori : /lib/python3.6/site-packages/orca/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/orca/__pycache__/caret_navigation.cpython-36.pyc

3

�2[�5�@srdZdZdZdZdZdZddlmZddlmZdd	lm	Z	dd
lm
Z
ddlmZddlmZGd
d�d�Z
dS)z3Provides an Orca-controlled caret for text content.z$Id$z
$Revision$z$Date$z$Copyright (c) 2013-2015 Igalia, S.L.ZLGPL�)�cmdnames)�debug)�input_event)�keybindings)�messages)�settings_managerc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
dd��Ze
dd��Ze
dd��Z
e
dd��Ze
dd��Ze
dd��Ze
dd��Ze
dd��Ze
dd��Ze
d d!��Ze
d"d#��Zd$S)%�CaretNavigationz=Implements the caret navigation support available to scripts.cCs:|o|jsd}tjtj|�||_|j�|_|j�|_dS)Nz1INFO: Caret navigation requires a script and app.)	�appr�println�
LEVEL_INFO�_script�_setup_handlers�	_handlers�_setup_bindings�	_bindings)�self�script�msg�r�&/usr/lib/python3.6/caret_navigation.py�__init__(s

zCaretNavigation.__init__cCs&||jj�krdS|j|jkr"dSdS)z0Returns True if handler is a navigation command.FT)r�valuesZfunction�_toggle_enabled)rZhandlerrrr�handles_navigation1s
z"CaretNavigation.handles_navigationcCs|jS)z)Returns the caret-navigation keybindings.)r)rrrr�get_bindings<szCaretNavigation.get_bindingscCs|jS)z&Returns the caret-navigation handlers.)r)rrrr�get_handlersAszCaretNavigation.get_handlerscCs�i}|jo|jjs|Stj|jtj�|d<tj|jtj�|d<tj|j	tj
�|d<tj|jtj�|d<tj|j
tj�|d<tj|jtj�|d<tj|jtj�|d<tj|jtj�|d<tj|jtj�|d	<tj|jtj�|d
<tj|jtj�|d<|S)z>Sets up and returns the caret-navigation input event handlers.�toggle_enabled�next_character�previous_character�	next_word�
previous_word�	next_line�
previous_line�
start_of_file�end_of_file�
start_of_line�end_of_line)rr	rZInputEventHandlerrrZCARET_NAVIGATION_TOGGLE�_next_characterZCARET_NAVIGATION_NEXT_CHAR�_previous_characterZCARET_NAVIGATION_PREV_CHAR�
_next_wordZCARET_NAVIGATION_NEXT_WORD�_previous_wordZCARET_NAVIGATION_PREV_WORD�
_next_lineZCARET_NAVIGATION_NEXT_LINE�_previous_lineZCARET_NAVIGATION_PREV_LINE�_start_of_fileZCARET_NAVIGATION_FILE_START�_end_of_fileZCARET_NAVIGATION_FILE_END�_start_of_lineZCARET_NAVIGATION_LINE_START�_end_of_lineZCARET_NAVIGATION_LINE_END)rZhandlersrrrr
FsJzCaretNavigation._setup_handlerscCs�tj�}|jo|jjs|S|jtjdtjtj|jj	d���|jtjdtjtj
|jj	d���|jtjdtjtj
|jj	d���|jtjdtjtj|jj	d���|jtjdtjtj|jj	d���|jtjd	tjtj
|jj	d
���|jtjdtjtj
|jj	d���|jtjd
tjtj
|jj	d���|jtjdtjtj
|jj	d���|jtjd
tjtj|jj	d���|jtjdtjtj|jj	d���|S)z6Sets up and returns the caret-navigation key bindings.ZF12rZRightrZLeftrrr ZDownr!ZUpr"ZEndr&ZHomer%r$r#)rZKeyBindingsrr	�addZ
KeyBindingZdefaultModifierMaskZORCA_MODIFIER_MASKr�getZNO_MODIFIER_MASKZCTRL_MODIFIER_MASK)rZbindingsrrrr�s�zCaretNavigation._setup_bindingscCsH|sdStj�}|jd�}|r(tj}ntj}|j|�|jd|�dS)zToggles caret navigation.FZcaretNavigationEnabledT)r�
getManager�
getSettingrZCARET_CONTROL_ORCAZCARET_CONTROL_APPZpresentMessageZ
setSetting)r�event�_settings_managerZenabled�stringrrrr�s
zCaretNavigation._toggle_enabledcCsD|sdS|jj�\}}|sdS|jj||�|j|�|j|�dS)zMoves to the next character.FT)�	utilities�nextContext�setCaretPosition�
updateBraille�sayCharacter)rr5�obj�offsetrrrr'�s

zCaretNavigation._next_charactercCsD|sdS|jj�\}}|sdS|jj||�|j|�|j|�dS)z Moves to the previous character.FT)r8�previousContextr:r;r<)rr5r=r>rrrr(s

z#CaretNavigation._previous_charactercCs�|sdS|jjdd�\}}|jj||�}|s0dS|dd|d	d|d
d}}}|rr|dj�rr|d8}|jj||�|j|�|j|�dS)zMoves to the next word.FT)�	skipSpacer������rDrDrD)r8r9�getWordContentsAtOffset�isalnumr:r;�sayWord)rr5r=r>�contents�endr7rrrr)s(

zCaretNavigation._next_wordcCsp|sdS|jjdd�\}}|jj||�}|s0dS|dd|dd}}|jj||�|j|�|j|�dS)zMoves to the previous word.FT)r@rAr)r8r?rEr:r;rG)rr5r=r>rH�startrrrr*%s

zCaretNavigation._previous_wordcCs�|sdS|j�r8tj�}|jd�r8d}tjtj|�dS|jj�}|sJdS|dd|dd}}|jj	||�|j
|�|j|�dS)zMoves to the next line.F�rewindAndFastForwardInSayAllz:INFO: inSayAll and rewindAndFastforwardInSayAll is enabledTrAr)�inSayAllrr3r4rr
rr8ZgetNextLineContentsr:�
speakContents�displayContents)rr5r6rrHr=rJrrrr+7s 



zCaretNavigation._next_linecCs�|sdS|j�r8tj�}|jd�r8d}tjtj|�dS|jj�}|sJdS|dd|dd}}|jj	||�|j
|�|j|�dS)zMoves to the previous line.FrKz:INFO: inSayAll and rewindAndFastforwardInSayAll is enabledTrAr)rLrr3r4rr
rr8ZgetPreviousLineContentsr:rMrN)rr5r6rrHr=rJrrrr,Os 



zCaretNavigation._previous_linecCst|sdS|jj�\}}|jj||�}|o.|ds4dS|dd|dd}}|jj||�|j|�|j|�dS)zMoves to the start of the line.FrArT)r8�getCaretContext�getLineContentsAtOffsetr:r<rN)rr5r=r>�linerJrrrr/hs

zCaretNavigation._start_of_linecCs�|sdS|jj�\}}|jj||�}|o.|ds4dS|dd|dd|d	d}}}|j�rx|d
j�rx|d8}|jj||�|j|�|j|�dS)zMoves to the end of the line.FrArrBrCTrDrDrDrD)r8rOrP�strip�isspacer:r<rN)rr5r=r>rQrIr7rrrr0zs(

zCaretNavigation._end_of_linecCsz|sdS|jj�}|jj|d�\}}|jj||�}|s:dS|dd|dd}}|jj||�|j|�|j|�dS)zMoves to the start of the file.FrArT)r8�
documentFrameZfindFirstCaretContextrPr:rMrN)rr5�documentr=r>rHrrrr-�s


zCaretNavigation._start_of_filec	Cs�|sdS|jj�}|jj|�}d}|jj|�}|r<|jd}x*|rf|jj||�\}}|sZP||}}q>W|jj||�}|s~dS|dd|dd}}|jj||�|j|�|j	|�dS)zMoves to the end of the file.FrArrBTrDrD)
r8rTZgetLastObjectInDocumentZqueryNonEmptyTextZcharacterCountr9rPr:rMrN)	rr5rUr=r>�textZlastobjZ
lastoffsetrHrrrr.�s*



zCaretNavigation._end_of_fileN)�__name__�
__module__�__qualname__�__doc__rrrrr
r�staticmethodrr'r(r)r*r+r,r/r0r-r.rrrrr%s$	AWrN)rZZ__id__�__version__Z__date__Z
__copyright__Z__license__�rrrrrrrrrrr�<module>s