Mini Shell

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

3

�p5[C��@s�dZdZdZdZdZdZddlZddlZddlZddl	Z	ddl
Z
ddlmZm
Z
d	d
lmZd	dlmZd	dlmZd	d
lmZd	dlmZd	dlmZddd�ZdZej�ZGdd�d�ZdS)zASuperclass of classes used to generate presentations for objects.z$Id:$z$Revision:$z$Date:$zLCopyright (c) 2009 Sun Microsystems Inc.Copyright (c) 2015-2016 Igalia, S.L.ZLGPL�N)�Atspi�Atk�)�braille)�debug)�messages)�object_properties)�settings)�settings_manager�cCsNtj�\}}}|j}y
|j}Wntk
r6d}YnXtj||�}|||fS)Nz	<no args>)�sys�exc_info�__name__�args�KeyError�	traceback�	format_tb)Z
maxTBlevelZcla�excZtrbkZexcNameZexcArgsZexcTb�r�/usr/lib/python3.6/generator.py�_formatExceptionInfo,s

rZ	_generatec@s*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+�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(dLdM�Z)dNdO�Z*dPdQ�Z+dRdS�Z,dTdU�Z-dVdW�Z.dXdY�Z/dZd[�Z0d\d]�Z1d^d_�Z2d`da�Z3dbdc�Z4ddde�Z5dfdg�Z6dhdi�Z7djdk�Z8dldm�Z9dndo�Z:dpdq�Z;drds�Z<dtdu�Z=dvdw�Z>dxdy�Z?dzd{�Z@d|d}�ZAd�dd��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd~S)��	Generatorz�Takes accessible objects and generates a presentation for those
    objects.  See the generate method, which is the primary entry
    point.cs�|�_|�_i�_i�_xfdd��fdd�dd�t��D�D�D�D]8}|jtt�d�}|dj�|dd�}|�j|<qDW�j	�dS)NcSsg|]}t|tj�r|�qSr)�
isinstance�collections�Callable)�.0�zrrr�
<listcomp>Qsz&Generator.__init__.<locals>.<listcomp>cs g|]}t�|�j��j��qSr)�getattr�__get__�	__class__)r�y)�selfrrrQscSsg|]}|jt�r|�qSr)�
startswith�
METHOD_PREFIX)r�xrrrrQsrr)
�_mode�_script�_activeProgressBars�_methodsDict�dirr�lenr$�lower�_verifyFormatting)r"Zscript�mode�method�namer)r"r�__init__Hs.zGenerator.__init__cCsd|d<d|d<t|d<dS)zCOther things to make available from the formatting string.
        N�obj�role�pyatspi)r4)r"�globalsDictrrr�_addGlobalsWszGenerator._addGlobalscCsi}x|jj�D]}g||<qW|j|�x�|jj|jD]�}x�dD]�}y|jj|j||}WnwDYqDX|sxqDx�yt||�PWqztk
r�t�}|dd}|j	dd�}|j	dd�}||jkr�t
jt
j�g||<Yqzt
jt
j�PYqzXqzWqDWq:WdS)	N�focused�	unfocusedrrzname '�z' is not defined)r7r8)
r)�keysr6r'�
formattingr&�eval�	NameErrorr�replacer�printException�LEVEL_SEVERE)r"r5�keyZroleKeyZ
evalString�info�argrrrr-^s6	



zGenerator._verifyFormattingcCs|jdd�}||d<|S)z�Convenience method to allow you to temporarily override the role in
        the args dictionary.  This changes the role in args ags
        returns the old role so you can pass it back to _restoreRole.
        r3N)�get)r"ZnewRoler�oldRolerrr�
_overrideRole�szGenerator._overrideRolecCs|r||d<n|d=dS)z�Convenience method to restore the old role back in the args
        dictionary.  The oldRole should have been obtained from
        _overrideRole.  If oldRole is None, then the 'role' key/value
        pair will be deleted from args.
        r3Nr)r"rErrrr�_restoreRole�s
zGenerator._restoreRolecKsgS)Nr)r"�contentsrrrr�generateContents�szGenerator.generateContentscKsgS)Nr)r"r2rrrr�generateContext�szGenerator.generateContextcKs�|jjj|�r&d}tjtj|d�gStj�}g}i}|j|�||d<y|jd|j	��|d<Wn"d|}tjtj|d�|S�y�|d|d<|j
|d<|jdd�s�|jd	d
�r�d|d<nd|d<|jjjf|�}|jd
d
��s0|jdd��r"|jjj
f|�}|jjjf|�}	d|||	f}d|d
<d}
nd
}
d|j
j�|f}tjtj|d�x�tj�}yt||�}PWn�tk
�rg}t�}|dd}
|
jdd�}
|
jdd�}
|
|jk�r�tjtj�P|j|
|f|�||
<dtj�|}tjtjd||
t||
�f�YnX�qXWWntjtj�g}YnXdtj�|}tjtjd|�tjtjd|j
j�d�x |D]}tjtjd|��q~W|jd��r�|�r�|j|�|S)a4Returns an array of strings (and possibly voice and audio
        specifications) that represent the complete presentation for the
        object.  The presentation to be generated depends highly upon the
        formatting strings in formatting.py.

        args is a dictionary that may contain any of the following:
        - alreadyFocused: if True, we're getting an object
          that previously had focus
        - priorObj: if set, represents the object that had focus before
          this object
        - includeContext: boolean (default=True) which says whether
          the context for an object should be included as a prefix
          and suffix
        - role: a role to override the object's role
        - formatType: the type of formatting, such as
          'focused', 'basicWhereAmI', etc.
        - forceMnemonic: boolean (default=False) which says if we
          should ignore the settings.enableMnemonicSpeaking setting
        - forceTutorial: boolean (default=False) which says if we
          should force a tutorial to be spoken or not
        z,ERROR: Cannot generate presentation dead objTr2r3z5ERROR: Cannot generate presentation for: %s. Abortingr.�
formatTypeN�alreadyFocusedFr7r8Z	recursing�includeContextz%s + %s + %sz(%s GENERATOR: Starting generation for %srrzname 'r9z' is not definedz%.4fz,           GENERATION TIME: %s  ---->  %s=%sz           COMPLETION TIME: %sz%s GENERATOR: Results:z
           %sZisProgressBarUpdate)r'�	utilities�isDeadrZprintlnZ
LEVEL_INFO�timer6rD�getRoler&r;Z	getFormatZ	getPrefixZ	getSuffix�upperr<r=rr>r)r?r@Z	LEVEL_ALL�repr� setProgressBarUpdateTimeAndValue)r"r2r�msgZ	startTime�resultr5r;�prefix�suffixZfirstTimeCalledZcurrentTimerBrCZduration�elementrrr�generate�s~
	


&


zGenerator.generatecKsgS)aReturns the role name for the object in an array of strings, 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.
        r)r"r2rrrr�_generateRoleNameszGenerator._generateRoleNamecKs�g}d|jjd<|jjj|�}|j�tjkr�|jjj|�}|rX|jrX|jjj|d�}|phdd�|D�}t	|jjj|�}t
tdd�|��}t|�dkr�|dj
�}n8t|�dkr�|djr�|djj
�}n|r�|jr�|j}|r�|j|�n�y
|j}Wnttfk
�r|SX|�r2|j|�d	|jjd<n^d
}|j�tjk�rL|}n |j�rl|jj�tjk�rl|j}|�r�|jjj|�}	|	�r�|j|	�y|jd|j��}
Wnttfk
�r�|SX|�r�|j�tjk�r�|jj�tjk�r�|j|j�S|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.
        F�usedDescriptionForNamercSsg|]}|�qSrr)r�childrrrr7sz+Generator._generateName.<locals>.<listcomp>cSs|S)Nr)r%rrr�<lambda>9sz)Generator._generateName.<locals>.<lambda>rTNr3)r'�pointOfReferencerN�
displayedTextrQr4�ROLE_COMBO_BOXZselectedChildren�
childCount�map�list�filterr+�stripr0�append�description�LookupError�RuntimeErrorZ	ROLE_LINK�parentZlinkBasenamerD�	ROLE_ICON�
ROLE_PANEL�
_generateName)r"r2rrVr0Zchildren�namesrh�link�basenamer3rrrrn"sT


zGenerator._generateNamecKs dd�|j�D�}dd�|D�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.
        cSsg|]}|jd�r|�qS)zplaceholder-text:)r#)rr%rrrrgsz6Generator._generatePlaceholderText.<locals>.<listcomp>cSsg|]}|jdd��qS)zplaceholder-text:r9)r>)rr%rrrrhs)Z
getAttributes)r"r2rrVrrr�_generatePlaceholderText_sz"Generator._generatePlaceholderTextcKslg}|j|f|�}|j|f|�}|j|�t|�s>|j|�n*t|�rh|dj�|dj�krh|j|�|S)z�Returns the label and the name as an array of strings for speech
        and braille.  The name will only be present if the name is
        different from the label.
        r)�_generateLabelrn�extendr+�split)r"r2rrV�labelr0rrr�_generateLabelAndNamejs
 
zGenerator._generateLabelAndNamecKs<g}|j|j|f|��|s8|jr8t|j�r8|j|j�|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.
        )rtrsr0r+rg)r"r2rrVrrr�_generateLabelOrNameyszGenerator._generateLabelOrNamecKs�|jjjd�rgS|jd|j��}|tjkr0gS|tjkrN|jjj|�pJd}n
|j	pVd}g}|j
r�|jjj|�prd}|j
j�}||j�kp�||j�ks�|j
|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.
        r\r3r9)r'r_rDrQr4Z
ROLE_LABELrlrNr`r0rh�displayedLabelr,rg)r"r2rr3r0rVrvZdescrrr�_generateDescription�s



zGenerator._generateDescriptioncKs$g}|jjj|�}|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'rNryrg)r"r2rrVrvrrrrs�s

zGenerator._generateLabelcKsFg}y|j�}Wntk
r$YnX|j}|rBt|�rB|j|�|S)z�Returns an array of strings for use by speech and braille that
        represent the description of the image on the object, if it
        exists.  Otherwise, an empty array is returned.
        )Z
queryImage�NotImplementedErrorZimageDescriptionr+rg)r"r2rrVZimagerhrrr�_generateImageDescription�s
z#Generator._generateImageDescriptioncKsgS)Nr)r"r2rrrr�_generateClickable�szGenerator._generateClickablecKsgS)Nr)r"r2rrrr�_generateHasLongDesc�szGenerator._generateHasLongDesccKsLg}|jdd�s|j|d<d|d<|j�jtj�sH|j|jjj	f|��|S)aReturns an array of strings for use by speech and braille that
        represent the grayed/sensitivity/availability state of the
        object, but only if it is insensitive (i.e., grayed out and
        inactive).  Otherwise, and empty array will be returned.
        r.NZinsensitive�
stringType)
rDr&�getState�containsr4ZSTATE_SENSITIVErgr'r;�	getString)r"r2rrVrrr�_generateAvailability�s
zGenerator._generateAvailabilitycKs�|jjj|�}|sgSg}|jdd�s0|j|d<d|d<|jjjf|�}|dkrZ|d}n|dkrl|d}n|d}|jjj|�}|r�|jd	||f�n
|j|�|S)
Nr.ZinvalidrZspellingrZgrammar�rz%s: %s)	r'rNZgetErrorrDr&r;r�ZgetErrorMessagerg)r"r2r�errorrV�
indicatorsZ	indicatorZerrorMessagerrr�_generateInvalid�s$



zGenerator._generateInvalidcKslg}|jdd�s|j|d<d|d<|j�jtj�sR|j�tjkrh|jj�jtj�rh|j	|j
jjf|��|S)a*Returns an array of strings for use by speech and braille that
        represent the required state of the object, but only if it is
        required (i.e., it is in a dialog requesting input and the
        user must give it a value).  Otherwise, and empty array will
        be returned.
        r.NZrequiredr)
rDr&r�r�r4ZSTATE_REQUIREDrQ�ROLE_RADIO_BUTTONrkrgr'r;r�)r"r2rrVrrr�_generateRequired�s
zGenerator._generateRequiredcKsJg}|jdd�s|j|d<d|d<|jjj|�rF|j|jjjf|��|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.N�readonlyr)rDr&r'rNZisReadOnlyTextAreargr;r�)r"r2rrVrrr�_generateReadOnly
s
zGenerator._generateReadOnlycKsDg}|jjj|�r@|jtj|�}|j|j|f|��|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 that are in a table. An empty array will be
        returned if this is not a checkable cell.
        )	r'rN�hasMeaningfulToggleActionrFr4�ROLE_CHECK_BOXrtrZrG)r"r2rrVrErrr�_generateCellCheckedStatesz#Generator._generateCellCheckedStatecKs�g}|jdd�s|j|d<d|d<|jjjf|�}|j�}|jtj�rV|j	|d�n*|jtj
�rr|j	|d�n|j	|d�|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?]]]
        r.N�checkboxrrr�r)rDr&r'r;r�r�r�r4�
STATE_CHECKEDrgZSTATE_INDETERMINATE)r"r2rrVr��staterrr�_generateCheckedState%s
zGenerator._generateCheckedStatecKshg}|jdd�s|j|d<d|d<|jjjf|�}|j�}|jtj�rV|j	|d�n|j	|d�|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?]]]
        r.NZradiobuttonrrr)
rDr&r'r;r�r�r�r4r�rg)r"r2rrVr�r�rrr�_generateRadioState9s
zGenerator._generateRadioStatecs`tjtjtjtjtjtjg��fdd�}|jr\|jj�tj	kr\tj
||�}|r\|j|dd�SgS)Ncs|o|j��kS)N)rQ)r%)�widgetRolesrrr^Rsz0Generator._generateChildWidget.<locals>.<lambda>F)rM)r4r�raZROLE_PUSH_BUTTONr��ROLE_SLIDER�ROLE_TOGGLE_BUTTONrkrQZ
ROLE_LIST_BOXZfindDescendantrZ)r"r2rZisWidgetZwidgetr)r�r�_generateChildWidgetKszGenerator._generateChildWidgetcKstg}|jdd�s|j|d<d|d<|jjjf|�}|j�}|jtj�sR|jtj	�rb|j
|d�n|j
|d�|S)Nr.Zswitchrrr)rDr&r'r;r�r�r�r4r��
STATE_PRESSEDrg)r"r2rrVr�r�rrr�_generateSwitchState\s
zGenerator._generateSwitchStatecKstg}|jdd�s|j|d<d|d<|jjjf|�}|j�}|jtj�sR|jtj	�rb|j
|d�n|j
|d�|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?]]]
        r.NZtogglebuttonrrr)rDr&r'r;r�r�r�r4r�r�rg)r"r2rrVr�r�rrr�_generateToggleStatejs
zGenerator._generateToggleStatecKsTg}|jdd�s|j|d<d|d<|jjjf|�}|j�jtj�rP|j	|d�|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.
        r.Nr�rr)
rDr&r'r;r�r�r�r4r�rg)r"r2rrVr�rrr�_generateMenuItemCheckedState}s
z'Generator._generateMenuItemCheckedStatecKstg}|jdd�s|j|d<d|d<|jjjf|�}|j�}|jtj�rp|jtj	�rb|j
|d�n|j
|d�|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.
        r.NZ	expansionrrr)rDr&r'r;r�r�r�r4ZSTATE_EXPANDABLEZSTATE_EXPANDEDrg)r"r2rrVr�r�rrr�_generateExpandableState�s
z"Generator._generateExpandableStatecKsRg}|jdd�s|j|d<d|d<|j�jtj�rN|jrN|j|jj	j
f|��|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.
        r.NZmultiselectr)rDr&r�r�r4ZSTATE_MULTISELECTABLErbrgr'r;r�)r"r2rrVrrr�_generateMultiselectableState�s
z'Generator._generateMultiselectableStatecKs�g}|jjj|�}|s|S|jjj|�}|s0|S|j|tjd�}|jd�dkrvtj	tj
kr�|jd�d	kr�d||f}n|jd�dkr�d||f}|j|�|S)
z�Returns an array of strings to be used in speech and braille that
        represent the row header for an object that is in a table, if
        it exists.  Otherwise, an empty array is returned.
        )r3r.�speechrK�
basicWhereAmI�detailedWhereAmIz%s %sr)r�r�)r'rNZrowHeaderForCellr`�getLocalizedRoleNamer4ZROLE_ROW_HEADERrDr	�speechVerbosityLevel�VERBOSITY_LEVEL_VERBOSErg)r"r2rrV�header�text�
roleStringrrr�_generateRowHeader�s 
zGenerator._generateRowHeadercKs�g}|jjj|�}|s|S|jjj|�}|s0|S|j|tjd�}|jd�dkrvtj	tj
kr�|jd�d	kr�d||f}n|jd�dkr�d||f}|j|�|S)
z�Returns 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.  Otherwise, an empty array
        is returned.
        )r3r.r�rKr�r�z%s %sr)r�r�)r'rN�columnHeaderForCellr`r�r4ZROLE_COLUMN_HEADERrDr	r�r�rg)r"r2rrVr�r�r�rrr�_generateColumnHeader�s 
zGenerator._generateColumnHeadercKs�g}|jdkr�g}ddg}x,t|�D] \}}|jjj|�r$d||<Pq$W|drd|drdddg}n|dr~|dr~ddg}|r�x,|D]$}||s�|j|j||f|��q�W|S)z�Returns an array of strings for use by speech and braille for the
        label of a toggle in a table cell that has a special 2 child
        pattern that we run into.  Otherwise, an empty array is
        returned.
        r�FTrr)rb�	enumerater'rNr�rtrZ)r"r2rrV�	cellOrder�	hasToggle�ir]rrr�_generateTableCell2ChildLabel�s"	


z'Generator._generateTableCell2ChildLabelcKs�g}|jdkr�g}ddg}x,t|�D] \}}|jjj|�r$d||<Pq$W|drd|drdddg}n|dr~|dr~ddg}|r�x,|D]$}||r�|j|j||f|��q�W|S)z�Returns an array of strings for use by speech and braille for the
        toggle value of a toggle in a table cell that has a special 2
        child pattern that we run into.  Otherwise, an empty array is
        returned.
        r�FTrr)rbr�r'rNr�rtrZ)r"r2rrVr�r�r�r]rrr�_generateTableCell2ChildToggles"	


z(Generator._generateTableCell2ChildTogglecKsp|ddkr|jdd�rgSg}|jjj|�}|jjj|�}|rl|jjj|�rl|jjj|�}|j|j�|S)z�If this table cell has a "toggle" action, and doesn't have any
        label associated with it then also speak the table column
        header.  See Orca bug #455230 for more details.
        r.r��
readingRowF)	rDr'rN�realActiveDescendantr`r�r�rgr0)r"r2rrVZ
descendantrvZ	accHeaderrrr�&_generateColumnHeaderIfToggleAndNoText'sz0Generator._generateColumnHeaderIfToggleAndNoTextcKs4g}|jd|�}|j|j|f|��|j||�|S)a`Orca 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 for use by speech and braille for a single
        table cell itself.  The string, 'blank', is added for empty
        cells.
        ZREAL_ROLE_TABLE_CELL)rFrtrZrG)r"r2rrVrErrr�_generateRealTableCell:s
z Generator._generateRealTableCellc	Ks<|jjj|�rgSy|j�}Wn
gStj|j|j�gS)zaReturns an array of strings for use by speech and braille to present
        the size of a table.)r'rN�isLayoutOnly�
queryTablerZ	tableSize�nRows�nColumns)r"r2r�tablerrr�_generateTableHszGenerator._generateTablec
s�g}y|jj��Wnd�YnX|jdd�dk}|jjj|�}|sJ|o^�o^|jjj|j��r�|j}|jjj|�}�j|���j	|�}d}	|r��j
dkr�|SnXd|jjkr�d|jjkr�|jj}
|jdkp�|
d�kp��d	ks��j
dko�|
d|k}	|	�r�d|d
<|jjj|��r(dd�|D�}n��fd
d�t�j
�D�}x�|D]l}|�sV�qH|j�}
|
jtj�}|�rH|j|f|�}|�r�|�r�|jdk�r�|jtjtj��|j|��qHWn|j|j|f|��n|j|j|f|��|S)a�Orca 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 an entire row
        in a table if that's what the user has requested and if the row
        has changed.  Otherwise, it will return an array for just the
        current cell.
        NrKr�TrZlastRowZ
lastColumnrrr�cSsg|]}|�qSrr)rr%rrrr�sz3Generator._generateTableCellRow.<locals>.<listcomp>csg|]}�j�|��qSr)ZgetAccessibleAt)rr�)�parentTable�rowrrr�s)rkr�rDr'rNZshouldReadFullRowr�Z	cellIndexZ
getRowAtIndexZgetColumnAtIndexr�r_r&r�Z
isTableRow�ranger�r�r4Z
STATE_SHOWINGr�rgrZRegionrZTABLE_CELL_DELIMITER_BRAILLErt)r"r2rrVZisDetailedWhereAmIZreadFullRowrk�index�columnZ
presentAllr_ZcellsZcellr�ZshowingZ
cellResultr)r�r�r�_generateTableCellRowVsX	






zGenerator._generateTableCellRowcKsgS)z>Returns the expanded embedded object characters for an object.r)r"r2rrrr�_generateExpandedEOCs�szGenerator._generateExpandedEOCscKs\|jd�}|jd�}|dks$|dkr(gS|jd|jjj|||��}|rX|jj|krX|gSgS)N�startOffset�	endOffset�string)rDr'rN�	substring�EMBEDDED_OBJECT_CHARACTER)r"r2r�start�endr�rrr�_generateSubstring�s

zGenerator._generateSubstringcKs
|jd�S)Nr�)rD)r"r2rrrr�_generateStartOffset�szGenerator._generateStartOffsetcKs
|jd�S)Nr�)rD)r"r2rrrr�_generateEndOffset�szGenerator._generateEndOffsetcKsB|j|f|�}|r|S|jj|�\}}}|r>|jj|kr>|gSgS)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'ZgetTextLineAtCaretr�)r"r2rrVr�ZcaretOffsetr�rrr�_generateCurrentLineText�sz"Generator._generateCurrentLineTextcKs2|j|f|�}|r|S|jjj|�}|s,gS|gS)z�Returns an array of strings for use by speech and braille that
        represents all the text being displayed by the object.
        )r�r'rNr`)r"r2rrVr`rrr�_generateDisplayedText�sz Generator._generateDisplayedTextcKsZg}|jdd�s|j|d<d|d<|jjj|�}|dkrV|j|jjjf|�|d�|S)z�Returns an array of strings for use by speech and braille that
        represents the tree node level of the object, or an empty
        array if the object is not a tree node.
        r.NZ	nodelevelrrr)rDr&r'rNZ	nodeLevelrgr;r�)r"r2rrV�levelrrr�_generateNodeLevel�s
zGenerator._generateNodeLevelcKs|jjj|�gS)aMReturns an array of strings for use by speech and braille that
        represents the value of the object.  This is typically the
        numerical value, but may also be the text of the 'value'
        attribute if it exists on the object.  [[[WDW - we should
        consider returning an empty array if there is no value.
        )r'rNZtextForValue)r"r2rrrr�_generateValue�szGenerator._generateValuec	Ks*g}y|j|j�j�WnYnX|S)z�Returns an array of strings for use by speech and braille that
        represents the name of the application for the object.
        )rgZgetApplicationr0)r"r2rrVrrr�_generateApplicationName�sz"Generator._generateApplicationNamecKsz|jd�}|jd�}|dk	r(|dk	r(gSg}|jdd�sB|j|d<d|d<|jjj|�}|rv|j|jjjf|�|�|S)z�Returns an array of strings for use by speech and braille that
        represent the nesting level of an object in a list.
        r�r�Nr.Znestinglevelr)rDr&r'rN�nestingLevelrgr;r�)r"r2rr�r�rVr�rrr�_generateNestingLevels


zGenerator._generateNestingLevelc
	Ks�g}y|j�}Wnd}YnX|tjkr�d}|j�}x,|D]$}|r>|j�tjkr>|jd�}Pq>W|r�|j|jj	j
|��nN|j}xF|r�|j|kr�|j�tjtj
gkr�|j|�}	|	r�|j|	�P|j}q�W|S)z�Returns an array of strings for use by speech and braille that
        represents the radio button group label for the object, or an
        empty array if the object has no such label.
        Nr)rQr4r�ZgetRelationSetZgetRelationTypeZRELATION_LABELLED_BYZ	getTargetrgr'rNr`rkrmZROLE_FILLERrwrt)
r"r2rrVr3ZradioGroupLabelZ	relationsZrelationrkrvrrr�_generateRadioButtonGroups6









z#Generator._generateRadioButtonGroupcs\g}�jjj|�}|j�tjko$|js4�j|f|�S�fdd�|D�}djt	dd�|��gS)aNObjects, such as tables and trees, can represent individual cells
        via a complicated nested hierarchy.  This method returns an
        array of strings for use by speech and braille that represents
        the text actually being painted in the cell, if it can be
        found.  Otherwise, an empty array is returned.
        csg|]}�jjj|�j��qSr)r'rNr`rf)rr%)r"rrrJszHGenerator._generateRealActiveDescendantDisplayedText.<locals>.<listcomp>� cSs|S)Nr)r%rrrr^KszFGenerator._generateRealActiveDescendantDisplayedText.<locals>.<lambda>)
r'rNr�rQr4�ROLE_TABLE_CELLrbr��joinre)r"r2rrV�radZcontentr)r"r�*_generateRealActiveDescendantDisplayedText=sz4Generator._generateRealActiveDescendantDisplayedTextcKs(|jjj|�}|j�|d<|j|f|�S)aObjects, such as tables and trees, can represent individual cells
        via a complicated nested hierarchy.  This method returns an
        array of strings for use by speech and braille that represents
        the role of the object actually being painted in the cell.
        r3)r'rNr�rQr[)r"r2rr�rrr�%_generateRealActiveDescendantRoleNameMsz/Generator._generateRealActiveDescendantRoleNamecKsPg}|j}x@|rJ|j|krJ|j�tjkrB|j|�}|rB|j|�P|j}qW|S)z�Returns an array of strings for use by speech and braille that
        represents the nearest ancestor of an object which is a named panel.
        )rkrQr4rmrwrt)r"r2rrVrkrvrrr�_generateNamedContainingPanelWs


z'Generator._generateNamedContainingPanelcKsgS)Nr)r"r2rrrr�_generatePageSummaryfszGenerator._generatePageSummarycKsgS)Nr)r"r2rrrr�_generateProgressBarIndexisz#Generator._generateProgressBarIndexcKsgS)Nr)r"r2rrrr�_generateProgressBarValuelsz#Generator._generateProgressBarValuecCsttjd��S)NZprogressBarUpdateInterval)�int�_settingsManagerZ
getSetting)r"rrr�_getProgressBarUpdateIntervalosz'Generator._getProgressBarUpdateIntervalcKsT|jjj|�}|j||d�\}}||kr,dS|dkr8dSttj�|�}||j�kS)N)�typeF�dT)r'rN�getValueAsPercent� getProgressBarUpdateTimeAndValuer�rPr�)r"r2rZpercent�lastTime�	lastValueZintervalrrr�_shouldPresentProgressBarUpdatersz)Generator._shouldPresentProgressBarUpdatecs4�fdd�}tt|�j��}�fdd�|D��_dS)Ncs�jjj|�p�jjj|�S)N)r'rNZisZombierO)r%)r"rrr^sz6Generator._cleanUpCachedProgressBars.<locals>.<lambda>csi|]}�jj|�|�qSr)r(rD)rr%)r"rr�
<dictcomp>�sz8Generator._cleanUpCachedProgressBars.<locals>.<dictcomp>)rdrer()r"ZisValidZbarsr)r"r�_cleanUpCachedProgressBars~sz$Generator._cleanUpCachedProgressBarscCsP|j�|jj�sdSt|jj�dd�d�}|d\}}t|jj��d||fS)	N�cSs|dS)Nrr)r%rrrr^�sz;Generator._getMostRecentProgressBarUpdate.<locals>.<lambda>)rAr)Nr�N���r�)r�r(�values�sortedrdr:)r"ZsortedValuesZprevTimeZ	prevValuerrr�_getMostRecentProgressBarUpdate�s
z)Generator._getMostRecentProgressBarUpdatecCsL|j�||jkrd|j|<|j|�}t|jj��j|�}|dt|j�fS)N�r)r�N)r�r(r�rdr�r�r+)r"r2Z	thisValuer�rrr�getProgressBarNumberAndCount�s


z&Generator.getProgressBarNumberAndCountcKs ||jkrd|j|<|jj|�S)N�)r�N)r(rD)r"r2rrrrr��s

z*Generator.getProgressBarUpdateTimeAndValueNcCs0|p
tj�}|p|jjj|�}||f|j|<dS)N)rPr'rNr�r()r"r2r�r�rrrrT�sz*Generator.setProgressBarUpdateTimeAndValuecKsH|jjj|�r�|jjj|�r dS|jjj|�r2dS|jjj|�rDdS|jjj|�rVdS|jjj|�rhdS|jjj|�rzdS|jjj	|�r�dS|jjj
|�r�|jjj|�r�dS|jjj|�r�d	S|j
�tjkr�d
S|jjj|�r�dS|jjj|�r�tjS|jjj|��rtjS|jjj|��r"tjS|jjj|��r8tjS|jd|j
��S)
NZROLE_MATH_SCRIPT_SUBSUPERZROLE_MATH_SCRIPT_UNDEROVERZROLE_MATH_MULTISCRIPTZROLE_MATH_ENCLOSEDZROLE_MATH_FENCEDZROLE_MATH_TABLEZROLE_MATH_TABLE_ROW�
ROLE_FOOTNOTEZROLE_DPUB_LANDMARK�ROLE_DPUB_SECTION�ROLE_SWITCHr3)r'rNZisMathZisMathSubOrSuperScriptZisMathUnderOrOverScriptZisMathMultiScriptZ
isMathEncloseZisMathFencedZisMathTableZisMathTableRow�isDPub�isDPubFootnote�
isLandmarkrQr4ZROLE_SECTION�isSwitchZisAnchorZROLE_STATICZisBlockquoteZROLE_BLOCK_QUOTEZ
ROLE_LANDMARKZisFocusableLabel�ROLE_LIST_ITEMrD)r"r2rrrr�_getAlternativeRole�sBzGenerator._getAlternativeRolec
	Ksl|jd|j��}dtj|�kr�|j�}|jtj�}|jtj�}|jtj�pT|jdd�}|tj	krv|rjt
jS|r�t
jSnb|tj
kr�|r�t
jS|r�t
jSnB|tjkr�|r�t
jS|r�t
jSn"|tjkr�|r�|r�t
jS|r�t
jS|jjj|�r�t
jS|jjj|��rt
jS|jjj|��rt
jS|jjj|��r.t
jS|jjj|��rB|jjj|��r�|jjj |��rdt
j!S|jjj"|��rzt
j#S|jjj$|��r�t
j%S|jjj&|��r�t
j'S|jjj(|��r�t
j)S|jjj*|��r�t
j+S|jjj,|��r�t
j-S|jjj.|��r�t
j/S|jjj0|��rt
j1S|jjj2|��r*t
j3S|jjj4|��r@t
j5S|jjj6|��rVt
j7S|jjj8|��rlt
j9S|jjj:|��r�t
j;S|jjj<|��r�t
j=S|jjj>|��r�t
j?S|jjj@|��r�t
jAS|jjjB|��r�t
jCS|jjjD|��rBt
jES�nN|dk�r�|jjjF|��rt
jGS|jjjH|��r*t
jIS|jjjJ|��r@t
jKS|jjjL|��rVt
jMS|jjjN|��rlt
jOS|jjjP|��r�t
jQS|jjjR|��r�t
jSS|jjjT|��rBt
jUSn�|tjVk�r�|jjjW|��r�t
jXS|jjjY|��rBt
jZSnX|jjj[|��rt
j\S|jjj]|��rt
j^S|jjj_|��r,t
j`S|jjja|��rBt
jbS|jjj|��r|jjjc|��rht
jdS|jjje|��r~t
jfS|jjjg|��r�t
jhS|jjji|��r�t
jjS|jjjk|��r�t
jlS|jjjm|��r�t
jnS|jjjo|��r�t
jpS|jjjq|��rtjr}ts|tjttujtf��s*y|jv�SdStujw|�}txjy|�}	|	txjtjzk�rb|tj{k�rbtxjyd�}	txj||	�S)Nr3ZValuerLFr�r9Z	statusbar)}rDrQr4ZlistInterfacesr�r�ZSTATE_VERTICALZSTATE_HORIZONTALZ
STATE_FOCUSEDr�rZROLE_SLIDER_HORIZONTALZROLE_SLIDER_VERTICAL�ROLE_SCROLL_BARZROLE_SCROLL_BAR_HORIZONTALZROLE_SCROLL_BAR_VERTICALZROLE_SEPARATORZROLE_SPLITTER_HORIZONTALZROLE_SPLITTER_VERTICALZROLE_SPLIT_PANEr'rNZisFeedZ	ROLE_FEEDZisFigureZROLE_FIGUREZisMenuButtonZROLE_MENU_BUTTONr�r�r�r�ZisDPubAcknowledgmentsZROLE_ACKNOWLEDGMENTSZisDPubAfterwordZROLE_AFTERWORDZisDPubAppendixZ
ROLE_APPENDIXZisDPubBibliographyZROLE_BIBLIOGRAPHYZ
isDPubChapterZROLE_CHAPTERZisDPubConclusionZROLE_CONCLUSIONZ
isDPubCreditsZROLE_CREDITSZisDPubEndnotesZ
ROLE_ENDNOTESZisDPubEpilogueZ
ROLE_EPILOGUEZisDPubErrataZROLE_ERRATAZisDPubForewordZ
ROLE_FOREWORDZisDPubGlossaryZ
ROLE_GLOSSARYZisDPubIndexZ
ROLE_INDEXZisDPubIntroductionZROLE_INTRODUCTIONZisDPubPagelistZ
ROLE_PAGELISTZ
isDPubPartZ	ROLE_PARTZ
isDPubPrefaceZROLE_PREFACEZisDPubPrologueZ
ROLE_PROLOGUEZ	isDPubTocZROLE_TOCZisDPubAbstractZ
ROLE_ABSTRACTZisDPubColophonZ
ROLE_COLOPHONZisDPubCreditZROLE_CREDITZisDPubDedicationZROLE_DEDICATIONZisDPubEpigraphZ
ROLE_EPIGRAPHZ
isDPubExampleZROLE_EXAMPLEZisDPubPullquoteZROLE_PULLQUOTEZ	isDPubQnaZROLE_QNAr�ZisDPubBiblioentryZROLE_BIBLIOENTRYZ
isDPubEndnoteZROLE_ENDNOTEZisDPubCoverZ
ROLE_COVERr�r�ZisDPubPagebreakZROLE_PAGEBREAKZisDPubSubtitleZ
ROLE_SUBTITLEZisLandmarkBannerZROLE_LANDMARK_BANNERZisLandmarkComplementaryZROLE_LANDMARK_COMPLEMENTARYZisLandmarkContentInfoZROLE_LANDMARK_CONTENTINFOZisLandmarkMainZROLE_LANDMARK_MAINZisLandmarkNavigationZROLE_LANDMARK_NAVIGATIONZisLandmarkRegionZROLE_LANDMARK_REGIONZisLandmarkSearchZROLE_LANDMARK_SEARCHZisLandmarkFormZ	ROLE_FORMrZRolerr�Z
role_get_namerZ
role_for_nameZINVALIDZROLE_STATUS_BARZrole_get_localized_name)
r"r2rr3r�Z
isVerticalZisHorizontalZ	isFocusedZnonlocalizedZatkRolerrrr��s







zGenerator.getLocalizedRoleNamecKs�|jjj|�r|j|f|�S|jd|j��}|tjkrD|j|f|�S|tj	tj
gkrb|j|f|�S|tjtj
gkr�|j|f|�S|tjkr�|j|f|�S|tjkr�|j|f|�SgS)Nr3)r'rNr�r�rDrQr4ZROLE_MENU_ITEMr�r�ZROLE_RADIO_MENU_ITEMr�r�ZROLE_CHECK_MENU_ITEMr�r�r�r�r�)r"r2rr3rrr�getStateIndicatorWs


zGenerator.getStateIndicatorcKsJ|jd|j��}|tjkr(|j|f|�S|tjtjgkrF|j|f|�SgS)Nr3)rDrQr4ZROLE_PROGRESS_BARr�r�r�Z_generatePercentage)r"r2rr3rrr�getValuens
zGenerator.getValue)NN)Gr�
__module__�__qualname__�__doc__r1r6r-rFrGrIrJrZr[rnrrrwrxrzrsr|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�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rTr�r�r�r�rrrrrAs�*	w	=
  I"
		
$r)r)rZ__id__�__version__Z__date__Z
__copyright__Z__license__rr4rrPrZ
gi.repositoryrrr9rrrrr	r
rr$Z
getManagerr�rrrrr�<module>s*