Mini Shell

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

3

�p5[��@s:dZdZdZdZdZdZddlZddlZddl	Zddl
ZddlZdd	lmZdd
lm
Z
ddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZGdd�d�Ze�gZGdd�d�Ze�gZdZdZdZdZdZdZdZeej eej!eej"eej#eej#eej#iZ$ej%�Z&Gdd�dej'�Z(dS)z6Utilities for obtaining speech utterances for objects.z$Id:$z$Revision:$z$Date:$z-Copyright (c) 2005-2009 Sun Microsystems Inc.ZLGPL�N�)�chnames)�debug)�	generator)�messages)�object_properties)�settings)�settings_manager)�text_attribute_names)�acssc@seZdZdZdd�ZdS)�PausezJA dummy class to indicate we want to insert a pause into an
    utterance.cCsdS)N�)�selfr
r
�&/usr/lib/python3.6/speech_generator.py�__init__,szPause.__init__N)�__name__�
__module__�__qualname__�__doc__rr
r
r
rr)src@seZdZdZdd�ZdS)�	LineBreakzYA dummy class to indicate we want to break an utterance into
    separate calls to speak.cCsdS)Nr
)rr
r
rr4szLineBreak.__init__N)rrrrrr
r
r
rr1srZ	_generate�defaultZ	uppercaseZ	hyperlink�system�state�valuecs�eZdZdZdd�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+�Z�fd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Z�fd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&�fdHdI�Z'�fdJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+dRdS�Z,dTdU�Z-dVdW�Z.dXdY�Z/dZd[�Z0d\d]�Z1d^d_�Z2d`dadbgfdcdd�Z3dedf�Z4dgdh�Z5didj�Z6dkdl�Z7dmdn�Z8�fdodp�Z9dqdr�Z:dsdt�Z;dudv�Z<dwdx�Z=dydz�Z>d{d|�Z?d}d~�Z@dd��ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZP�fd�d��ZQ�fd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d��ZXd�d��ZYd�d��ZZd�d��Z[d�d��Z\d�d��Z]d�d��Z^d�d��Z_d�d��Z`d�d��Zad�d„Zbd�dĄZcd�dƄZdd�dȄZed�dʄZfd�d̄Zgd�d΄Zhd�dЄZid�d҄Zjd�dԄZkd�dքZld�d؄Zmd�dڄZnd�d܄Zod�dބZpd�d�Zqd�d�Zrd�d�Zsd�d�Ztd�d�Zud�d�Zvd�d�Zwd�d�d�Zx�ZyS)��SpeechGeneratorz�Takes accessible objects and produces a string to speak for
    those objects.  See the generateSpeech method, which is the primary
    entry point.  Subclasses can feel free to override/extend the
    speechGenerators instance field as they see fit.cCstjj||d�dS)N�speech)r�	Generatorr)r�scriptr
r
rr\szSpeechGenerator.__init__cCsR|j�tjkr|jt�}n4t|t�rD|j�rD|j�j	�rD|jt
�}n
|jt�}|S)N)�getRole�pyatspi�	ROLE_LINK�voice�	HYPERLINK�
isinstance�str�isupper�strip�isalpha�	UPPERCASE�DEFAULT)r�obj�stringrr
r
r�_getACSS_s

zSpeechGenerator._getACSScCstjj||�|j|d<dS)zCOther things to make available from the formatting string.
        r!N)rr�_addGlobalsr!)rZglobalsDictr
r
rr-kszSpeechGenerator._addGlobalscKs|j|f|�S)N)�generate)rr*�argsr
r
r�generateSpeechqszSpeechGenerator.generateSpeechcKs�y|jd|j��}Wn.ttfk
rBtjtjd|�d}YnX|tjkrht	j
d�r\gS|jt�}n
|jt
�}tjj||f|�}|r�|j|�|S)a Returns an array of strings for use by speech and braille that
        represent the name of the object.  If the object is directly
        displaying any text, that text will be treated as the name.
        Otherwise, the accessible name of the object will be used.  If
        there is no accessible name, then the description of the
        object will be used.  This method will return an empty array
        if nothing can be found.  [[[WDW - I wonder if we should just
        have _generateName, _generateDescription,
        _generateDisplayedText, etc., that don't do any fallback.
        Then, we can allow the formatting to do the fallback (e.g.,
        'displayedText or name or description'). [[[JD to WDW - I
        needed a _generateDescription for whereAmI. :-) See below.
        �rolezError getting role for: %sN�onlySpeakDisplayedText)�getr�LookupError�RuntimeErrorr�printlnZ
LEVEL_FINEr�ROLE_LAYERED_PANE�_settingsManager�
getSettingr!�SYSTEMr)rr�
_generateName�extend)rr*r/r1r�resultr
r
rr;zs




zSpeechGenerator._generateNamecKs.|jt�}tjj||f|�}|r*|j|�|S)aReturns the label for an object as an array of strings for use by
        speech and braille.  The label is determined by the displayedLabel
        method of the script utility, and an empty array will be returned if
        no label can be found.
        )r!r)rr�_generateLabelr<)rr*r/rr=r
r
rr>�s


zSpeechGenerator._generateLabelc	Ks�g}|jt�}|j|j|f|��|sjy
|j}Wn d|}tjtj|�|S|rj|j|�|j|�|r�|j	j
�tjkr�|j
|j	f|�}|S)z�Returns the label as an array of strings for speech and braille.
        If the label cannot be found, the name will be used instead.
        If the name cannot be found, an empty array will be returned.
        z ERROR: Could not get name for %s)r!r)r<r>�namerr6�
LEVEL_INFO�append�parentrrZROLE_AUTOCOMPLETE�_generateLabelOrName)rr*r/r=rr?�msgr
r
rrC�s 



z$SpeechGenerator._generateLabelOrNamecKs.|jt�}tjj||f|�}|r*|j|�|S)a�Returns an array of strings for use by speech and braille that
        represent the 'placeholder' text. This is typically text that
        serves as a functional label and is found in a text widget until
        that widget is given focus at which point the text is removed,
        the assumption being that the user was able to see the text prior
        to giving the widget focus.
        )r!r)rr�_generatePlaceholderTextr<)rr*r/rr=r
r
rrE�s


z(SpeechGenerator._generatePlaceholderTextcKsjtjd�rgStjd�sgS|jd�}|r<|j�tjkr<gS|jt�}tj	j
||f|�}|rf|j|�|S)z�Returns an array of strings fo use by speech and braille that
        represent the description of the object, if that description
        is different from that of the name and label.
        r2�speakDescription�priorObj)r8r9r3rr�
ROLE_TOOL_TIPr!r:rr�_generateDescriptionr<)rr*r/rGrr=r
r
rrI�s




z$SpeechGenerator._generateDescriptioncKsJtjd�rgStjd�sgS|jt�}tjj||f|�}|rF|j|�|S)z|Returns an array of strings for use by speech and braille that
        represent the description of the image on the object.r2rF)r8r9r!r:rr�_generateImageDescriptionr<)rr*r/rr=r
r
rrJ�s



z)SpeechGenerator._generateImageDescriptioncKs.|jt�}tjj||f|�}|r*|j|�|S)z�Returns an array of strings for use by speech and braille that
        represent the read only state of this object, but only if it
        is read only (i.e., it is a text area that cannot be edited).
        )r!r:rr�_generateReadOnlyr<)rr*r/rr=r
r
rrK�s


z!SpeechGenerator._generateReadOnlycKsLtjd�stjd�tjkrgS|jt�}tjj||f|�}|rH|j	|�|S)Nr2�speechVerbosityLevel)
r8r9r�VERBOSITY_LEVEL_BRIEFr!r:rr�_generateClickabler<)rr*r/rr=r
r
rrN�s


z"SpeechGenerator._generateClickablecKs<tjd�rgS|jt�}tjj||f|�}|r8|j|�|S)Nr2)r8r9r!r:rr�_generateHasLongDescr<)rr*r/rr=r
r
rrOs


z$SpeechGenerator._generateHasLongDesccKs<tjd�rgS|jt�}tjj||f|�}|r8|j|�|S)Nr2)r8r9r!r:rr�_generateAvailabilityr<)rr*r/rr=r
r
rrPs


z%SpeechGenerator._generateAvailabilitycKs<tjd�rgS|jt�}tjj||f|�}|r8|j|�|S)Nr2)r8r9r!r:rr�_generateInvalidr<)rr*r/rr=r
r
rrQs


z SpeechGenerator._generateInvalidcKs<tjd�rgS|jt�}tjj||f|�}|r8|j|�|S)Nr2)r8r9r!r:rr�_generateRequiredr<)rr*r/rr=r
r
rrR&s


z!SpeechGenerator._generateRequiredcKs�tjd�rgS|jd�rgS|jjj|�rT|jd|j��}|j�\}}||krhgSntjd�tj	krhgS|j
t�}tj
j||f|�}|r�|j|�|S)Nr2�leavingr1rL)r8r9r3�_script�	utilities�isTextDocumentTabler�"_getEnabledAndDisabledContextRolesrrMr!r:rr�_generateTabler<)rr*r/r1�enabled�disabledrr=r
r
rrX0s"



zSpeechGenerator._generateTablecKsDtjd�rgSg}|jd|j��}|tjkr@|j|j|f|��|S)awA convenience method to prevent the pyatspi.ROLE_PARAGRAPH role
        from being spoken. In the case of a pyatspi.ROLE_PARAGRAPH
        role, an empty array will be returned. In all other cases, the
        role name will be returned as an array of strings (and
        possibly voice and audio specifications).  Note that a 'role'
        attribute in args will override the accessible role of the
        obj. [[[WDW - I wonder if this should be moved to
        _generateRoleName.  Or, maybe make a 'do not speak roles' attribute
        of a speech generator that we can update and the user can
        override.]]]
        r2r1)r8r9r3rrZROLE_PARAGRAPHr<�_generateRoleName)rr*r/r=r1r
r
r�_generateTextRoleFs

z!SpeechGenerator._generateTextRolec	KsFtjd�rgS|jjj|�r gSg}|jt�}|jd|j��}t	j
t	jt	jg}y|j
j�}Wnd}YnX|t	jkr�|t	jkr�|j|j
�S|t	jkr�|j|j��tjd�tjkr�|jt	jt	jg�|t	jk�r|jjj|�}|�r|jtj|j|f|�|d��|j|�||k�rB|�rB|j|j|f|��|j|�|S)a7Returns the role name for the object in an array of strings (and
        possibly voice and audio specifications), with the exception
        that the pyatspi.ROLE_UNKNOWN role will yield an empty array.
        Note that a 'role' attribute in args will override the
        accessible role of the obj.
        r2r1NrL)r1�level)r8r9rTrU�isStatusBarNotificationr!r:r3rrZROLE_UNKNOWNZROLE_FILLERZ
ROLE_EXTENDEDrB�	ROLE_MENU�ROLE_COMBO_BOXr[�
ROLE_LIST_BOXrArrMr<�	ROLE_ICONZROLE_CANVASZROLE_HEADINGZheadingLevelrZROLE_HEADING_LEVEL_SPEECH�getLocalizedRoleName)	rr*r/r=rr1ZdoNotPresent�
parentRoler]r
r
rr[[s@





z!SpeechGenerator._generateRoleNamecKs|j|f|�}|r|dSdS)ayReturns the role name for the object in an array of strings (and
        possibly voice and audio specifications), with the exception
        that the pyatspi.ROLE_UNKNOWN role will yield an empty array.
        Note that a 'role' attribute in args will override the
        accessible role of the obj.  This is provided mostly as a
        method for scripts to call.
        r�)r[)rr*r/�	generatedr
r
r�getRoleName�szSpeechGenerator.getRoleNamecKs|j|f|�}|r|dSdS)Nrre)r;)rr*r/rfr
r
r�getName�szSpeechGenerator.getNamecsf|jjj|�s|jjj|�r"tjS|jd|j��}|j�}|t	j
krV|jt	j�rVtj
St�j|f|�S)z�Returns the localized name of the given Accessible object; the name
        is suitable to be spoken.

        Arguments:
        - obj: an Accessible object
        r1)rTrU�isEditableComboBoxZisEditableDescendantOfComboBoxrZROLE_EDITABLE_COMBO_BOXr3r�getStaterr �contains�
STATE_VISITEDZROLE_VISITED_LINK�superrc)rr*r/r1r)�	__class__r
rrc�sz$SpeechGenerator.getLocalizedRoleNamec	Ksfg}|jt�}|jjj|�}|jjj||�}x$|D]}|j|f|�}|j|�q4W|rb|j|�|S)z�Returns, as an array of strings (and possibly voice
        specifications), all the labels which are underneath the obj's
        hierarchy and which are not in a label for or labelled by
        relation.
        )r!r)rTrUr^ZunrelatedLabelsr;r<)	rr*r/r=rZvisibleOnlyZlabelsZlabelr?r
r
r�_generateUnrelatedLabels�s


z(SpeechGenerator._generateUnrelatedLabelscKs<tjd�rgS|jt�}tjj||f|�}|r8|j|�|S)aReturns an array of strings for use by speech and braille that
        represent the checked state of the object.  This is typically
        for check boxes. [[[WDW - should we return an empty array if
        we can guarantee we know this thing is not checkable?]]]
        r2)r8r9r!�STATErr�_generateCheckedStater<)rr*r/rr=r
r
rrq�s


z%SpeechGenerator._generateCheckedStatecKs<tjd�rgS|jt�}tjj||f|�}|r8|j|�|S)z�Returns an array of strings for use by speech and braille that
        represent the expanded/collapsed state of an object, such as a
        tree node. If the object is not expandable, an empty array
        will be returned.
        r2)r8r9r!rprr�_generateExpandableStater<)rr*r/rr=r
r
rrr�s


z(SpeechGenerator._generateExpandableStatecKs<tjd�rgS|jt�}tjj||f|�}|r8|j|�|S)z�Returns an array of strings for use by speech and braille that
        represent the checked state of the menu item, only if it is
        checked. Otherwise, and empty array will be returned.
        r2)r8r9r!rprr�_generateMenuItemCheckedStater<)rr*r/rr=r
r
rrs�s


z-SpeechGenerator._generateMenuItemCheckedStatecs:tjd�rgS|jt�}t�j|f|�}|r6|j|�|S)aReturns an array of strings (and possibly voice and audio
        specifications) that represent the multiselectable state of
        the object.  This is typically for list boxes. If the object
        is not multiselectable, an empty array will be returned.
        r2)r8r9r!rprm�_generateMultiselectableStater<)rr*r/rr=)rnr
rrt�s


z-SpeechGenerator._generateMultiselectableStatecKs<tjd�rgS|jt�}tjj||f|�}|r8|j|�|S)aReturns an array of strings for use by speech and braille that
        represent the checked state of the object.  This is typically
        for check boxes. [[[WDW - should we return an empty array if
        we can guarantee we know this thing is not checkable?]]]
        r2)r8r9r!rprr�_generateRadioStater<)rr*r/rr=r
r
rrus


z#SpeechGenerator._generateRadioStatecKs<tjd�rgS|jt�}tjj||f|�}|r8|j|�|S)z?Returns an array of strings indicating the on/off state of obj.r2)r8r9r!rprr�_generateSwitchStater<)rr*r/rr=r
r
rrvs


z$SpeechGenerator._generateSwitchStatecKs<tjd�rgS|jt�}tjj||f|�}|r8|j|�|S)aReturns an array of strings for use by speech and braille that
        represent the checked state of the object.  This is typically
        for check boxes. [[[WDW - should we return an empty array if
        we can guarantee we know this thing is not checkable?]]]
        r2)r8r9r!rprr�_generateToggleStater<)rr*r/rr=r
r
rrw"s


z$SpeechGenerator._generateToggleStatecKsb|j|f|�}|j|j|f|��|j|j|f|��|j|j|f|��|j|j|f|��|S)N)�_generateLinkInfor<�_generatePauserA�_generateSiteDescription�_generateFileSize)rr*r/r=r
r
r�generateLinkInfo7sz SpeechGenerator.generateLinkInfoc
Ksxg}|jt�}|jjj|�}|sX|j|j|��|j|j|��|j|jjj	|���nt
jj|�}|ddkr�|dj
d�}|jtj|d|dd��n�tj|d}|jjj	|�}	y|j�jtj�}
Wnd	}
YnX|
�s�tj|d}ntj|d}|	�s|jjj|�}	|	�r*|d
|	7}|j|�|j�rd|dj�tjk�rd|j|j|d��|�rt|j|�|S)
z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the protocol of the URI of
        the link associated with obj.
        r�ftp�ftps�file��/r)�urirF� )r}r~r���)r!r"rTrUr�r<r>r[rA�
displayedText�urllib�parse�urlparse�splitrZLINK_TO_FILEZLINK_WITH_PROTOCOLrjrkrrlZLINK_WITH_PROTOCOL_VISITEDZlinkBasename�
childCountr�
ROLE_IMAGE)rr*r/r=r�link_uri�
link_uri_infoZfileNameZ
linkOutput�textZ	isVisitedr
r
rrx?s@



z!SpeechGenerator._generateLinkInfocKsg}|jt�}|jjj|�}|r.tjj|�}n|S|jjj�}|�r�tjj|�}|d|dkr�|d|dkr~|j	t
j�n|j	t
j�nn|dj
d�}	|dj
d�}
t|	�dkr�t|
�dkr�|	d|
dkr�|	d|
dkr�|j	t
j�n|j	t
j�|�r
|j|�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) that describe the site (same or different)
        pointed to by the URI of the link associated with obj.
        rr��.r�r����r�)r!r"rTrUr�r�r�r�ZdocumentFrameURIrArZLINK_SAME_PAGEZLINK_SAME_SITEr��lenZLINK_DIFFERENT_SITEr<)rr*r/r=rr�r�Zdoc_uriZdoc_uri_infoZ
linkdomainZ	docdomainr
r
rrzvs.

z(SpeechGenerator._generateSiteDescriptionc	Ks�g}|jt�}d}|jjj|�}|s(|Sy6tjj|�}y|j�d}Wnt	k
rZYnXWnt
tjjt
fk
r|YnX|r�t|�}|dkr�|jtj|��nB|dkr�|jtjt|�d�n |dkr�|jtjt|�d�|r�|j|�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the size (Content-length) of
        the file pointed to by the URI of the link associated with
        obj.
        rezContent-lengthi'i@Bg����MbP?g���ư>)r!r"rTrUr�r�ZrequestZurlopen�info�KeyError�
ValueError�errorZURLError�OSError�intrArZ
fileSizeBytesZFILE_SIZE_KB�floatZFILE_SIZE_MBr<)	rr*r/r=rZ
sizeStringr��x�sizer
r
rr{�s2


z!SpeechGenerator._generateFileSizec
KsTg}|jt�}y|j�}WnYn*Xtj|d<|j|j|f|��|j|�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the image on the the object, if
        it exists.  Otherwise, an empty array is returned.
        r1)r!r)Z
queryImagerr�r<r.)rr*r/r=rZimager
r
r�_generateImage�s


zSpeechGenerator._generateImagecs6|jj�rgSt�j|f|�}|r2|j|jt��|S)N)rT�inSayAllrm�_generateColumnHeaderr<r!r))rr*r/r=)rnr
rr��s
z%SpeechGenerator._generateColumnHeadercs6|jj�rgSt�j|f|�}|r2|j|jt��|S)N)rTr�rm�_generateRowHeaderr<r!r))rr*r/r=)rnr
rr��s
z"SpeechGenerator._generateRowHeadercKs |jjj|�sgS|j|f|�S)a�Returns an array of strings (and possibly voice and audio
        specifications) that represent the row header for an object
        that is in a table, if it exists and if it is different from
        the previous row header.  Otherwise, an empty array is
        returned.  The previous row header is determined by looking at
        the row header for the 'priorObj' attribute of the args
        dictionary.  The 'priorObj' is typically set by Orca to be the
        previous object with focus.
        )rTrUZcellRowChangedr�)rr*r/r
r
r�_generateNewRowHeader�sz%SpeechGenerator._generateNewRowHeadercKs.|jjj|�sgS|jd�r gS|j|f|�S)aReturns an array of strings (and possibly voice and audio
        specifications) that represent the column header for an object
        that is in a table, if it exists and if it is different from
        the previous column header.  Otherwise, an empty array is
        returned.  The previous column header is determined by looking
        at the column header for the 'priorObj' attribute of the args
        dictionary.  The 'priorObj' is typically set by Orca to be the
        previous object with focus.
        �
readingRow)rTrUZcellColumnChangedr3r�)rr*r/r
r
r�_generateNewColumnHeader�s

z(SpeechGenerator._generateNewColumnHeadercKsvg}|jt�}|jd|�}|j|j|f|��|j||�|rrtjd�rr|jdd�rr|j	t
j�|rr|j|�|S)ahOrca has a feature to automatically read an entire row of a table
        as the user arrows up/down the roles.  This leads to complexity in
        the code.  This method is used to return an array of strings
        (and possibly voice and audio specifications) for a single table
        cell itself.  The string, 'blank', is added for empty cells.
        ZREAL_ROLE_TABLE_CELL�speakBlankLinesr�F)r!r)�
_overrideRoler<r.�_restoreRoler8r9r3rAr�BLANK)rr*r/r=r�oldRoler
r
r�_generateRealTableCells

z&SpeechGenerator._generateRealTableCellcKs�tjd�rgS|sgS|jo*dtj|j�ks0gS|j�}|jtj�rHgS|jj�}|tj	tj
gkr�|jjj
�\}}|dkr~gS|jjj|j�r�gSn(|tjkr�||jjj|j�kr�gSngStjg}|j|jt��|S)ajReturns an array of strings (and possibly voice and audio
        specifications) if this is an icon within an layered pane or a
        table cell within a table or a tree table and the item is
        focused but not selected.  Otherwise, an empty array is
        returned.  [[[WDW - I wonder if this string should be moved to
        settings.py.]]]
        r2�	Selection�Left�Right)r�r�)r8r9rBr�listInterfacesrjrkZSTATE_SELECTEDrZROLE_TREE_TABLE�
ROLE_TABLErTrUZlastKeyAndModifiers�isLayoutOnlyr7�selectedChildrenrZSTATE_UNSELECTED_TABLE_CELLr<r!rp)rr*r/rrdZlastKeyZmodsr=r
r
r�_generateUnselectedCell"s.


z'SpeechGenerator._generateUnselectedCellc	
Ks�tjd�rgSg}|jt�}d}|jj�tjkr6|j}|j}y|j�}Wn(|j	dd�rl|j
jj	dd�}YnX|j
jj
|�}|j|�}|dkr�|jtj|d�|r�|j|�|S)	z�Returns an array of strings (and possibly voice and audio
        specifications) reflecting the column number of a cell.
        r2r�guessCoordinatesFZ
lastColumnrr�r�)r8r9r!r:rBrr�ROLE_TABLE_CELL�
queryTabler3rT�pointOfReferencerU�	cellIndex�getColumnAtIndexrArZTABLE_COLUMNr<)	rr*r/r=r�colrB�table�indexr
r
r�_generateColumnIs(



zSpeechGenerator._generateColumnc	
Ks�tjd�rgSg}|jt�}d}|jj�tjkr6|j}|j}y|j�}Wn(|j	dd�rl|j
jj	dd�}YnX|j
jj
|�}|j|�}|dkr�|jtj|d�|r�|j|�|S)	zReturns an array of strings (and possibly voice and audio
        specifications) reflecting the row number of a cell.
        r2rr�FZlastRowrr�r�)r8r9r!r:rBrrr�r�r3rTr�rUr��
getRowAtIndexrAr�	TABLE_ROWr<)	rr*r/r=r�rowrBr�r�r
r
r�_generateRowds(



zSpeechGenerator._generateRowc
Ks�tjd�rgSg}|jt�}|jj�tjkr2|j}|j}y|j�}Wnd}Yn\X|j	j
j|�}|j|�}|j
|�}	|jtj|d|jd��|jtj|	d|jd��|r�|j|�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) reflecting the position of the cell in terms
        of its column number, the total number of columns, its row,
        and the total number of rows.
        r2Nr)r��total)r8r9r!r:rBrrr�r�rTrUr�r�r�rArZTABLE_COLUMN_DETAILED�nColumnsZTABLE_ROW_DETAILED�nRowsr<)
rr*r/r=rrBr�r�r�r�r
r
r�_generateColumnAndRows.





z%SpeechGenerator._generateColumnAndRowcKsPtjd�rgStjd�tjkr"gS|jjj|�rLtjg}|j	|j
t��|SgS)z�Returns an array of strings (and possibly voice and audio
        specifications) indicating that this cell is the last cell
        in the table.
        r2rL)r8r9rZVERBOSITY_LEVEL_VERBOSErTrUZ
isLastCellrZ	TABLE_ENDr<r!r:)rr*r/r=r
r
r�_generateEndOfTableIndicator�s
z,SpeechGenerator._generateEndOfTableIndicatorcKs||j|f|�}|r|S|jt�}tjj||f|�}|rx|dgkrntjd�rn|jj	�rn|j
dd�dkrntjg}|j
|�|S)z�Returns an array of strings for use by speech and braille
        that represents the current line of text, if
        this is a text object.  [[[WDW - consider returning an empty
        array if this is not a text object.]]]
        �
r�r�r)�_generateSubstringr!r)rr�_generateCurrentLineTextr8r9rTr�r3rr�r<)rr*r/r=rr
r
rr��s

z(SpeechGenerator._generateCurrentLineTextcKs�|j|f|�}|r|S|jt�}tjj||f|�}|r�|dj�}t|�dkrv|jj	j
|�rvtj|�}||krv||d<|j
|�|S)Nrr)r�r!r)rr�_generateDisplayedTextr&r�rTrUZisMathr�getCharacterNamer<)rr*r/r=rr+Zcharnamer
r
rr��s


z&SpeechGenerator._generateDisplayedText�style�weight�	underlinecCsHd}|j�}|jjj|�\}}	|j|�}
|
dr`|jjj|
d�\}}x|D]}|||	|<qLW|	�rDx�|D]�}tj||j�}
||	krl|	|}tj||j�}|rl|dkr�t|�dkr�|dtj	7}ql|dkr�|dkr�|d|
7}ql|dk�r|d	k�r|d|7}ql|d
7}||
d
|7}qlW|jjj
||�dk�rD|dtj7}|S)zyHelper function that returns a string containing the
        given attributes from keys for the given character.
        rerr�i�z %sr�Znoner�Znormalr�)ZgetDefaultAttributesrTrUZstringToKeysAndDictZ
getAttributesr
ZgetTextAttributeNamer�rZBOLDZ	linkIndexZLINK)rr*r��
textOffsetZ	lineIndex�keysZ	attribStrZdefaultAttributesZkeyListZattributesDictionaryZcharAttributesZcharDict�keyZlocalizedKeyZ	attributeZlocalizedValuer
r
r�_getCharacterAttributes�s>	






z'SpeechGenerator._getCharacterAttributesc

Cs�y|jjdSYnX|j�}|j}|jjj|�\}}}|dk}|s�|j|jtj�\}}}t	|�rz|jjj
|�}|}n*|j|tj�}	|	ddkr�||kr�|	d}||||g|jjd<|jjdS)a�Returns [textContents, startOffset, endOffset, selected] as
        follows:

        A. if no text on the current line is selected, the current line
        B. if text is selected, the selected text
        C. if the current line is blank/empty, 'blank'

        Also sets up a 'textInformation' attribute in
        self._script.generatorCache to prevent computing this
        information repeatedly while processing a single event.
        ZtextInformationrerr�)rTZgeneratorCache�	queryText�caretOffsetrUZallSelectedText�getTextAtOffsetr�TEXT_BOUNDARY_LINE_STARTr�ZadjustForRepeatsZTEXT_BOUNDARY_CHAR)
rr*�textObjr�ZtextContents�startOffset�	endOffset�selected�line�charr
r
r�_getTextInformations*
z#SpeechGenerator._getTextInformationc
Kst|j|f|�}|r|Sy|j�}Wntk
r6gSXg}|jt�}|j|�\}}}}	|rp|j|�|j|�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) containing the text content.  This requires
        _generateTextInformation to have been called prior to this method.
        )r�r��NotImplementedErrorr!r)r�rAr<)
rr*r/r=r�rr�r�r�r�r
r
r�_generateTextContent@s


z$SpeechGenerator._generateTextContentcKs�y|j�}Wntk
r gSX|jt�}|j|�\}}}}d}	d}
|}xftdt|��D]T}|j||||�}
|
r�|
|
kr�|	r�|	d7}	|	|
7}	|	d7}	|
}
|	||7}	|d7}qZW|j|||ddg�}
|
r�|	r�|	d7}	|	|
7}	|	g}|j|�|S)a;Returns an array of strings (and possibly voice and audio
        specifications) containing the text content, obtained from the
        'textInformation' value, with character attribute information
        mixed in.  This requires _generateTextInformation to have been
        called prior to this method.
        reNrz ; r�rzparagraph-style)	r�r�r!r)r��ranger�r�r<)rr*r/r�rr�r�r�r�ZnewLineZlastAttribsr��iZattribsr=r
r
r�"_generateTextContentWithAttributes]s>

z2SpeechGenerator._generateTextContentWithAttributesc
Ksntjd�rgSy|j�}Wntk
r.gSXg}|jt�}|j|�\}}}}	|	rj|jtj	�|j
|�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) that says if any of the text for the entire
        object is selected. [[[WDW - I wonder if this string should be
        moved to settings.py.]]]
        r2)r8r9r�r�r!r:r�rAr�
TEXT_SELECTEDr<)
rr*r/r�r=rr�r�r�r�r
r
r�_generateAnyTextSelection�s


z)SpeechGenerator._generateAnyTextSelectionc
	Ks�tjd�rgSg}|jt�}y|j�}WnYnLX|j�}|dkr�|jdtj�\}}}	|dkr�|	t	|�kr�t
jg}|j|�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) that says if all the text for the entire
        object is selected. [[[WDW - I wonder if this string should be
        moved to settings.py.]]]
        r2rr)
r8r9r!r:r�ZgetNSelectionsr�rr�r�rr�r<)
rr*r/r=rr�ZnoOfSelectionsr+r�r�r
r
r�_generateAllTextSelection�s


z)SpeechGenerator._generateAllTextSelectioncs�t�j|f|�}|o|ds gS|j�jtj�s@|dj�|d<|j|j||d��|ddkr�t	j
d�r�|jj�r�|j
dd�dkr�tj|d<|S)Nrr�rer�r�r)r�re)rmr�rjrkrZSTATE_EDITABLEr&r<r,r8r9rTr�r3rr�)rr*r/r=)rnr
rr��s
z"SpeechGenerator._generateSubstringcKsPtjd�sgS|jj|�\}}}|jjj|�}|s6gS|g}|j|jt��|S)z�Speaks a summary of the number of spaces and/or tabs at the
        beginning of the given line.

        Arguments:
        - obj: the text object.
        ZenableSpeechIndentation)	r8r9rTZgetTextLineAtCaretrUZindentationDescriptionr<r!r:)rr*r/r�r�r��descriptionr=r
r
r�_generateTextIndentation�s
z(SpeechGenerator._generateTextIndentationcKsrtjd�rgSg}|jt�}|jjj|jdd��}|jjj|�}||krn|dkrn|j|j	|f|��|j|�|S)a�Returns an array of strings (and possibly voice and audio
        specifications) that represents the tree node level of the
        object, or an empty array if the object is not a tree node or
        if the node level is not different from the 'priorObj'
        'priorObj' attribute of the args dictionary.  The 'priorObj'
        is typically set by Orca to be the previous object with
        focus.
        r2rGNr)
r8r9r!r:rTrUZ	nodeLevelr3r<Z_generateNodeLevel)rr*r/r=rZoldLevelZnewLevelr
r
r�_generateNewNodeLevel�s	


z%SpeechGenerator._generateNewNodeLevelcKsHtjd�rgS|jjj|�}|dk	rDtj|�g}|j|jt	��|SgS)aReturns an array of strings (and possibly voice and audio
        specifications) that represents the percentage value of the
        object.  This is typically for progress bars. [[[WDW - we
        should consider returning an empty array if there is no value.
        r2N)
r8r9rTrU�getValueAsPercentr�
percentager<r!r:)rr*r/ZpercentValuer=r
r
r�_generatePercentages
z#SpeechGenerator._generatePercentagecKs�g}|jt�}|jdd�}|r�|j�tjkr�d}d}|j�}xn|D]f}	|rd|	j�tjkrd|	j	d�}|rB|	j�tj
krBx.td|	j��D]}
|	j	|
�}||kr�d}Pq�WqBW|r�|r�|j
|jjj|��|j|�|S)a�Returns an array of strings (and possibly voice and audio
        specifications) that represents the radio button group label
        of the object, or an empty array if the object has no such
        label or if the radio button group is not different from the
        'priorObj' 'priorObj' attribute of the args dictionary.  The
        'priorObj' is typically set by Orca to be the previous object
        with focus.
        rGNFrT)r!r)r3rr�ROLE_RADIO_BUTTON�getRelationSet�getRelationTypeZRELATION_LABELLED_BY�	getTarget�RELATION_MEMBER_OFr��getNTargetsrArTrUr�r<)rr*r/r=rrGZradioGroupLabelZinSameGroup�	relations�relationr��targetr
r
r�_generateNewRadioButtonGroups2







z,SpeechGenerator._generateNewRadioButtonGroupc	Ks�tjd�rgSg}|jt�}|jjj|�}t|�}|rT|jt	j
|��|j|�|S|jd|j
��}|tjtjgkr�dd�|D�}t|�}|s�gSt	j|�g}|j|�|S)a5Returns an array of strings (and possibly voice and audio
        specifications) that represents the number of children the
        object has.  [[[WDW - can we always return an empty array if
        this doesn't apply?]]] [[[WDW - I wonder if this string should
        be moved to settings.py.]]]
        r2r1cSsg|]}|j�tjkr|�qSr
)rrZROLE_LIST_ITEM)�.0r�r
r
r�
<listcomp>Tsz=SpeechGenerator._generateNumberOfChildren.<locals>.<listcomp>)r8r9r!r:rTrU�
childNodesr�rArZ	itemCountr<r3rr�	ROLE_LISTraZ
listItemCount)	rr*r/r=rr��childrenr1Zsetsizer
r
r�_generateNumberOfChildren?s&



z)SpeechGenerator._generateNumberOfChildrencKsftjd�rgSg}|jt�}d}x&|D]}|j�}|jtj�r&d}Pq&W|sb|jt	j
�|j|�|S)ahReturns an array of strings (and possibly voice and audio
        specifications) that says if this object has no showing
        children (e.g., it's an empty table or list).  object has.
        [[[WDW - can we always return an empty array if this doesn't
        apply?]]] [[[WDW - I wonder if this string should be moved to
        settings.py.]]]
        r2FT)r8r9r!r:rjrkr�
STATE_SHOWINGrAr�
ZERO_ITEMSr<)rr*r/r=rZhasItems�childrr
r
r�_generateNoShowingChildren^s



z*SpeechGenerator._generateNoShowingChildrencKs<tjd�rgSg}|jt�}|js8|jtj�|j|�|S)ahReturns an array of strings (and possibly voice and audio
        specifications) that says if this object has no children at
        all (e.g., it's an empty table or list).  object has.  [[[WDW
        - can we always return an empty array if this doesn't
        apply?]]] [[[WDW - I wonder if this string should be moved to
        settings.py.]]]
        r2)	r8r9r!r:r�rArr�r<)rr*r/r=rr
r
r�_generateNoChildrenvs


z#SpeechGenerator._generateNoChildrencKs�g}|jd|j��}|tjtjgkr(|Sdtj|�krF|jjj|�}n|jjj	|�g}|o`|dsf|Sxt
|j|�D]}|j|�qtW|S)Nr1r�r)
r3rrr�rar�rTrUr�ZfocusedChild�mapr;r<)rr*r/r=r1�items�itemr
r
r�_generateFocusedItem�sz$SpeechGenerator._generateFocusedItemcKs�tjd�rgS|}dtj|�kr8|j}dtj|�kr8gSg}|jt�}|j}t|j	j
j|��}|jt
j||��|j|�|j|j	jjddd�|j�d|d��|j|�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) indicating how many items are selected in this
        and the position of the current item. This object will be an icon
        panel or a layered pane.
        r2r�rZ	iconindex)�mode�
stringTyper)r�r�)r8r9rr�rBr!r:r�r�rTrUr�rArZselectedItemsCountr<�
formatting�	getString�getIndexInParent)rr*r/�	containerr=rr�Z
selectedCountr
r
r�_generateSelectedItemCount�s(




z*SpeechGenerator._generateSelectedItemCountcKsVtjd�rgS|}dtj|�kr8|j}dtj|�kr8gS|jjj|�}tt	|j
|��S)z�Returns an array of strings (and possibly voice and audio
        specifications) containing the names of all the selected items.
        This object will be an icon panel or a layered pane.
        r2r�)r8r9rr�rBrTrUr��listr��_generateLabelAndName)rr*r/rZ
selectedItemsr
r
r�_generateSelectedItems�s
z&SpeechGenerator._generateSelectedItemsc	Ksftjd�rgSg}|jt�}y|jjj|�}Wnd}YnX|dkrb|jtj	|��|j
|�|S)aReturns an array of strings (and possibly voice and audio
        specifications) that says how many unfocused alerts and
        dialogs are associated with the application for this object.
        [[[WDW - I wonder if this string should be moved to
        settings.py.]]]
        r2r)r8r9r!r:rTrU�unfocusedAlertAndDialogCountrAr�dialogCountSpeechr<)rr*r/r=r�alertAndDialogCountr
r
r�_generateUnfocusedDialogCount�s



z-SpeechGenerator._generateUnfocusedDialogCountcCsptjtjtjddtjtjtjg}gg}}|jj�r�t	j
d�rJ|jtj�t	j
d�rd|jtjdg�t	j
d�rz|jtj�t	j
d�r�|jtjdg�t	j
d�r�|jtj�t	j
d�r�|jtj�n�t	j
d	�r�|jtj�t	j
d
�r�|jtjdg�t	j
d��r
|jtj�t	j
d��r&|jtjdg�t	j
d
��r>|jtj�t	j
d��rV|jtj�t
t|�j|��}||fS)N�ROLE_DPUB_LANDMARK�ROLE_DPUB_SECTIONZsayAllContextBlockquoteZsayAllContextLandmarkZsayAllContextListZsayAllContextPanelZsayAllContextNonLandmarkFormZsayAllContextTableZspeakContextBlockquoteZspeakContextLandmarkZspeakContextListZspeakContextPanelZspeakContextNonLandmarkFormZspeakContextTable)r�ROLE_BLOCK_QUOTE�	ROLE_FORM�
ROLE_LANDMARKr��
ROLE_PANELr�rTr�r8r9rAr<r�set�symmetric_difference)rZallRolesrYrZr
r
rrW�sH









z2SpeechGenerator._getEnabledAndDisabledContextRolescKs�|jd�sgS|jd|j��}|j�\}}||kr6gS|jdd�}g}|tjkrz|dkrj|jtj|��n|jtj��nR|tj	kr�|j
jj|�r�|dkr�|jtj
|��n|jtj��n|tjk�r*|j
jj|�r�|jtj�nB|j
jj|��r|jtj�n$|j
jj|��r |jtj�ndg}�n�|tjk�rV|j
jj|��rV|jtj��nv|dk�r�|j
jj|��r�|jtj��q�|j
jj|��r�|jtj��q�|j
jj|��r�|jtj��q�|j
jj|��r�|jtj ��q�|j
jj!|��r|jtj"��q�|j
jj#|��r |jtj$��q�|j
jj%|��r@|jtj&��q�|j
jj'|��r`|jtj(��q�|j
jj)|��r�|jtj*��q�|j
jj+|��r�|jtj,��q�|j
jj-|��r�|jtj.�n�|j
jj/|��r�|jtj0�n�|j
jj1|��r�|jtj2�n�|j
jj3|��r|jtj4�n�|j
jj5|��r6|jtj6�nv|j
jj7|��rT|jtj8�nX|j
jj9|��rr|jtj:�n:|j
jj;|��r�|jtj<�n|j
jj=|��r�|jtj>��n|dk�r�|j
jj?|��r�|jtj@�n�|j
jjA|��r�|jtjB�n�|j
jjC|��r|jtjD�n�|j
jjE|��r2|jtjF�nv|j
jjG|��rP|jtjH�nX|j
jjI|��rn|jtjJ�n:|j
jjK|��r�|jtjL�n|j
jjM|��r�|jtjN��n |j
jjO|��r�|j
jjP|��r�|jtjQ�n�|j
jjR|��r�|jtjS�n�|j
jjT|��r|jtjU�n�|j
jjV|��r4|jtjW�nv|j
jjX|��rR|jtjY�nX|j
jjZ|��rp|jtj[�n:|j
jj\|��r�|jtj]�n|j
jj^|��r�|jtj_�n |tj`k�r�|jtj_�ndg}|�r�|ja|jbtc��|S)NrSr1�countrrerr)dr3rrWrrrArZleavingNBlockquotesZLEAVING_BLOCKQUOTEr�rTrUZisDocumentListZ
leavingNListsZLEAVING_LISTrZisFeedZLEAVING_FEEDZisFigureZLEAVING_FIGUREZisDocumentPanelZ
LEAVING_PANELr�rVZ
LEAVING_TABLEZisDPubAcknowledgmentsZLEAVING_ACKNOWLEDGMENTSZisDPubAfterwordZLEAVING_AFTERWORDZisDPubAppendixZLEAVING_APPENDIXZisDPubBibliographyZLEAVING_BIBLIOGRAPHYZ
isDPubChapterZLEAVING_CHAPTERZisDPubConclusionZLEAVING_CONCLUSIONZ
isDPubCreditsZLEAVING_CREDITSZisDPubEndnotesZLEAVING_ENDNOTESZisDPubEpilogueZLEAVING_EPILOGUEZisDPubErrataZLEAVING_ERRATAZisDPubForewordZLEAVING_FOREWORDZisDPubGlossaryZLEAVING_GLOSSARYZisDPubIndexZ
LEAVING_INDEXZisDPubIntroductionZLEAVING_INTRODUCTIONZisDPubPagelistZLEAVING_PAGELISTZ
isDPubPartZLEAVING_PARTZ
isDPubPrefaceZLEAVING_PREFACEZisDPubPrologueZLEAVING_PROLOGUEZ	isDPubTocZLEAVING_TOCZisDPubAbstractZLEAVING_ABSTRACTZisDPubColophonZLEAVING_COLOPHONZisDPubCreditZLEAVING_CREDITZisDPubDedicationZLEAVING_DEDICATIONZisDPubEpigraphZLEAVING_EPIGRAPHZ
isDPubExampleZLEAVING_EXAMPLEZisDPubPullquoteZLEAVING_PULLQUOTEZ	isDPubQnaZLEAVING_QNAZ
isLandmarkZisLandmarkBannerZLEAVING_LANDMARK_BANNERZisLandmarkComplementaryZLEAVING_LANDMARK_COMPLEMENTARYZisLandmarkContentInfoZLEAVING_LANDMARK_CONTENTINFOZisLandmarkMainZLEAVING_LANDMARK_MAINZisLandmarkNavigationZLEAVING_LANDMARK_NAVIGATIONZisLandmarkRegionZLEAVING_LANDMARK_REGIONZisLandmarkSearchZLEAVING_LANDMARK_SEARCHZisLandmarkFormZLEAVING_FORMrr<r!r:)rr*r/r1rYrZrr=r
r
r�_generateLeaving
s�




z SpeechGenerator._generateLeavingc	s�g}|jd�}|r,|jd�r,|}|jd�}n
|jd�}|rL|j�tjkrLgS|r`|j|jkr`gS�jjj|�rrgS�jjj||�}||kr�gS|jdg�}|jdg�}|j	tj
��j�\}	}
|j|
�|jdg�}|jtj
tjg�tjtjg}d}
|o�|�r`�j|���|k�r`��fdd�}tj||�}tj||�}�jjj|�}�jjj|�}||k}
gg}}|j}x�|�r||jk�r�j|�}||k�r�P||k�r�nH|�r�||k�r�n6�jjj|��r�n$||k�s�|
�r�|j	|�|j	|�||k�r�P|j}�qrWg}x|t|�D]p\}}||}||k�r<||k�r<�q|j	|�|j|�}�j||�|j	�j|d	|||d
���j||��qW|�s�|j�|S)aEReturns an array of strings (and possibly voice and audio
        specifications) that represent the text of the ancestors for
        the object.  This is typically used to present the context for
        an object (e.g., the names of the window, the panels, etc.,
        that the object is contained in).  If the 'priorObj' attribute
        of the args dictionary is set, only the differences in
        ancestry between the 'priorObj' and the current obj will be
        computed.  The 'priorObj' is typically set by Orca to be the
        previous object with focus.
        rSrG�includeOnly�	skipRoles�stopAtRolesFcs|o�j|��kS)N)�_getAlternativeRole)r�)�
commonRolerr
r�<lambda>�sz4SpeechGenerator._generateAncestors.<locals>.<lambda>�focused)�
formatTyper1rSr)r3rrrHrBrTrUZisTypeahead�commonAncestorrAZROLE_TREE_ITEMrWr<ZROLE_APPLICATIONZ
ROLE_MENU_BARrr�r�findAncestor�nestingLevelr��	enumeraterr�r.r��reverse)rr*r/r=rSrGr!rrrYrZrZpresentOnceZpresentCommonAncestorZpredZobjAncestorZ
priorAncestorZobjLevelZ
priorLevelZ	ancestorsZ
ancestorRolesrBrdZpresentedRolesr�r�ZaltRolerr
)rrr�_generateAncestors�s�













z"SpeechGenerator._generateAncestorscs tjd�rgS|jjj�rgS|jd���s6|�kr:gS|j��j�ks^tj|�fdd��rbgS|jjj	|�\}}|r|gSd|d<tj
tjtjddtj
tjtjg|d	<g}|jjj��r�|j��}|j||�|j|j�|d
dd��|j||�|j|j|f|��|jd�|jd	�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the text of the ancestors for
        the object being left.r2rGcs|�kS)Nr
)r�)rGr
rr�sz7SpeechGenerator._generateOldAncestors.<locals>.<lambda>TrSrrrr)r1r rS)r8r9rTrU�
inFindToolbarr3ZgetApplicationrr"�frameAndDialogrrrr�rr�ZisBlockquoterr�r<r.r�r&�pop)rr*r/�frame�dialogr=r�r
)rGr�_generateOldAncestors�sB




z%SpeechGenerator._generateOldAncestorscKs�tjd�rgS|jjj�rgS|jd�}||kr4gSg}|j�tjkr^|sZ|j�tj	kr^|S|jjj
|�}|s�|r�|j�tjkr�|j|f|�}|S)awReturns an array of strings (and possibly voice and audio
        specifications) that represent the text of the ancestors for
        the object.  This is typically used to present the context for
        an object (e.g., the names of the window, the panels, etc.,
        that the object is contained in).  If the 'priorObj' attribute
        of the args dictionary is set, only the differences in
        ancestry between the 'priorObj' and the current obj will be
        computed.  Otherwise, no ancestry will be computed.  The
        'priorObj' is typically set by Orca to be the previous object
        with focus.
        r2rG)
r8r9rTrUr'r3rrZROLE_MENU_ITEMZROLE_WINDOW�topLevelObjectZROLE_DIALOGr&)rr*r/rGr=ZtopLevelObjr
r
r�_generateNewAncestorss 

z%SpeechGenerator._generateNewAncestorscKs8|jd�|krgS|j|f|�}|j|j|f|��|S)NrG)r3r,rAr.)rr*r/r=r
r
r�generateContext.s
zSpeechGenerator.generateContextcKsV|jd|j��tjkr.|jdd�dkr.tjgS|jj�tjtjgkrJ|j}|j	|j�S)z�Returns an array of strings (and possibly voice and audio
        specifications) containing the role name of the parent of obj.
        r1r N�
basicWhereAmI�detailedWhereAmI)r0r1)
r3rrrbrZROLE_ICON_PANELrBr�r_r[)rr*r/r
r
r�_generateParentRoleName6s
z'SpeechGenerator._generateParentRoleNamecKsFg}|jjj|tjgtjg�}|rB|j|j|��|j|j|��|S)z�Returns an array of strings (and possibly voice and audio
        specifications) containing the name and role of the toolbar
        which contains obj.
        )	rTrUZancestorWithRolerZ
ROLE_TOOL_BARZ
ROLE_FRAMEr<r	r[)rr*r/r=Zancestorr
r
r�_generateToolbarBsz SpeechGenerator._generateToolbarcKs�tjd�rgSg}|jt�}d}d	}y|j�}Wng}YnXxd|D]\}|j�tjkrHd}xDtd|j	��D]2}	|j
|	�}
|
j�jtj
�rn|d7}|
|krn|}qnWqHW|dkr�||d}|j|jjjddd�||d��|j|�|S)
z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the relative position of an
        object in a group.
        r2rrr�
groupindex)rr)r�r�r�r�)r8r9r!r:r�r�rr�r�r�r�rjrkr�rArTrrr<)rr*r/r=r�positionr�r�r�r�r�r
r
r�_generatePositionInGroupOs8





z(SpeechGenerator._generatePositionInGroupcKs�tjd�s"tjd�p|jdd�r&gS|j�tjkrL|j|jjj	|�krLgS|jjj
|�r^gSg}|jt�}|jjj
|�\}}|dks�|dkr�gS|d7}|j|jjjddd	�||d
��|j|�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the relative position of an
        object in a list.
        r2ZenablePositionSpeakingZ	forceListFrrrr4)rr)r�r�)r8r9r3rrr_rBrTrUr-rir!r:ZgetPositionAndSetSizerArrr<)rr*r/r=rr5r�r
r
r�_generatePositionInListvs,



z'SpeechGenerator._generatePositionInListc	Ksh|jd�s|j|f|�r gSg}|j�\}}}||krd|j|�\}}tj|g}|j|jt��|S)N�isProgressBarUpdate)	r3�_shouldPresentProgressBarUpdateZ_getMostRecentProgressBarUpdateZgetProgressBarNumberAndCountrZPROGRESS_BAR_NUMBERr<r!r:)	rr*r/r=ZaccZ
updateTimeZupdateValueZnumberrr
r
r�_generateProgressBarIndex�sz)SpeechGenerator._generateProgressBarIndexcKs\|jd�r|j|f|�rgSg}|jjj|�}|dk	rX|jtj|��|j|j	t
��|S)Nr8)r3r9rTrUr�rArr�r<r!r:)rr*r/r=Zpercentr
r
r�_generateProgressBarValue�s
z)SpeechGenerator._generateProgressBarValuecs$tjd�}|dkrt�j�}t|�S)NZprogressBarSpeechInterval)r8r9rm�_getProgressBarUpdateIntervalr�)rZinterval)rnr
rr<�s

z-SpeechGenerator._getProgressBarUpdateIntervalcstjd�sdSt�j|f|�S)NZspeakProgressBarUpdatesF)r8r9rmr9)rr*r/)rnr
rr9�s
z/SpeechGenerator._shouldPresentProgressBarUpdatecKs\g}|jjj|�}|rX|j�jtj�rX|j|�}|rX|jt	j
|d�|j|jt
��|S)z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the default button in a dialog.
        This method should initially be called with a top-level window.
        r)rTrUZ
defaultButtonrjrkrZSTATE_SENSITIVEr;rArZDEFAULT_BUTTON_ISr<r!r:)rr*r/r=Zbuttonr?r
r
r�_generateDefaultButton�s
z&SpeechGenerator._generateDefaultButtoncKs|j|f|�S)z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the default button of the window
        containing the object.
        )r=)rr*r/r
r
r�generateDefaultButton�sz%SpeechGenerator.generateDefaultButtoncKst|jjj|�}|sgS|j|�}|r(|SxF|D]>}|j|�}|r^|j�tjkr^|j|dd�}|r.|j|�q.W|S)z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the status bar of a window.
        This method should initially be called with a top-level window.
        F)�includeContext)	rTrU�	statusBarr;rrZ
ROLE_LABELr.r<)rr*r/r@r=r�ZchildResultr
r
r�_generateStatusBar�s


z"SpeechGenerator._generateStatusBarcKs|j|f|�S)z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the status bar of the window
        containing the object.
        )rA)rr*r/r
r
r�generateStatusBar�sz!SpeechGenerator.generateStatusBarc	Ks�g}|jt�}|jjj|�\}}|r4|j|j|��|rH|j|j|��|jjj|�}|dkr~tj	|�g}|j
|�|j|�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the title of the window, obj.
        containing the object, along with information associated with
        any unfocused dialog boxes.
        r)r!r)rTrUr(rAr	rrrr<)	rr*r/r=rr*r+r
Zdialogsr
r
r�
generateTitle�s


zSpeechGenerator.generateTitlecs�tjtjtjtjtjtjtjg��fdd�}g}|jr�|jj	�tj
kr�tj||�}x.|D]&}|jj
j|�rX|j|j|dd��qXW|S)Ncs|o|j��kS)N)r)r�)�widgetRolesr
rrsz=SpeechGenerator._generateListBoxItemWidgets.<locals>.<lambda>F)r?)rZROLE_CHECK_BOXr`ZROLE_PUSH_BUTTONr�ZROLE_SLIDERZ	ROLE_TEXTZROLE_TOGGLE_BUTTONrBrraZfindAllDescendantsrTrUZisShowingAndVisiblerAr.)rr*r/ZisWidgetr=ZwidgetsZwidgetr
)rDr�_generateListBoxItemWidgetss
z+SpeechGenerator._generateListBoxItemWidgetscKsLtjd�rgSg}|jt�}|jjj|�\}}}|rH|j|�|j|�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the accelerator for the object,
        or an empty array if no accelerator can be found.
        r2)	r8r9r!r:rTrU�mnemonicShortcutAcceleratorrAr<)rr*r/r=r�mnemonic�shortcut�acceleratorr
r
r�_generateAccelerator s



z$SpeechGenerator._generateAcceleratorcKsxtjd�rgSg}|jt�}tjd�s2|jdd�rt|jjj|�\}}}|rR|d}|r`|r`|}|rt|g}|j|�|S)z�Returns an array of strings (and possibly voice and audio
        specifications) that represent the mnemonic for the object, or
        an empty array if no mnemonic can be found.
        r2ZenableMnemonicSpeakingZ
forceMnemonicFrr�)	r8r9r!r:r3rTrUrFr<)rr*r/r=rrGrHrIr
r
r�_generateMnemonic2s




z!SpeechGenerator._generateMnemonicc
Ks�tjd�rgSg}|jt�}|jdd�}|jdd�}|jd|j��}|j|jjj	||||��|jd|j��t
jkr�|jdd�dkr�|jjj
|�\}}	|r�|j|jjj	|||��|r�|d	r�|j|�|S)
a�Returns an array of strings (and possibly voice and audio
        specifications) that represent the tutorial for the object.
        The tutorial will only be generated if the user has requested
        tutorials, and will then be generated according to the
        tutorial generator.  A tutorial can be forced by setting the
        'forceTutorial' attribute of the args dictionary to True.
        r2�alreadyFocusedF�
forceTutorialr1r Z	unfocusedr0r)r8r9r!r:r3rr<rTZtutorialGeneratorZgetTutorialrrbrUr()
rr*r/r=rrLrMr1r*r+r
r
r�_generateTutorialPs.


z!SpeechGenerator._generateTutorialcKs�g}dd�|D�p|g}xh|D]`}|jjj|�rH|jrH|j|j|��q|j|�}|j||�|j|j||d��|j	||�qW|S)NcSsg|]}|�qSr
r
)r�r�r
r
rr�usz1SpeechGenerator._generateMath.<locals>.<listcomp>)r1)
rTrU�isMathLayoutOnlyr�r<�
_generateMathrr�r.r�)rr*r/r=r�r�r�r
r
rrPss

zSpeechGenerator._generateMathcKs|j|f|�S)N)rP)rr*r/r
r
r�_generateEnclosedBase�sz%SpeechGenerator._generateEnclosedBasecKsg}|jjj|�}d|kr&|jtj�d|kr:|jtj�d|krN|jtj�d|krb|jtj�d|krv|jtj	�d|kr�|jtj
�d|kr�|jtj�d|kr�|jtj�d	|kr�|jtj
�d
|kr�|jtj�d|kr�|jtj�d|k�r|jtj�d
|k�r|jtj�d|k�r0|jtj�d|k�rF|jtj�d|k�r\|jtj�d|k�rr|jtj�|�s�d|}tjtj|�gSt|�dk�r�tj|dg}nB|jdtj�t|�dk�r�tjdj|�g}ntjdj|�g}|j|jt ��|S)NZ	actuarialZboxZcircleZlongdivZradicalZ
roundedboxZhorizontalstrikeZverticalstrikeZdowndiagonalstrikeZupdiagonalstrikeZnortheastarrowZbottom�left�right�topZphasorangleZmadruwbz,INFO: Could not get enclosure message for %srr�r�z, r�)!rTrUZgetMathEnclosuresrArZMATH_ENCLOSURE_ACTUARIALZMATH_ENCLOSURE_BOXZMATH_ENCLOSURE_CIRCLEZMATH_ENCLOSURE_LONGDIVZMATH_ENCLOSURE_RADICALZMATH_ENCLOSURE_ROUNDEDBOXZMATH_ENCLOSURE_HORIZONTALSTRIKEZMATH_ENCLOSURE_VERTICALSTRIKEZ!MATH_ENCLOSURE_DOWNDIAGONALSTRIKEZMATH_ENCLOSURE_UPDIAGONALSTRIKEZMATH_ENCLOSURE_NORTHEASTARROWZMATH_ENCLOSURE_BOTTOMZMATH_ENCLOSURE_LEFTZMATH_ENCLOSURE_RIGHTZMATH_ENCLOSURE_TOPZMATH_ENCLOSURE_PHASOR_ANGLEZMATH_ENCLOSURE_MADRUWBrr6r@r�ZMATH_ENCLOSURE_ENCLOSED_BY�insertZMATH_ENCLOSURE_AND�joinr<r!r:)rr*r/ZstringsZ
enclosuresrDr=r
r
r�_generateEnclosedEnclosures�s`





z+SpeechGenerator._generateEnclosedEnclosurescKs:|jjj|�\}}|r6tj|�g}|j|jt��|SgS)N)rTrU�
getMathFencesrr�r<r!r))rr*r/�
fenceStart�fenceEndr=r
r
r�_generateFencedStart�sz$SpeechGenerator._generateFencedStartc	Ks�g}|jjj|�}x*tt|�|jd�D]}|j|d�q(W|jd�xht|�D]\\}}|j|j	|f|��t
j||�}|j|�|j|jt
��|rR|j|j|f|��qRW|S)Nrrer�)rTrUZgetMathFencedSeparatorsr�r�r�rAr$r<rPrr�r!r)ry)	rr*r/r=Z
separatorsr�r�r�Z
separatorNamer
r
r�_generateFencedContents�s

z'SpeechGenerator._generateFencedContentscKs:|jjj|�\}}|r6tj|�g}|j|jt��|SgS)N)rTrUrYrr�r<r!r))rr*r/rZr[r=r
r
r�_generateFencedEnd�sz"SpeechGenerator._generateFencedEndcKs4|jjj|�rtjg}ntjg}|j|jt��|S)N)	rTrUZisMathFractionWithoutBarrZMATH_FRACTION_WITHOUT_BAR_STARTZMATH_FRACTION_STARTr<r!r:)rr*r/r=r
r
r�_generateFractionStart�s

z&SpeechGenerator._generateFractionStartcKsZ|jjj|�}|jjj|�r&|j|�S|j|�}|j||�|j||d�}|j||�|S)N)r1)	rTrUZgetMathNumeratorrOrPrr�r.r�)rr*r/�	numeratorr�r=r
r
r�_generateFractionNumerator�s

z*SpeechGenerator._generateFractionNumeratorcKsZ|jjj|�}|jjj|�r&|j|�S|j|�}|j||�|j||d�}|j||�|S)N)r1)	rTrUZgetMathDenominatorrOrPrr�r.r�)rr*r/�denominatorr�r=r
r
r�_generateFractionDenominator�s

z,SpeechGenerator._generateFractionDenominatorcKstjg}|j|jt��|S)N)rZMATH_FRACTION_LINEr<r!r:)rr*r/r=r
r
r�_generateFractionLine�sz%SpeechGenerator._generateFractionLinecKstjg}|j|jt��|S)N)rZMATH_FRACTION_ENDr<r!r:)rr*r/r=r
r
r�_generateFractionEnd	sz$SpeechGenerator._generateFractionEndcKs�g}|jjj|�rtjg}n�|jjj|�}|jjj|�}|dkrJtjg}n�|dkr\tjg}n�|rv|g}|jtj	g�nl|jjj
|�r�|j|�}|jtj	g�nD|j|�}|j
||�|j|j||d��|j||�|jtj	g�|r�|j|jt��|S)N�2�3)r1)rTrU�isMathSquareRootrZMATH_SQUARE_ROOT_OFZgetMathRootIndexr�ZMATH_CUBE_ROOT_OFr<ZMATH_ROOT_OFrOrPrr�r.r�r!r:)rr*r/r=r�r+r�r
r
r�_generateRootStart	s.




z"SpeechGenerator._generateRootStartcKs�|jjj|�}|sgS|jjj|�s@|jjj|�s@|jjj|�rJ|j|�S|j|f|�g}|j|�}|j	||�|j
|j||d��|j||�|S)N)r1)
rTrUZgetMathRootBaserhZisMathTokenrOrPryrr�r<r.r�)rr*r/�baser=r�r
r
r�_generateRootBase#	s

z!SpeechGenerator._generateRootBasecKstjg}|j|jt��|S)N)rZ
MATH_ROOT_ENDr<r!r:)rr*r/r=r
r
r�_generateRootEnd5	sz SpeechGenerator._generateRootEndcKs |jjj|�}|sgS|j|�S)N)rTrUZgetMathScriptBaserP)rr*r/rjr
r
r�_generateScriptBase:	sz#SpeechGenerator._generateScriptBasecKsL|jjj|�r|j|�S|j|�}|j||�|j||d�}|j||�|S)N)r1)rTrUrOrPrr�r.r�)rr*r/r�r=r
r
r�_generateScriptScriptA	s

z%SpeechGenerator._generateScriptScriptcKsB|jjj|�}|sgStjg}|j|jt��|j|j|��|S)N)	rTrUZgetMathScriptSubscriptr�MATH_SUBSCRIPTr<r!r:rn)rr*r/Z	subscriptr=r
r
r�_generateScriptSubscriptL	sz(SpeechGenerator._generateScriptSubscriptcKsB|jjj|�}|sgStjg}|j|jt��|j|j|��|S)N)	rTrUZgetMathScriptSuperscriptr�MATH_SUPERSCRIPTr<r!r:rn)rr*r/Zsuperscriptr=r
r
r�_generateScriptSuperscriptW	sz*SpeechGenerator._generateScriptSuperscriptcKsB|jjj|�}|sgStjg}|j|jt��|j|j|��|S)N)	rTrUZgetMathScriptUnderscriptrZMATH_UNDERSCRIPTr<r!r:rn)rr*r/Zunderscriptr=r
r
r�_generateScriptUnderscriptb	sz*SpeechGenerator._generateScriptUnderscriptcKsB|jjj|�}|sgStjg}|j|jt��|j|j|��|S)N)	rTrUZgetMathScriptOverscriptrZMATH_OVERSCRIPTr<r!r:rn)rr*r/Z
overscriptr=r
r
r�_generateScriptOverscriptm	sz)SpeechGenerator._generateScriptOverscriptcKs�g}|jjj|�}xht|�D]\\}}|jjj|�r4q|drFtjg}ntjg}|j|j	t
��|j|j|��|j|�qW|S)Nr�)
rTrUZgetMathPrescriptsr$�
isNoneElementrZMATH_PRE_SUPERSCRIPTZMATH_PRE_SUBSCRIPTr<r!r:rnrA)rr*r/r=Z
prescriptsr�r�rvr
r
r�_generateScriptPrescriptsx	s
z)SpeechGenerator._generateScriptPrescriptscKs�g}|jjj|�}xht|�D]\\}}|jjj|�r4q|drFtjg}ntjg}|j|j	t
��|j|j|��|j|�qW|S)Nr�)
rTrUZgetMathPostscriptsr$rurrqror<r!r:rnrA)rr*r/r=Zpostscriptsr�rrvr
r
r�_generateScriptPostscripts�	s
z*SpeechGenerator._generateScriptPostscriptsc	Kshy|j�}Wn
gS|jjj|�}|dkrBtj|j|j�g}ntj|j|j�g}|j	|j
t��|S)Nr)r�rTrU�getMathNestingLevelrZmathNestedTableSizer�r�Z
mathTableSizer<r!r:)rr*r/r�r#r=r
r
r�_generateMathTableStart�	sz'SpeechGenerator._generateMathTableStartcKsLg}xB|D]:}|j|�}|j||�|j|j||d��|j||�q
W|S)N)r1)rr�r<r.r�)rr*r/r=r�r�r
r
r�_generateMathTableRows�	s

z&SpeechGenerator._generateMathTableRowscKsvg}|jtj|j�d�|j|jt��|j|j|f|��x0|D](}|j|j|��|j|j|f|��qFW|S)Nr)	rArr�rr<r!r:ryrP)rr*r/r=r�r
r
r�_generateMathRow�	s
z SpeechGenerator._generateMathRowcKs<|jjj|�}|dkr tjg}ntjg}|j|jt��|S)Nr)	rTrUryrZMATH_NESTED_TABLE_ENDZMATH_TABLE_ENDr<r!r:)rr*r/r#r=r
r
r�_generateMathTableEnd�	s
z%SpeechGenerator._generateMathTableEndcKs tjd�s|jdd�rgStS)NZenablePauseBreaksZeliminatePausesF)r8r9r3�PAUSE)rr*r/r
r
rry�	szSpeechGenerator._generatePausecKstS)N)�
LINE_BREAK)rr*r/r
r
r�_generateLineBreak�	sz"SpeechGenerator._generateLineBreakNcKs�tj|�ptjt�}tjd�}tj|jtjt���}|dtgkrv|jdd�}t|t�r�|j	�r�|j
|jtjt���n$|j|�}|r�|jdd�r�|j
|�|gS)z�Returns an array containing a voice.  The key is a value
        to be used to look up the voice in the settings.py:voices
        dictionary. Other arguments can be passed in for future
        decision making.
        �voicesNr+reZestablishedT)�	voiceTyper3r)r8r9rZACSSr#r$r%�updater()rr�r/Z	voicenamer�r!r+�overrider
r
rr!�	s


zSpeechGenerator.voice)N)zrrrrrr,r-r0r;r>rCrErIrJrKrNrOrPrQrRrXr\r[rgrhrcrorqrrrsrtrurvrwr|rxrzr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr
rrWrr&r,r.r/r2r3r6r7r:r;r<r9r=r>rArBrCrErJrKrNrPrQrXr\r]r^r_rarcrdrerirkrlrmrnrprrrsrtrwrxrzr{r|r}ryr�r!�
__classcell__r
r
)rnrrTs�	!



27$&

' 1,.')s]/"
'!
#6		

r))rZ__id__�__version__Z__date__Z
__copyright__Z__license__rZurllib.parser�Zurllib.requestZurllib.errorrerrrrrrr	r
rrr~rrZ
METHOD_PREFIXr)r(r"r:rpZVALUEZ
DEFAULT_VOICEZUPPERCASE_VOICEZHYPERLINK_VOICEZSYSTEM_VOICEr�Z
getManagerr8rrr
r
r
r�<module>sF