Mini Shell

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

3

�2[�w�@sbdZdZdZdZdZdZddlZdd	lmZdd
lm	Z	ddlm
Z
ddlmZGd
d�d�Z
dS)a%Utilities for obtaining tutorial utterances for objects.  In general,
there probably should be a singleton instance of the TutorialGenerator
class.  For those wishing to override the generators, however,
one can create a new instance and replace/extend the tutorial generators
as they see fit.z$Id$z
$Revision$z$Date$z-Copyright (c) 2008-2009 Sun Microsystems Inc.ZLGPL�N�)�debug)�
orca_state)�settings)�_c@s�eZdZdZdd�Zdd�Zd2dd�Zd	d
�Zdd�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.�Zd3d0d1�ZdS)4�TutorialGeneratoraTakes accessible objects and produces a tutorial string to speak
    for those objects.  See the getTutorialString method, which is the
    primary entry point.  Subclasses can feel free to override/extend
    the getTutorialGenerators instance field as they see fit.cCsP||_d|_d|_i|_|j|jtj<|j|jtj<|j	|jtj
<|j|jtj<|j
|jtj<|j|jtj<|j|jtj<|j|jtj<|j|jtj<|j|jtj<|j|jtj<|j|jtj<|j|jtj<|j|jtj<|j|jtj<|j|jtj <|j!|jtj"<|j#|jtj$<|j|jtj%<|j&|jtj'<|j|jtj(<|j)|jtj*<dS)N�)+�_script�lastTutorial�lastRole�tutorialGenerators�_getTutorialForCheckBox�pyatspiZROLE_CHECK_BOX�_getTutorialForComboBoxZROLE_COMBO_BOX�_getTutorialForFrameZ
ROLE_FRAME�_getTutorialForIconZ	ROLE_ICON�_getTutorialForLayeredPane�ROLE_LAYERED_PANE�_getTutorialForListZ	ROLE_LIST�_getTutorialForListItemZROLE_LIST_ITEM�_getTutorialForPageTabZ
ROLE_PAGE_TAB�_getTutorialForTextZROLE_PARAGRAPHZROLE_PASSWORD_TEXTZ
ROLE_ENTRY�_getTutorialForPushButtonZROLE_PUSH_BUTTON�_getTutorialForSpinButtonZROLE_SPIN_BUTTON�_getTutorialForTableCellRowZROLE_TABLE_CELLZ	ROLE_TEXTZROLE_TOGGLE_BUTTON�_getTutorialForRadioButtonZROLE_RADIO_BUTTON�_getTutorialForMenuZ	ROLE_MENUZROLE_CHECK_MENU_ITEM�_getTutorialForMenuItemZROLE_MENU_ITEMZROLE_RADIO_MENU_ITEM�_getTutorialForSliderZROLE_SLIDER)�selfZscript�r �'/usr/lib/python3.6/tutorialgenerator.py�__init__-s4zTutorialGenerator.__init__cCs�tjtjd|�tjtjd|j�tjtjd|j��tjtjd|�tjtjd�x|D]}tjtjd|�qbWdS)a/Prints debug.LEVEL_FINER information regarding
        the tutorial generator.

        Arguments:
        - generatorName: the name of the generator
        - obj: the object being presented
        - alreadyFocused: False if object just received focus
        - utterances: the generated text
        z
GENERATOR: %sz           obj             = %sz           role            = %sz           alreadyFocused  = %sz           utterances:z               (%s)N)rZprintlnZLEVEL_FINER�nameZgetRoleName)rZ
generatorName�obj�alreadyFocused�
utterances�textr r r!�_debugGeneratoris


z!TutorialGenerator._debugGeneratorNcCsgS)a�The default tutorial generator returns the empty tutorial string
        because We have no associated tutorial function for the object.

        Arguments:
        - obj: an Accessible
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string
        - role: A role that should be used instead of the Accessible's
          possible role.

        Returns the empty list []
        r )rr$r%�
forceTutorial�roler r r!�_getDefaultTutorial�sz%TutorialGenerator._getDefaultTutorialcCs@g}td�}|r|j|gks"|r,|j|�|jd|||�|S)a>Get the  tutorial string for a check box.

        Arguments:
        - obj: the check box
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of tutorial utterances to be spoken for the object.
        zPress space to toggle.r
)rr
�appendr()rr$r%r)r&�msgr r r!r
�s
z)TutorialGenerator._getTutorialForCheckBoxcCs@g}td�}|r|j|gks"|r,|j|�|jd|||�|S)a=Get the  tutorial string for a combobox.

        Arguments:
        - obj: the combo box
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of tutorial utterances to be spoken for the object.
        z=Press space to expand, and use up and down to select an item.r)rr
r,r()rr$r%r)r&r-r r r!r�s
z)TutorialGenerator._getTutorialForComboBoxcCsvg}|jjj|�}|r$|jr$|j}td�}y|jjj|�}Wnd}YnX|dkrb|j|�|jd|||�|S)a6Get the  tutorial string for a frame.

        Arguments:
        - obj: the frame
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of tutorial utterances to be spoken for the object.
        z,Press alt+f6 to give focus to child windows.rr)r	�	utilities�
displayedText�descriptionrZunfocusedAlertAndDialogCountr,r()rr$r%r)r&r#ZchildWindowsMsgZalertAndDialogCountr r r!r�s 

z&TutorialGenerator._getTutorialForFramecCsD|jj�tjkr"|j|j||�}n|j|||�}|jd|||�|S)a5Get the  tutorial string for an icon.

        Arguments:
        - obj: the icon
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of tutorial utterances to be spoken for the object.
        r)�parent�getRolerrrr+r()rr$r%r)r&r r r!r�sz%TutorialGenerator._getTutorialForIconc

Cs�g}|jjj|�}|r$|jr$|j}td�}|j|�td�}|jj}y|jjd�}	Wnt	k
rnd}	YnXd|kr�||	kr�|j|�|r�|j
|ks�|r�ng}|jd|||�|S)aDGet the  tutorial string for a layered pane.

        Arguments:
        - obj: the layered pane
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of tutorial utterances to be spoken for the object.
        zDTo move to items, use either the arrow keys or type ahead searching.z0To get to the system menus press the alt+f1 key.rNZnautilusr)r	r.r/r0rr,r#r1ZgetChildAtIndex�AttributeErrorr
r()
rr$r%r)r&r#r-Z
desktopMsgZ
scriptNameZsiblingr r r!r	s.


z,TutorialGenerator._getTutorialForLayeredPanecCs@g}td�}|r|j|gks"|r,|j|�|jd|||�|S)a4Get the  tutorial string for a list.

        Arguments:
        - obj: the list
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of tutorial utterances to be spoken for the object.
        z"Use up and down to select an item.r)rr
r,r()rr$r%r)r&r-r r r!r8s
z%TutorialGenerator._getTutorialForListcCs~g}td�}td�}|j�}|jtj�rj|jtj�rP|j|gksD|rj|j|�n|j|gks`|rj|j|�|jd|||�|S)a<Get the  tutorial string for a listItem.

        Arguments:
        - obj: the listitem
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of tutorial utterances to be spoken for the object.
        z#To collapse, press shift plus left.z"To expand, press shift plus right.r)	r�getState�containsr�STATE_EXPANDABLE�STATE_EXPANDEDr
r,r()rr$r%r)r&�expandedMsg�collapsedMsg�stater r r!rSs
z)TutorialGenerator._getTutorialForListItemcCs@g}td�}|r|j|gks"|r,|j|�|jd|||�|S)a3Get the tutorial string for a menu item

        Arguments:
        - obj: the menu item
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of utterances to be spoken for the object.
        zTo activate press return.r)rr
r,r()rr$r%r)r&r-r r r!r}s
z)TutorialGenerator._getTutorialForMenuItemcCsX|j�jtj�sgSg}td�}|s*|rD|jjj|�rD|j|�|j	d|||�|S)aDGet the tutorial string for a text object.

        Arguments:
        - obj: the text component
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of tutorial utterances to be spoken for the object.
        z
Type in text.r)
r4r5rZSTATE_EDITABLErr	r.ZisReadOnlyTextArear,r()rr$r%r)r&r-r r r!r�s

z%TutorialGenerator._getTutorialForTextcCs:g}td�}|j|gks|r&|j|�|jd|||�|S)a;Get the tutorial string for a page tab.

        Arguments:
        - obj: the page tab
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of tutorial utterances to be spoken for the object.
        z&Use left and right to view other tabs.Z_getTutorialForPageTabList)rr
r,r()rr$r%r)r&r-r r r!r�s
z(TutorialGenerator._getTutorialForPageTabcCs@g}td�}|r|j|gks"|r,|j|�|jd|||�|S)a7Get the tutorial string for a push button

        Arguments:
        - obj: the push button
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of utterances to be spoken for the object.
        zTo activate press space.r)rr
r,r()rr$r%r)r&r-r r r!r�s
z+TutorialGenerator._getTutorialForPushButtoncCs@g}td�}|r|j|gks"|r,|j|�|jd|||�|S)a}Get the tutorial string for a spin button.  If the object already has
        focus, then no tutorial is given.

        Arguments:
        - obj: the spin button
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of utterances to be spoken for the object.
        zMUse up or down arrow to select value. Or type in the desired numerical value.r)rr
r,r()rr$r%r)r&r-r r r!r�s
z+TutorialGenerator._getTutorialForSpinButtoncCs^g}td�}td�}|jdkr�g}ddg}x,t|�D] \}	}
|jjj|
�r4d||	<Pq4W|drt|drtddg}n|dr�|dr�ddg}|r�x4|D],}	|r�||	r�q�|j|j||	||��q�W|S|jjj|�r�|j|||�}|j	�}|j
tj��rJ|j
tj
��r,|j|gk�s |�rJ|j|�n|j|gk�s@|�rJ|j|�|jd|||�|S)	a;Get the tutorial utterances for a single table cell

        Arguments:
        - obj: the table
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of utterances to be spoken for the object.
        z#To collapse, press shift plus left.z"To expand, press shift plus right.�FTrr�_getTutorialForTableCell)rZ
childCount�	enumerater	r.ZhasMeaningfulToggleAction�extendr<r
r4r5rr6r7r
r,r()rr$r%r)r&r8r9Z	cellOrderZ	hasToggle�iZchildr:r r r!r<sJ	





z*TutorialGenerator._getTutorialForTableCellc
Csg}|s�y|jj�}Wnd}YnX|jjj|�}|r�|r�|jjj|j�r�|j}|jjj|�}|j|�}	|j|�}
d}d|jj	kr�d|jj	kr�|jj	}|d|	kp�|	dks�|	|j
dko�|d|
k}|j|j|||��n|j|||�}n|j|||�}|j
d|||�|S)aKGet the tutorial string for the active table cell in the table row.

        Arguments:
        - obj: the table
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of utterances to be spoken for the object.
        NTZlastRowZ
lastColumnrrr)r1Z
queryTabler	r.ZshouldReadFullRowZisLayoutOnlyZ	cellIndexZ
getRowAtIndexZgetColumnAtIndex�pointOfReferenceZnRowsr>r<r()
rr$r%r)r&Zparent_tableZreadFullRowr1�index�row�columnZspeakAllr@r r r!rXs>




z-TutorialGenerator._getTutorialForTableCellRowcCs@g}td�}|r|j|gks"|r,|j|�|jd|||�|S)a:Get the tutorial string for a radio button.

        Arguments:
        - obj: the radio button
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of utterances to be spoken for the object.
        zUse arrow keys to change.r)rr
r,r()rr$r%r)r&r-r r r!r�s
z,TutorialGenerator._getTutorialForRadioButtoncCsxg}td�}td�}|jjdkrJ|jj|jkrJ|j|gks>|rd|j|�n|j|gksZ|rd|j|�|jd|||�|S)a*Get the tutorial string for a menu.

        Arguments:
        - obj: the menu
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of utterances to be spoken for the object.
        zUTo navigate, press left or right arrow. To move through items press up or down arrow.z%To enter sub menu, press right arrow.rr)rr1r#�	__class__r
r,r()rr$r%r)r&ZmainMenuMsgZ
subMenuMsgr r r!r�s
z%TutorialGenerator._getTutorialForMenucCs@g}td�}|r|j|gks"|r,|j|�|jd|||�|S)asGet the tutorial string for a slider.  If the object already has
        focus, then no tutorial is given.

        Arguments:
        - obj: the slider
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string

        Returns a list of utterances to be spoken for the object.
        ztTo decrease press left arrow, to increase press right arrow. To go to minimum press home, and for maximum press end.r)rr
r,r()rr$r%r)r&r-r r r!r�s
z'TutorialGenerator._getTutorialForSlidercCs<|jjj|�}|sdS|jjj|�}|s,dS|d}|j�S)Nr)r	ZinputEventHandlers�getZkeyBindingsZgetBindingsForHandlerZasString)rZhandlerNameZhandlerZbindingsZbindingr r r!�_getBindingsForHandler�sz(TutorialGenerator._getBindingsForHandlercCsgS)Nr )rr$r%r)r r r!�_getModeTutorial�sz"TutorialGenerator._getModeTutorialFcCs�tjs
gS|o|tjksgSg}|p*|j�}|j|||�}|sf||jkrT|j|}n|j}||||�}||jkr�||j	kr�|r�g}|r�dj
|�g}||_||_	|r�d|_d|_	|jd|||�|S)a3Get the tutorial for an Accessible object.  This will look
        first to the specific tutorial generators and if this
        does not exist then return the empty tutorial.
        This method is the primary method
        that external callers of this class should use.

        Arguments:
        - obj: the object
        - alreadyFocused: False if object just received focus
        - forceTutorial: used for when whereAmI really needs the tutorial string
        - role: Alternative role to use

        Returns a list of utterances to be spoken.
        � rN�getTutorial)rZenableTutorialMessagesrZlocusOfFocusr2rGrr+r
r�joinr()rr$r%r)r*r&r-�	generatorr r r!rI�s6
zTutorialGenerator.getTutorial)N)FN)�__name__�
__module__�__qualname__�__doc__r"r(r+r
rrrrrrrrrrrr<rrrrrFrGrIr r r r!r's0<
%/*Q7#r)rOZ__id__�__version__Z__date__Z
__copyright__Z__license__rrrrrZ	orca_i18nrrr r r r!�<module>s