Mini Shell

Direktori : /proc/self/root/lib/python3.6/site-packages/orca/__pycache__/
Upload File :
Current File : //proc/self/root/lib/python3.6/site-packages/orca/__pycache__/braille_generator.cpython-36.pyc

3

�2[5Q�@s�dZdZdZdZdZdZddlZdd	lmZdd
lm	Z	ddlm
Z
ddlmZdd
lmZddlm
Z
ddlmZddlmZddlmZej�ZGdd�d�Ze�gZGdd�de
j�ZdS)z:Utilities for obtaining braille presentations for objects.z$Id$z
$Revision$z$Date$z-Copyright (c) 2005-2009 Sun Microsystems Inc.ZLGPL�N�)�braille)�debug)�	generator)�messages)�object_properties)�
orca_state)�settings)�settings_manager)�shortRoleNamesc@seZdZdZddd�ZdS)�SpacezxA dummy class to indicate we want to insert a space into an
    utterance, but only if there is text prior to the space.� cCs
||_dS)N)�	delimiter)�selfr�r�'/usr/lib/python3.6/braille_generator.py�__init__-szSpace.__init__N)r
)�__name__�
__module__�__qualname__�__doc__rrrrrr*srcs�eZdZdZejejejejfZ	dd�Z
dd�Zdd�Zdd	�Z
�fd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z�fdd�Z�fd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd/d+d,�Zd0d-d.�Z�Z S)1�BrailleGeneratoraTakes accessible objects and produces a list of braille Regions
    for those objects.  See the generateBraille method, which is the
    primary entry point.  Subclasses can feel free to override/extend
    the brailleGenerators instance field as they see fit.cCstjj||d�dS)Nr)r�	Generatorr)rZscriptrrrr=szBrailleGenerator.__init__cCsNtjj||�|j|d<tj|d<tj|d<tj|d<tj|d<|j	|d<dS)zCOther things to make available from the formatting string.
        �space�	Component�Region�Text�Link�asStringN)
rr�_addGlobalsrrrrrrr)rZglobalsDictrrrr@s




zBrailleGenerator._addGlobalscKs$tjd�r.tjd�r.tjtjd�gdgS|tjkrN|jdd�rNd|d<|j|f|�}y|d}Wnd}YnXx�|D]�}y|j	�}Wnd}YnXt
|tjtj
f�r�|j|kr�|}Pq�t
|tj
�r�|tjkr�|jj|kr�|}Pq�t
|tj�r�|tjkr�|jj|kr�|}Pq�W||gS)NZ
enableBrailleZenableBrailleMonitorzBRAILLE: generation disabledZ
formatTypeZfocusedr)�_settingsManager�
getSettingrZprintlnZ
LEVEL_INFOrZlocusOfFocus�get�generate�getRole�
isinstancerrrZ
accessible�pyatspi�ROLE_COMBO_BOX�parentZROLE_TABLE_CELL)r�obj�args�resultZ
focusedRegionZregion�rolerrr�generateBrailleKs@






z BrailleGenerator.generateBraillecKs�|jd�rtjd�rgSg}|jd|j��}tjd�}tjtjtjtjg}|j	rp|j	j�tj
krp|j|j��|tj
kr�|jtjtjg�|tjkr�|jjj|�}|jtj|�n4|tjkr�|jdd�r�||kr�|j|j|f|��|S)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.
        �isProgressBarUpdate�brailleProgressBarUpdatesr,�brailleVerbosityLevelZ
readingRowF)r"r r!r$r&ZROLE_UNKNOWN�ROLE_FILLERZ
ROLE_EXTENDEDZ	ROLE_LINKr(�
ROLE_LIST_BOX�appendr	�VERBOSITY_LEVEL_BRIEF�extendZ	ROLE_ICONZROLE_CANVASZROLE_HEADING�_script�	utilitiesZheadingLevelrZROLE_HEADING_LEVEL_BRAILLEZVERBOSITY_LEVEL_VERBOSE�getLocalizedRoleName)rr)r*r+r,�verbosityLevelZdoNotPresent�levelrrr�_generateRoleNames*




z"BrailleGenerator._generateRoleNamecsBtjd�tjkr2|jd|j��}tj|�}|r2|St�j|f|�S)z�Returns the localized name of the given Accessible object; the name
        is suitable to be brailled.

        Arguments:
        - obj: an Accessible object
        ZbrailleRolenameStyler,)	r r!r	ZBRAILLE_ROLENAME_STYLE_SHORTr"r$r�superr8)rr)r*r,�rv)�	__class__rrr8�s
z%BrailleGenerator.getLocalizedRoleNamecKs<g}|jjj|�}x$|D]}|j|f|�}|j|�qW|S)N)r6r7ZunrelatedLabels�
_generateNamer5)rr)r*r+Zlabels�label�namerrr�_generateUnrelatedLabels�s
z)BrailleGenerator._generateUnrelatedLabelscKsJtjd�}|tjkrgSg}|jjj|�\}}}|rF|jd|d�|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.
        r0�(�))r r!r	r4r6r7ZmnemonicShortcutAcceleratorr3)rr)r*r9r+ZmnemonicZshortcutZacceleratorrrr�_generateAccelerator�s

z%BrailleGenerator._generateAcceleratorc	KsDg}y|jjj|�}Wnd}YnX|dkr@|jtj|��|S)z�Returns an array of strings that says how many alerts and dialogs
        are associated with the application for this object.  [[[WDW -
        I wonder if this string should be moved to settings.py.]]]
        r)r6r7ZunfocusedAlertAndDialogCountr3rZdialogCountBraille)rr)r*r+ZalertAndDialogCountrrr�_generateAlertAndDialogCount�s
z-BrailleGenerator._generateAlertAndDialogCountc		Ks�g}tjd�s|Sd|d<|jd|j��}|tjk}|j}|rR|j�|jkrR|j}�x$|ob|j|k�rxg}y|j�}Wnd}YnX|r�|tjkr�|tj	kr�|tj
kr�|tjkr�|jj
j|�r�||d<|j|f|�}|tjtjgk�r<|jj
j|�}|�r<t|��r<|j��r<|�s8|j�|d<|j|f|�}nd}|�rX|�rX|jtjd��|j|�|tjk�rpP|j}qVW|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.
        �enableBrailleContextF�includeContextr,Nr
)r r!r"r$r&�ROLE_RADIO_BUTTONr(�SKIP_CONTEXT_ROLESr1ZROLE_SECTIONZROLE_SPLIT_PANEZROLE_DESKTOP_FRAMEr6r7ZisLayoutOnlyr#Z
ROLE_PANELZdisplayedLabel�len�isspacer3rrr5Z
ROLE_EMBEDDED�reverse)	rr)r*r+r,ZexcludeRadioButtonGroupr(ZparentResultr@rrr�_generateAncestors�sJ
	




	

z#BrailleGenerator._generateAncestorscKs�g}|jd|j��}|tjtjgkr(|Sdtj|�krF|jjj|�}n|jjj	|�g}|o`|dsf|Sxt
|j|�D]}|j|�qtW|S)Nr,Z	Selectionr)
r"r$r&Z	ROLE_LISTr2ZlistInterfacesr6r7ZselectedChildrenZfocusedChild�mapr?r5)rr)r*r+r,�items�itemrrr�_generateFocusedItem3sz%BrailleGenerator._generateFocusedItemcs�tjtjtjtjtjtjg��fdd�}g}|jr�|jj�tj	kr�tj
||�}x0|D](}|j|j|dd��|j
tjd��qTW|S)Ncs|o|j��kS)N)r$)�x)�widgetRolesrr�<lambda>Lsz>BrailleGenerator._generateListBoxItemWidgets.<locals>.<lambda>F)rHr
)r&ZROLE_CHECK_BOXr'ZROLE_PUSH_BUTTONrIZROLE_SLIDERZROLE_TOGGLE_BUTTONr(r$r2ZfindAllDescendantsr5r#r3rr)rr)r*ZisWidgetr+ZwidgetsZwidgetr)rTr�_generateListBoxItemWidgetsEs
z,BrailleGenerator._generateListBoxItemWidgetscKsR|jd�s|j|f|�r gS|j�\}}}||krN|j|�\}}d|gSgS)Nr.z%s)r"�_shouldPresentProgressBarUpdateZ_getMostRecentProgressBarUpdateZgetProgressBarNumberAndCount)rr)r*ZaccZ
updateTimeZupdateValueZnumber�countrrr�_generateProgressBarIndexVs
z*BrailleGenerator._generateProgressBarIndexcKs,|jd�r|j|f|�rgS|j|f|�S)Nr.)r"rW�_generatePercentage)rr)r*rrr�_generateProgressBarValuebs
z*BrailleGenerator._generateProgressBarValuecKs$|jjj|�}|dk	r d|gSgS)Nz%s%%)r6r7ZgetValueAsPercent)rr)r*ZpercentrrrrZis
z$BrailleGenerator._generatePercentagecs$tjd�}|dkrt�j�St|�S)NZprogressBarBrailleInterval)r r!r<�_getProgressBarUpdateInterval�int)rZinterval)r>rrr\ps

z.BrailleGenerator._getProgressBarUpdateIntervalcstjd�sdSt�j|f|�S)Nr/F)r r!r<rW)rr)r*)r>rrrWws
z0BrailleGenerator._shouldPresentProgressBarUpdatecKs�g}y|j�}Wng}YnXx:|D]2}|j�tjkr(|jd�}|j|j|f|��Pq(W|s�|jd|�}|j|j|f|��|j||�|S)z�If this scroll pane is labelled by a page tab, then return the page
        tab information for the braille context instead. Thunderbird
        folder properties is such a case. See bug #507922 for more
        details.
        rZREAL_ROLE_SCROLL_PANE)	�getRelationSet�getRelationTyper&ZRELATION_LABELLED_BY�	getTargetr5r#Z
_overrideRoleZ_restoreRole)rr)r*r+Z	relations�relationZ
labelledByZoldRolerrr�_generateAsPageTabOrScrollPane�s


z/BrailleGenerator._generateAsPageTabOrScrollPanecKsNg}d}x"|D]}|r|j�tjkr|}qW|rJ|j�jtj�rJ|j|�|S)a�For a combo box, we check to see if the text is editable. If so,
        then we want to show the text attributes (such as selection --
        see bug 496846 for more details).  This will return an array
        containing a single object, which is the accessible for the
        text object. Note that this is different from the rest of the
        generators, which all return an array of strings.  Yes, this
        is a hack.
        N)r$r&Z	ROLE_TEXTZgetState�containsZSTATE_EDITABLEr3)rr)r*r+ZtextObjZchildrrr�_generateComboBoxTextObj�s	

z)BrailleGenerator._generateComboBoxTextObjc	Ks�|jd�rdStjd�}|s |Sy|j�}Wntk
rDd}YnX|r�|jjj|�sh|j�t	j
gkr�y|j|jt	j
�\}}}Wn
|S|dk}|r�x4|j�D](}|j�t	jkr�|jjj|jd��}q�W|S)z]Returns True or False to indicate whether context should be
        included or not.
        r.FrGNr)r"r r!Z	queryText�NotImplementedErrorr6r7Z
isTextArear$r&Z
ROLE_LABELZgetTextAtOffsetZcaretOffsetZTEXT_BOUNDARY_LINE_STARTr^r_ZRELATION_FLOWS_FROMr`)	rr)r*�include�textZ
lineStringZstartOffsetZ	endOffsetrarrr�_generateIncludeContext�s0


z(BrailleGenerator._generateIncludeContextcKsFg}tjd�sB|jdd�s$|j|d<d|d<|j|jjjf|��|S)NZdisableBrailleEOL�modeZeolZ
stringType)r r!r"�_moder3r6Z
formattingZ	getString)rr)r*r+rrr�_generateEol�s

zBrailleGenerator._generateEolr
cCs|dkrtSt|�gSdS)Nr
)�SPACEr)rrrrrr�szBrailleGenerator.spacecCs�d}d}t|t�r|}n�|r�t|t�r�x"|rHt|dt�rH|dd�}q(Wx"|rlt|dt�rl|dd�}qLWxF|D]>}t|t�r�|r�||j7}d}qt|j|�}|jjj|||�}qtW|S)N�rr���rn)	r%�str�listrrrr6r7ZappendString)rZcontentrZcombinedZprior�elementrrrr�s"



zBrailleGenerator.asString)r
)r
)!rrrrr&Z	ROLE_MENUZ
ROLE_MENU_BARZROLE_PAGE_TAB_LISTr'rJrrr-r;r8rBrErFrNrRrVrYr[rZr\rWrbrdrhrkrr�
__classcell__rr)r>rr2s64$I*	
r)rZ__id__�__version__Z__date__Z
__copyright__Z__license__r&rmrrrrrrr	r
Zbraille_rolenamesrZ
getManagerr rrlrrrrrr�<module>s&