
    g
f@                     \   d Z dZdZdZdZdZddlmZ ddlmZ dd	lm	Z	 dd
lm
Z
 ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z   G d  d!      Z!y")#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.LGPL   )ax_event_synthesizer)action_presenter)braille_generator)debug)event_manager)flat_review_presenter)
formatting)keybindings)label_inference)learn_mode_presenter)mouse_review)notification_presenter)object_navigator)script_utilities)settings_manager)sleep_mode_manager)sound_generator)speech_and_verbosity_manager)speech_generator)structural_navigation)system_information_presenter)table_navigator)	bookmarks)where_am_i_presenter)AXObjectc                   (   e Zd ZdZd Zd Zd Zd Zd1dZd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d Z!d  Z"d! Z#d" Z$d# Z%d$ Z&d% Z'd& Z(d' Z)d2d)Z*d* Z+d+ Z,d, Z-d- Z.d. Z/d/ Z0d0 Z1y()3Scriptz:The specific focus tracking scripts for applications.
    c                    || _         |r)t        j                  | j                         xs d| _        nd| _        | xj                  d| j                  z   dz   z  c_        | j                         | _        d| _        | j                         | _	        | j                         | _        | j                         | _        | j                         | _        | j!                         | _        | j%                         | _        | j)                         | _        | j-                         | _        | j1                         | _        | j5                         | _        | j9                         | _        | j=                         | _        | jA                         | _!        | jE                         | _#        | jI                         | _%        | jM                         | _'        | jQ                         | _)        | jU                         | _+        | jY                         | _-        i | _.        i | _/        | ja                          tc        jd                         | _3        | ji                         | _5        | jm                         | _7        | jq                         | _9        | ju                         | _;        | jy                         | _=        i | _>        i | _?        | j                         | _A        d| _B        d| j                   d}t        j                  t        j                  |d       y)	zCreates 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
        defaultz	 (module=)TFzSCRIPT: z initializedN)Fappr   get_namename
__module__getListeners	listenerspresentIfInactivegetUtilities	utilitiesgetLabelInferencelabelInferencegetStructuralNavigationstructuralNavigationgetCaretNavigationcaretNavigationgetBookmarksr   getLiveRegionManagerliveRegionManagergetNotificationPresenternotificationPresentergetFlatReviewPresenterflatReviewPresentergetSpeechAndVerbosityManagerspeechAndVerbosityManagergetSystemInformationPresentersystemInformationPresentergetObjectNavigatorobjectNavigatorgetTableNavigatortableNavigatorgetWhereAmIPresenterwhereAmIPresentergetLearnModePresenterlearnModePresentergetMouseReviewermouseReviewergetEventSynthesizereventSynthesizergetActionPresenteractionPresentergetSleepModeManagersleepModeManagergetChatchatinputEventHandlerspointOfReferencesetupInputEventHandlersr   KeyBindingskeyBindingsgetBrailleBindingsbrailleBindingsgetFormattingr
   getBrailleGeneratorbrailleGeneratorgetSoundGeneratorsoundGeneratorgetSpeechGeneratorspeechGeneratorgeneratorCache
eventCachegetSpellCheck
spellcheckfindCommandRunr   printMessage
LEVEL_INFO)selfr"   msgs      -/usr/lib/python3/dist-packages/orca/script.py__init__zScript.__init__I   su     ))$((3@yDI!DI		[4??2S88	**, "&**,"446$($@$@$B!#668**,!%!:!:!<%)%B%B%D"#'#>#>#@ )-)J)J)L&*.*L*L*N'#668"446!%!:!:!<"&"<"<">!224 $ 8 8 :#668 $ 8 8 :LLN	"$ "$$&&224#668,,. $ 8 8 :"446#668 ,,.#<05++S$7    c                     | j                    S N)r$   rc   s    re   __str__zScript.__str__   s    ))rg   c                     i S )zSets 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.
         rj   s    re   r&   zScript.getListeners   	     	rg   c                      y)zlDefines InputEventHandler fields for this script that can be
        called by the key and braille bindings.Nrm   rj   s    re   rP   zScript.setupInputEventHandlers   s     	rg   c                 *    t        j                         S )zkDefines the key bindings for this script.

        Returns an instance of keybindings.KeyBindings.
        r   rQ   )rc   enabledOnlys     re   getKeyBindingszScript.getKeyBindings   s    
 &&((rg   c                 *    t        j                         S )z9Returns the toolkit-specific keybindings for this script.rq   rj   s    re   getToolkitKeyBindingszScript.getToolkitKeyBindings        &&((rg   c                 *    t        j                         S )z=Returns the application-specific keybindings for this script.rq   rj   s    re   getAppKeyBindingszScript.getAppKeyBindings   rv   rg   c                     i S )zDefines the braille bindings for this script.

        Returns a dictionary where the keys are BrlTTY commands and the
        values are InputEventHandler instances.
        rm   rj   s    re   rS   zScript.getBrailleBindings   rn   rg   c                 ,    t        j                  |       S )z/Returns the formatting strings for this script.)r
   
Formattingrj   s    re   rU   zScript.getFormatting   s    $$T**rg   c                 ,    t        j                  |       S )z7Returns the braille generator for this script.
        )r   BrailleGeneratorrj   s    re   rV   zScript.getBrailleGenerator   s     !11$77rg   c                 ,    t        j                  |       S )z,Returns the sound generator for this script.)r   SoundGeneratorrj   s    re   rX   zScript.getSoundGenerator       --d33rg   c                 ,    t        j                  |       S )z6Returns the speech generator for this script.
        )r   SpeechGeneratorrj   s    re   rZ   zScript.getSpeechGenerator   s      //55rg   c                      y)z2Returns the 'chat' class for this script.
        Nrm   rj   s    re   rL   zScript.getChat   s     rg   c                      y)z/Returns the spellcheck support for this script.Nrm   rj   s    re   r^   zScript.getSpellCheck       rg   c                      y)z5Returns the caret navigation support for this script.Nrm   rj   s    re   r/   zScript.getCaretNavigation   r   rg   c                 ,    t        j                  |       S )z&Returns the utilities for this script.)r   	Utilitiesrj   s    re   r)   zScript.getUtilities   s    ))$//rg   c                 ,    t        j                  |       S )z:Returns the label inference functionality for this script.)r   LabelInferencerj   s    re   r+   zScript.getLabelInference   r   rg   c                     g S )zaReturns a list of the structural navigation object types
        enabled in this script.
        rm   rj   s    re   #getEnabledStructuralNavigationTypesz*Script.getEnabledStructuralNavigationTypes   s	     	rg   c                     | j                         }t        j                         j                  d      }t	        j
                  | ||      S )z:Returns the 'structural navigation' class for this script.structuralNavigationEnabled)r   r   
getManager
getSettingr   StructuralNavigation)rc   typesenables      re   r-   zScript.getStructuralNavigation   s?    88:!,,.99:WX$99$vNNrg   c                      y)z0Returns the live region support for this script.Nrm   rj   s    re   r2   zScript.getLiveRegionManager   r   rg   c                 *    t        j                         S ri   )r   getPresenterrj   s    re   r4   zScript.getNotificationPresenter   s    %2244rg   c                 *    t        j                         S ri   )r	   r   rj   s    re   r6   zScript.getFlatReviewPresenter   s    $1133rg   c                 *    t        j                         S ri   )r   r   rj   s    re   r:   z$Script.getSystemInformationPresenter   s    +88::rg   c                 *    t        j                         S ri   )r   getNavigatorrj   s    re   r<   zScript.getObjectNavigator       ,,..rg   c                 *    t        j                         S ri   )r   r   rj   s    re   r>   zScript.getTableNavigator   s    ++--rg   c                 *    t        j                         S ri   )r   r   rj   s    re   r8   z#Script.getSpeechAndVerbosityManager   s    +6688rg   c                 *    t        j                         S ri   )r   r   rj   s    re   r@   zScript.getWhereAmIPresenter       #0022rg   c                 *    t        j                         S ri   )r   r   rj   s    re   rB   zScript.getLearnModePresenter   r   rg   c                 *    t        j                         S ri   )r   r   rj   s    re   rH   zScript.getActionPresenter   r   rg   c                 *    t        j                         S ri   )r   r   rj   s    re   rJ   zScript.getSleepModeManager  s    !,,..rg   c                 *    t        j                         S ri   )r   getReviewerrj   s    re   rD   zScript.getMouseReviewer  s    ''))rg   c                 *    t        j                         S ri   )r   getSynthesizerrj   s    re   rF   zScript.getEventSynthesizer  s    #2244rg   c                     	 | j                   S # t        $ r) t        j                  |       | _         | j                   cY S w xY w)z7Returns the "bookmarks" class for this script.
        )r   AttributeError	Bookmarksrj   s    re   r1   zScript.getBookmarks  s<    	">>! 	"&006DN>>!	"s    /A A c                      y)zxReturn a GtkGrid containing the application unique configuration
        GUI items for the current application.
        Nrm   rj   s    re   getAppPreferencesGUIzScript.getAppPreferencesGUI  s     rg   c                     i S )z7Returns a dictionary with the app-specific preferences.rm   rj   s    re   getPreferencesFromGUIzScript.getPreferencesFromGUI  s	     	rg   c                 J    t        j                         j                  |        y)zTells the event manager to start listening for all the event types
        of interest to the script.

        Arguments:
        - script: the script.
        N)r   r   registerScriptListenersrj   s    re   registerEventListenerszScript.registerEventListeners  s     	  "::4@rg   c                 J    t        j                         j                  |        y)zTells the event manager to stop listening for all the event types
        of interest to the script.

        Arguments:
        - script: the script.
        N)r   r   deregisterScriptListenersrj   s    re   deregisterEventListenerszScript.deregisterEventListeners)  s     	  "<<TBrg   c                     | j                  |      ryi | _        | j                  j                         D ]3  }|j                  j                  |      s | j                  |   |       5 y)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
        N)skipObjectEventr\   r'   keystype
startswith)rc   eventkeys      re   processObjectEventzScript.processObjectEvent3  sb     & ! >>&&( 	+Czz$$S)#s#E*	+rg   Nc                    | j                   j                  |d dg      \  }}|s*d|g}t        j                  t        j                  |d       y |E||j
                  k7  r6d|j
                  d|g}t        j                  t        j                  |d       y |E||j                  k7  r6d|j                  d|g}t        j                  t        j                  |d       y |E||j                  k7  r6d|j                  d|g}t        j                  t        j                  |d       y d|g}t        j                  t        j                  |d       |S )	N    zSCRIPT: No queued event of typeTz SCRIPT: Queued event's detail1 (z) doesn't matchz SCRIPT: Queued event's detail2 (z!SCRIPT: Queued event's any_data (z$SCRIPT: Found matching queued event:)r]   getr   printTokensrb   detail1detail2any_data)rc   	eventTyper   r   r   cachedEvent	eventTimetokenss           re   _getQueuedEventzScript._getQueuedEventU  sB   !%!4!4Yq	!JY7CFe..=7k.A.A#A8+:M:M'2Fe..=7k.A.A#A8+:M:M'2Fe..=H0D0D$D9!**,=xIFe..=8+F%**FD9rg   c                 V   | j                   j                  |j                  ddg      \  }}|r||k(  rydg}ddg}g d}d}|j                  |v s|j                  |v r|j                  |j                  k(  rd}d	}n|j                  |v rP|j                  |j                  k7  r7|j                  |j                  k(  r|j                  |j                  k(  rd}d
}n|j                  j                  d      r|j                  |j                  k(  rd}d}nj|j                  j                  d      rO|j                  |j                  k(  r6|j                  |j                  k(  r|j                  |j                  k(  rd}d}|r*d|g}	t        j                  t        j                  |	d       |S )a  Gives 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.
        Nr   Fzobject:state-changed:focusedzobject:text-changed:insertzobject:text-changed:delete)zobject:text-caret-movedzobject:text-selection-changedzobject: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 objectzobject:state-changedz+appears to be duplicate state-changed eventzSCRIPT: Skipping object event:)
r]   r   r   sourcer   endswithr   r   r   rb   )
rc   r   r   r   focustypingarrowingskipreasonr   s
             re   r   zScript.skipObjectEventr  s    "&!4!4UZZ$!KYkU22302NOT JJ("ejjF&:||{111DLFZZ5 U\\[5G5G%G{///+"5"55DOFZZ  *u||{?Q?Q/QDBFZZ""#9:{///!3!33+"5"55DBF6LFe..=rg   c                      y)a  Updates state and presents changes to the user in response to a
        notification from the FocusManager. Do not call this method outside
        of the FocusManager.

        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
        Nrm   )rc   r   oldLocusOfFocusnewLocusOfFocuss       re   locusOfFocusChangedzScript.locusOfFocusChanged  s     	rg   c                      y)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.
        Trm   rc   r   s     re   isActivatableEventzScript.isActivatableEvent  s     rg   c                      y)z8Allows scripts to insist that they should become active.Frm   r   s     re   forceScriptActivationzScript.forceScriptActivation  s     rg   c                      y)z%Called when this script is activated.Nrm   rj   s    re   activatezScript.activate      rg   c                      y)z'Called when this script is deactivated.Nrm   rj   s    re   
deactivatezScript.deactivate  r   rg   c                     i S ri   rm   rj   s    re   getTransferableAttributesz Script.getTransferableAttributes  s    	rg   )T)NNN)2__name__r%   __qualname____doc__rf   rk   r&   rP   rs   ru   rx   rS   rU   rV   rX   rZ   rL   r^   r/   r)   r+   r   r-   r2   r4   r6   r:   r<   r>   r8   r@   rB   rH   rJ   rD   rF   r1   r   r   r   r   r   r   r   r   r   r   r   r   r   rm   rg   re   r   r   E   s    <8|
))
)
+8
46

04O54;/.933//*5"
AC +D:+Z
	
rg   r   N)"r   __id____version____date____copyright____license__ r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	ax_objectr   r   rm   rg   re   <module>r      s}   (D  ? "     #    "  $       *  # *   "  rg   