Mini Shell

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

3

�2[�N�@s
dZdZdZdZdZdZddlZdd	lmZdd
lm	Z	ddlm
Z
ddlmZdd
lmZddlm
Z
ddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZe
j�Zej�Zej�ZGdd�d�ZdS)a$Each script maintains a set of key bindings, braille bindings, and
AT-SPI event listeners.  The key bindings are an instance of
KeyBindings.  The braille bindings are also a dictionary where the
keys are BrlTTY command integers and the values are instances of
InputEventHandler.  The listeners field is a dictionary where the keys
are AT-SPI event names and the values are function pointers.

Instances of scripts are intended to be created solely by the
script manager.

This Script class is not intended to be instantiated directly.
Instead, it is expected that subclasses of the Script class will be
created in their own module.  The module defining the Script subclass
is also required to have a 'getScript(app)' method that returns an
instance of the Script subclass.  See default.py for an example.z$Id$z
$Revision$z$Date$z-Copyright (c) 2005-2009 Sun Microsystems Inc.ZLGPL�N�)�braille_generator)�debug)�
event_manager)�
formatting)�label_inference)�keybindings)�
orca_state)�script_manager)�script_utilities)�settings)�settings_manager)�sound_generator)�speech_generator)�structural_navigation)�	bookmarks)�tutorialgeneratorc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLS)M�Scriptz:The specific focus tracking scripts for applications.
    cCs\||_|rNy|jj|_WqTttfk
rJd}tjtj|d�d|_YqTXnd|_|jd|jd7_|j�|_	d|_
|j�|_|j
�|_|j�|_|j�|_|j�|_|j�|_|j�|_i|_i|_|j�|j�|_|j�|_|j �|_!|j"�|_#|j$�|_%|j&�|_'i|_(i|_)|j*�|_+|j,�|_-d|_.d|_/d|j}tjtj|d�dS)	z�Creates a script for the given application, if necessary.
        This method should not be called by anyone except the
        script manager.

        Arguments:
        - app: the Python Accessible application to create a script for
        z*ERROR: Could not get name of script app %sT�defaultz	 (module=�)FzSCRIPT: %s initializedN)0�app�name�LookupError�RuntimeErrorr�println�
LEVEL_INFO�
__module__�getListeners�	listeners�presentIfInactive�getUtilitiesZ	utilities�getLabelInferenceZlabelInference�getStructuralNavigation�structuralNavigation�getCaretNavigationZcaretNavigation�getBookmarksr�getLiveRegionManagerZliveRegionManager�getChatZchatZinputEventHandlersZpointOfReference�setupInputEventHandlers�getKeyBindings�keyBindings�getBrailleBindings�brailleBindings�
getFormattingr�getBrailleGeneratorZbrailleGenerator�getSoundGeneratorZsoundGenerator�getSpeechGeneratorZspeechGenerator�generatorCache�
eventCache�
getSpellCheckZ
spellcheck�getTutorialGeneratorZtutorialGeneratorZfindCommandRun�_lastCommandWasStructNav)�selfr�msg�r8�/usr/lib/python3.6/script.py�__init__EsH
















zScript.__init__cCsiS)z�Sets up the AT-SPI event listeners for this script.

        Returns a dictionary where the keys are AT-SPI event names
        and the values are script methods.
        r8)r6r8r8r9r~szScript.getListenerscCsdS)zlDefines InputEventHandler fields for this script that can be
        called by the key and braille bindings.Nr8)r6r8r8r9r(�szScript.setupInputEventHandlerscCstj�S)zkDefines the key bindings for this script.

        Returns an instance of keybindings.KeyBindings.
        )r�KeyBindings)r6r8r8r9r)�szScript.getKeyBindingscCstj�S)z9Returns the toolkit-specific keybindings for this script.)rr;)r6r8r8r9�getToolkitKeyBindings�szScript.getToolkitKeyBindingscCstj�S)z=Returns the application-specific keybindings for this script.)rr;)r6r8r8r9�getAppKeyBindings�szScript.getAppKeyBindingscCsiS)z�Defines the braille bindings for this script.

        Returns a dictionary where the keys are BrlTTY commands and the
        values are InputEventHandler instances.
        r8)r6r8r8r9r+�szScript.getBrailleBindingscCs
tj|�S)z/Returns the formatting strings for this script.)rZ
Formatting)r6r8r8r9r-�szScript.getFormattingcCs
tj|�S)z7Returns the braille generator for this script.
        )rZBrailleGenerator)r6r8r8r9r.�szScript.getBrailleGeneratorcCs
tj|�S)z,Returns the sound generator for this script.)rZSoundGenerator)r6r8r8r9r/�szScript.getSoundGeneratorcCs
tj|�S)z6Returns the speech generator for this script.
        )rZSpeechGenerator)r6r8r8r9r0�szScript.getSpeechGeneratorcCs
tj|�S)z8Returns the tutorial generator for this script.
        )rZTutorialGenerator)r6r8r8r9r4�szScript.getTutorialGeneratorcCsdS)z2Returns the 'chat' class for this script.
        Nr8)r6r8r8r9r'�szScript.getChatcCsdS)z/Returns the spellcheck support for this script.Nr8)r6r8r8r9r3�szScript.getSpellCheckcCsdS)z5Returns the caret navigation support for this script.Nr8)r6r8r8r9r$�szScript.getCaretNavigationcCs
tj|�S)z.Returns the utilites for this script.
        )rZ	Utilities)r6r8r8r9r �szScript.getUtilitiescCs
tj|�S)z:Returns the label inference functionality for this script.)rZLabelInference)r6r8r8r9r!�szScript.getLabelInferencecCsgS)zaReturns a list of the structural navigation object types
        enabled in this script.
        r8)r6r8r8r9�#getEnabledStructuralNavigationTypes�sz*Script.getEnabledStructuralNavigationTypescCs |j�}tjd�}tj|||�S)z:Returns the 'structural navigation' class for this script.ZstructuralNavigationEnabled)r>�_settingsManagerZ
getSettingrZStructuralNavigation)r6�types�enabler8r8r9r"�s
zScript.getStructuralNavigationcCsdS)z0Returns the live region support for this script.Nr8)r6r8r8r9r&�szScript.getLiveRegionManagercCs|jjS)a5Returns True if we should use structural navigation. Most
        scripts will have no need to override this.  Gecko does however
        because within an HTML document there are times when we do want
        to use it and times when we don't even though it is enabled,
        e.g. in a form field.
        )r#Zenabled)r6r8r8r9�useStructuralNavigationModel�sz#Script.useStructuralNavigationModelcCs.y|jStk
r(tj|�|_|jSXdS)z7Returns the "bookmarks" class for this script.
        N)r�AttributeErrorZ	Bookmarks)r6r8r8r9r%�s
zScript.getBookmarkscCsdS)zxReturn a GtkGrid containing the application unique configuration
        GUI items for the current application.
        Nr8)r6r8r8r9�getAppPreferencesGUI�szScript.getAppPreferencesGUIcCsiS)z7Returns a dictionary with the app-specific preferences.r8)r6r8r8r9�getPreferencesFromGUI�szScript.getPreferencesFromGUIcCstj|�dS)z�Tells the event manager to start listening for all the event types
        of interest to the script.

        Arguments:
        - script: the script.
        N)�
_eventManagerZregisterScriptListeners)r6r8r8r9�registerEventListeners�szScript.registerEventListenerscCstj|�dS)z�Tells the event manager to stop listening for all the event types
        of interest to the script.

        Arguments:
        - script: the script.
        N)rFZderegisterScriptListeners)r6r8r8r9�deregisterEventListenersszScript.deregisterEventListenerscCs�y|jj�}Wn2ttfk
r@d|j}tjtj|d�dSXtj|kpP|j	}|t
jkrr|rrtj
tjkrrd}|szdS|j|�r�dSi|_x,|jj�D]}|jj|�r�|j||�q�WdS)a{Processes all AT-SPI object events of interest to this
        script.  The interest in events is specified via the
        'listeners' field that was defined during the construction of
        this script.

        Note that this script may be passed events it doesn't care
        about, so it needs to react accordingly.

        Arguments:
        - event: the Event
        z$ERROR: Exception getting role for %sTN)�sourceZgetRolerrrrrr	ZactiveScriptr�pyatspiZROLE_PROGRESS_BARrZprogressBarVerbosityZPROGRESS_BAR_ALL�skipObjectEventr1r�keys�type�
startswith)r6�eventZroler7ZprocessEvent�keyr8r8r9�processObjectEvents(




zScript.processObjectEventcCs@|jj|jddg�\}}|s&||kr*dSdg}ddg}ddd	d
g}d}|j|ks\|j|krr|j|jkrrd}d}n�|j|kr�|j|jkr�|j|jkr�|j|jkr�d}d
}n\|jjd�r�|j|jkr�d}d}n:|jjd�o�|j|jko�|j|jko�|j|jk�rd}d}|�r<dt|�jdd�}	d||	f}
t	j
t	j|
d�|S)aGives us, and scripts, the ability to decide an event isn't
        worth taking the time to process under the current circumstances.

        Arguments:
        - event: the Event

        Returns True if we shouldn't bother processing this object event.
        NrFzobject:state-changed:focusedzobject:text-changed:insertzobject:text-changed:deletezobject:text-caret-movedzobject:text-selection-changedzobject:selection-changedz object:active-descendant-changedTz5more recent event of the same type in the same objectz8more recent event of the same type in a different object�systemz+more recent system event in the same objectzobject:state-changedz+appears to be duplicate state-changed eventz
           %s�	� �z*SCRIPT: Skipping object event due to %s
%sz           )r2�getrMrIZdetail1�endswithrN�str�replacerrr)r6rOZcachedEventZ	eventTimeZfocusZtypingZarrowing�skip�reasonZeventDetailsr7r8r8r9rKPs>
zScript.skipObjectEventc
CsJyddlm}|j|j�|_Wn&d|j}tjtj|d�YnXdS)a�Checks the data on the keyboard event.

        Some toolkits don't fill all the key event fields, and/or fills
        them out with unexpected data. This method tries to fill in the
        missing fields and validate/standardize the data we've been given.
        While any script can override this method, it is expected that
        this will only be done at the toolkit script level.

        Arguments:
        - keyboardEvent: an instance of input_event.KeyboardEvent
        r)�Gdkz/ERROR: Exception getting keyval_name for id: %dTN)Z
gi.repositoryr\Zkeyval_name�idrrr)r6�
keyboardEventr\r7r8r8r9�checkKeyboardEventData~s

zScript.checkKeyboardEventDatacCs�d}tj}|j|kr ||j}nd|kr0|d}d}d|_|rv|j|�}|rn|j|jjkrn|j�}|rvd|_n|dk	}|s�|j	j|�}|r�|j|jjkr�|j�}|r�d|_n|dk	}|S)z�Called when a key is pressed on the keyboard.

        Arguments:
        - keyboardEvent: an instance of input_event.KeyboardEvent

        Returns True if the event is of interest.
        NrFT)
rZkeyBindingsMaprr5ZgetInputHandlerZfunctionr#Z	functionsrBr*)r6r^�
user_bindings�user_bindings_map�consumes�handlerr8r8r9�consumesKeyboardEvent�s2	

zScript.consumesKeyboardEventcCs\d}tj}|j|kr ||j}nd|kr0|d}|jd}d}|rJ||k}|sX||jk}|S)z�Called when a key is pressed on the braille display.

        Arguments:
        - brailleEvent: an instance of input_event.KeyboardEvent

        Returns True if the event is of interest.
        Nr�commandF)r�brailleBindingsMaprrOr,)r6�brailleEventr`rarerbr8r8r9�consumesBrailleEvent�s


zScript.consumesBrailleEventcCs�||_d}d}|jd}tj}|j|kr4||j}nd|krD|d}|rd||krd||}|j||�}|r�||jkr�|j|}|j||�}|S)a�Called whenever a key is pressed on the Braille display.

        This method will primarily use the brailleBindings field of
        this script instance see if this script has an interest in the
        event.

        NOTE: there is latent, but unsupported, logic for allowing
        the user's user-settings.py file to extend and/or override
        the brailleBindings for a script.

        Arguments:
        - brailleEvent: an instance of input_event.BrailleEvent
        FNrer)ZscriptrOrrfrZprocessInputEventr,)r6rg�consumedr`rerarcr8r8r9�processBrailleEvent�s 



zScript.processBrailleEventcCsdS)a=Called when the visual object with focus changes.

        The primary purpose of this method is to present locus of focus
        information to the user.

        NOTE: scripts should not call this method directly.  Instead,
        a script should call orca.setLocusOfFocus, which will eventually
        result in this method being called.

        Arguments:
        - event: if not None, the Event that caused the change
        - oldLocusOfFocus: Accessible that is the old locus of focus
        - newLocusOfFocus: Accessible that is the new locus of focus
        Nr8)r6rOZoldLocusOfFocusZnewLocusOfFocusr8r8r9�locusOfFocusChangedszScript.locusOfFocusChangedcCsdS)a�Returns True if the given event is one that should cause this
        script to become the active script.  This is only a hint to
        the focus tracking manager and it is not guaranteed this
        request will be honored.  Note that by the time the focus
        tracking manager calls this method, it thinks the script
        should become active.  This is an opportunity for the script
        to say it shouldn't.
        Tr8)r6rOr8r8r9�isActivatableEvents	zScript.isActivatableEventcCsdS)z%Called when this script is activated.Nr8)r6r8r8r9�activateszScript.activatecCsdS)z'Called when this script is deactivated.Nr8)r6r8r8r9�
deactivate szScript.deactivatecCsiS)Nr8)r6r8r8r9�getTransferableAttributes$sz Script.getTransferableAttributesN))�__name__r�__qualname__�__doc__r:rr(r)r<r=r+r-r.r/r0r4r'r3r$r r!r>r"r&rBr%rDrErGrHrQrKr_rdrhrjrkrlrmrnror8r8r8r9rAsL9		
5.&1r)rrZ__id__�__version__Z__date__Z
__copyright__Z__license__rJ�rrrrrrr	r
rrr
rrrrrZ
getManagerrFZ_scriptManagerr?rr8r8r8r9�<module>"s4