Mini Shell

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

3

�p5[@��4@s�dZdZdZdZdZdZddlZddlZddlZddl	m
Z
yddlZWnek
r`dZYnXyddl
Z
dad	Zd
adaWnd
Zd
aYnXddlmZdd
lmZej�ZyddlmZWnd
e_YnXddlmZddlmZddlmZddlmZddlmZddlmZej�Z e j!d�Z"ddl#m$Z$e�r�e$�r�ej%ej&d�ej%ej&d�ej%ej&d�ej%ej&d�dZda'gZ(e�r�e
j)e
j*e
j+e
j,gZ(iZ-e�rDej.e-e
j)<ej/e-e
j*<ej0e-e
j+<ej1e-e
j,<ej2e-e
j3<ej4e-e
j5<ej6e-e
j7<ej8e-e
j9<ej:e-e
j;<ej<e-e
j=<ej>e-e
j?<ej@e-e
jA<dZBeBdgaCgaDdaEdjaFddgaGdaHd
aId
aJdaKdaLdaMejNejOejPejQejRejSejTejUejVejWejXejYejZej[ej\ej]ej^ej_ej`ejaejbejcejdejeejfejgejhejiejjejkejld�Zmdd�Zndd �Zoe�reo�Zpd!d"�ZqGd#d$�d$�ZrGd%d&�d&er�ZsGd'd(�d(es�ZtGd)d*�d*er�ZuGd+d,�d,es�ZvGd-d.�d.er�ZwGd/d0�d0�Zxd1d2�Zyd3d4�Zzd5d6�Z{d7d8�Z|d9d:�Z}d;d<�Z~dkd=d>�Zdld?d@�Z�dAdB�Z�dmdCdD�Z�dEdF�Z�dGdH�Z�dndIdJ�Z�dpdKdL�Z�dMdN�Z�dOdP�Z�dQdR�Z�dqdSdT�Z�drdUdV�Z�dWdX�Z�dsdYdZ�Z�d[d\�Z�d]d^�Z�d_d`�Z�dadb�Z�dcdd�Z�dtdfdg�Z�dhdi�Z�dS)ua�A very experimental approach to the refreshable Braille display.  This
module treats each line of the display as a sequential set of regions, where
each region can potentially backed by an Accessible object.  Depending upon
the Accessible object, the cursor routing keys can be used to perform
operations on the Accessible object, such as invoking default actions or
moving the text caret.
z$Id$z
$Revision$z$Date$z-Copyright (c) 2005-2009 Sun Microsystems Inc.ZLGPL�N)�GLibTF�)�settings)�settings_manager)�brlmon)�
brltablenames)�cmdnames)�debug)�eventsynthesizer)�logger)�
orca_stateZbraille)�	tablesdirz0Contraction tables for liblouis cannot be found.z(This usually means orca was built beforez/liblouis was installed. Contracted braille willznot be available.� )zCz-Cz-g1zEs-Es-g1zFr-Ca-g2zFr-Fr-g2zLv-Lv-g1zNl-Nl-g1zNo-No-g0zNo-No-g1zNo-No-g2zNo-No-g3zPl-Pl-g1zPt-Pt-g1zSe-Se-g1zar-ar-g1zcy-cy-g1zcy-cy-g2zde-de-g0zde-de-g1zde-de-g2zen-GB-g2zen-gb-g1zen-us-g1zen-us-g2zfr-ca-g1zfr-fr-g1zgr-gr-g1zhi-in-g1zhu-hu-comp8zhu-hu-g1zit-it-g1znl-be-g1cCsli}yNxHtjt�D]:}|dd�dkr|dd�}tjjt|�|tj||�<qWWntk
rfYnX|S)N��.utb�.ctb���)rrr)�os�listdirr
�path�join�TABLE_NAMES�get�OSError)Ztables�fname�alias�r�/usr/lib/python3.6/braille.py�
listTables�s"rcCsZy@x:tjt�D],}|dd�dkr|jd�rtjjt|�SqWWntk
rTYnXdS)Nr�.utb�.ctbzen-us�r)rr )rrr
�
startswithrrr)rrrr�getDefaultTable�s
r#cCstj|dt|��dS)z�Prints out a Braille event.  The given level may be overridden
    if the eventDebugLevel (see debug.setEventDebugLevel) is greater in
    debug.py.

    Arguments:
    - command: the BrlAPI command for the key that was pressed.
    zBRAILLE EVENT: %sN)r	ZprintInputEvent�repr)�levelZcommandrrr�_printBrailleEvent�s	r&c@sfeZdZdZddd�Zdd�Zdd	�Zddd�Zd
d�Zddd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�RegionzpA Braille region to be displayed on the display.  The width of
    each region is determined by its string.
    rFcCsp|sd}tjotdk	|_||_|jd�|_|jr^tjp8t|_	|j
|j||�\|_|_|_
|_n|j|_||_dS)z�Creates a new Region containing the given string.

        Arguments:
        - string: the string to be displayed
        - cursorOffset: a 0-based index saying where to draw the cursor
                        for this Region if it gets focus.
        r!N�
)r�enableContractedBraille�louis�
contracted�expandOnCursor�strip�rawLine�brailleContractionTable�_defaultContractionTable�contractionTable�contractLine�string�inPos�outPos�cursorOffset)�selfr3r6r,rrr�__init__s	
zRegion.__init__cCsd|j|jfS)NzRegion: '%s', %d)r3r6)r7rrr�__str__1szRegion.__str__cCsdS)aProcesses a cursor routing key press on this Component.  The offset
        is 0-based, where 0 represents the leftmost character of string
        associated with this region.  Note that the zeroeth character may have
        been scrolled off the display.Nr)r7�offsetrrr�processRoutingKey4szRegion.processRoutingKeyTcCsdt|j�S)a�Creates a string which can be used as the attrOr field of brltty's
        write structure for the purpose of indicating text attributes, links,
        and selection.

        Arguments:
        - getLinkMask: Whether or not we should take the time to get
          the attributeMask for links. Reasons we might not want to
          include knowning that we will fail and/or it taking an
          unreasonable amount of time (AKA Gecko).
        �)�lenr3)r7�getLinkMaskrrr�getAttributeMask;szRegion.getAttributeMaskcCs.|jr*|j|j|j|j�\|_|_|_|_dS)z:Reposition the cursor offset for contracted mode.
        N)r+r2r.r6r,r3r4r5)r7rrr�repositionCursorKszRegion.repositionCursorc
Csxy||dk}Wntk
r(d}YnX|s4|r:d}ntj}tj|jg|||d�\}}}}	t|	t|��}	||||	fS)a*Contract the given line. Returns the contracted line, and the
        cursor position in the contracted line.

        Arguments:
        - line: Line to contract.
        - cursorOffset: Offset of cursor,defaults to 0.
        - expandOnCursor: Expand word under cursor, False by default.
        � Fr)�	cursorPos�mode)�
IndexErrorr*ZcompbrlAtCursor�	translater1�minr=)
r7�liner6r,Z
cursorOnSpacerCr+r4r5rBrrrr2Ts



zRegion.contractLinecCsHy|j|}Wn4tk
r,t|j�}Yntk
rB|}YnX|S)N)r4rDr=r.�AttributeError)r7�display_offsetr:rrr�displayToBufferOffsetts
zRegion.displayToBufferOffsetcCs&|rtjpt|_|j�n|j�dS)N)rr/r0r1�contractRegion�expandRegion)r7r+rrr�setContractedBraille�s

zRegion.setContractedBraillecCs8|jr
dS|j|j|j|j�\|_|_|_|_d|_dS)NT)r+r2r.r6r,r3r4r5)r7rrrrK�szRegion.contractRegioncCsP|js
dS|j|_y|j|j|_Wn tk
rDt|j�|_YnXd|_dS)NF)r+r.r3r4r6rDr=)r7rrrrL�szRegion.expandRegionN)rF)T)rF)�__name__�
__module__�__qualname__�__doc__r8r9r;r?r@r2rJrMrKrLrrrrr's
!
	
 	r'c@s2eZdZdZddd�Zdd�Zd	d
�Zdd�Zd
S)�	Componentz�A subclass of Region backed by an accessible.  This Region will react
    to any cursor routing key events and perform the default action on the
    accessible, if a default action exists.
    rr!FcCs<tj||||�|r2|jr,|d|j|_n||_||_dS)aCreates a new Component.

        Arguments:
        - accessible: the accessible
        - string: the string to use to represent the component
        - cursorOffset: a 0-based index saying where to draw the cursor
                        for this Region if it gets focus.
        rAN)r'r8r3�
accessible)r7rSr3r6Z	indicatorr,rrrr8�szComponent.__init__cCsd|j|jfS)NzComponent: '%s', %d)r3r6)r7rrrr9�szComponent.__str__cCsdS)z�Returns the caret position of the given offset if the object
        has text with a caret.  Otherwise, returns -1.

        Arguments:
        - offset: 0-based offset of the cell on the physical display
        r���r)r7r:rrr�getCaretOffset�szComponent.getCaretOffsetcCs�tjr8tjjj|j|�r8y|jj�j�WnYnXy|jj�}WnTtj	tj
d�ytj|jd�Wn&tj	tj
d�tjtj
�YnXYnX|jd�dS)aProcesses a cursor routing key press on this Component.  The offset
        is 0-based, where 0 represents the leftmost character of string
        associated with this region.  Note that the zeroeth character may have
        been scrolled off the display.z.braille.Component.processRoutingKey: no actionrzCould not process routing key:rN)r�activeScript�	utilitiesZgrabFocusBeforeRoutingrSZqueryComponentZ	grabFocusZqueryActionr	�println�LEVEL_FINESTr
ZclickObject�LEVEL_SEVERE�printExceptionZdoAction)r7r:�actionrrrr;�s$
zComponent.processRoutingKeyN)rr!F)rNrOrPrQr8r9rUr;rrrrrR�s
	rRc@s,eZdZdZddd�Zdd�Zddd	�Zd
S)
�Linkz�A subclass of Component backed by an accessible.  This Region will be
    marked as a link by dots 7 or 8, depending on the user's preferences.
    rcCstj||||dd�dS)zlInitialize a Link region. similar to Component, but here we always
        have the region expand on cursor.r!TN)rRr8)r7rSr3r6rrrr8�sz
Link.__init__cCsd|j|jfS)NzLink: '%s', %d)r3r6)r7rrrr9�szLink.__str__TcCsttj�t|j�S)a�Creates a string which can be used as the attrOr field of brltty's
        write structure for the purpose of indicating text attributes and
        selection.
        Arguments:

        - getLinkMask: Whether or not we should take the time to get
          the attributeMask for links. Reasons we might not want to
          include knowning that we will fail and/or it taking an
          unreasonable amount of time (AKA Gecko).
        )�chrr�brailleLinkIndicatorr=r3)r7r>rrrr?�szLink.getAttributeMaskN)r)T)rNrOrPrQr8r9r?rrrrr]�s
r]c@s^eZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zddd�Z	ddd�Z
dd�Zdd�ZdS)�TextajA subclass of Region backed by a Text object.  This Region will
    react to any cursor routing key events by positioning the caret in
    the associated text object. The line displayed will be the
    contents of the text object preceded by an optional label.
    [[[TODO: WDW - need to add in text selection capabilities.  Logged
    as bugzilla bug 319754.]]]r!NcCsb||_tjr2|jr2tjj|j||d�\}|_|_nd}d|_d|_y||j}Wntk
rlt|�}YnXy||j|_Wntk
r�d|_YnX||j|�}|j|j8_t	|j|jt|��}|jt|�|_
||_|r�|d|_nd|_|j|}|t|j�7}t
j|||d�|j�rHtj�rH|j|j7_ntj�r^|jd7_dS)z�Creates a new Text region.

        Arguments:
        - accessible: the accessible that implements AccessibleText
        - label: an optional label to display
        )�startOffset�	endOffsetr!rrATN)rSrrV�getTextLineAtCaret�caretOffset�
lineOffset�	TypeErrorr=rarF�_maxCaretOffset�eol�labelr'r8r+rZdisableBrailleEOLr3)r7rSrirhrarbr3r6rrrr8s<	
z
Text.__init__cCsd|j|jfS)NzText: '%s', %d)r3r6)r7rrrr9?szText.__str__cCs�tjj|j|j�\}}}t||t|��}||jkr8dS||_||_|t|j	�7}|j
rv|j|j|d�\|_
|_|_}||_dS)z�Attempts to reposition the cursor in response to a new
        caret position.  If it is possible (i.e., the caret is on
        the same line as it was), reposition the cursor and return
        True.  Otherwise, return False.
        FT)rrVrcrSrarFr=rerdrir+r2r.r3r4r5r6)r7r3rdrer6rrrr@Bs

zText.repositionCursorcCs(|j|�}|dkrdSt|j||j�S)z�Returns the caret position of the given offset if the object
        has text with a caret.  Otherwise, returns -1.

        Arguments:
        - offset: 0-based offset of the cell on the physical display
        rrrT)rJrFrerg)r7r:rrrrU_s
zText.getCaretOffsetcCs,|j|�}|dkrdStjjj|j|�dS)aProcesses a cursor routing key press on this Component.  The offset
        is 0-based, where 0 represents the leftmost character of text
        associated with this region.  Note that the zeroeth character may have
        been scrolled off the display.
        rN)rUrrVrW�setCaretOffsetrS)r7r:rdrrrr;ms

zText.processRoutingKeyTcsHy�jj�}Wntk
r"dSXt�j�t�j�}�j|}tjg|}tj	}tj
}tj}tj
}	|or|tjk�ry�jj�}
|
j�}Wnd}YnXd}xh||k�r
|
j|�}
�j|
jk�rx8t|
j|
j�D]&}y|||O<Wq�Yq�Xq�W|d7}q�W|�r�|	jjtj�\}}�j}x�||k�r�|	jj�j|d�\}}}||k�rZPtj}|}x8|D]0}|j|d�dk�rj||||k�rj|}P�qjW|tjk�r,t|�jd�}t|�j|�}x$t||�D]}|||O<�q�W�q,W|�rd|	jj�j�}xX|D]P\}}t|�jd�}t|�j|�}x$t||�D]}|||O<�qDW�qW�j�rdgt�j�}�jt�j�d�}�j�r��fdd�|D�}xJt|�D]>\}}y||||O<Wntk
�r��w�YnX�q�W|dt�j ��}|dgt�j!�7}�j�r8dgt�j�|}dj"t#t$|��S)a�Creates a string which can be used as the attrOr field of brltty's
        write structure for the purpose of indicating text attributes, links,
        and selection.

        Arguments:
        - getLinkMask: Whether or not we should take the time to get
          the attributeMask for links. Reasons we might not want to
          include knowning that we will fail and/or it taking an
          unreasonable amount of time (AKA Gecko).
        r!rrTNcsg|]}|t�j�d�qS)r)r=ri)�.0r:)r7rr�
<listcomp>�sz)Text.getAttributeMask.<locals>.<listcomp>)%rSZ	queryText�NotImplementedErrorr=r.rirerZBRAILLE_UNDERLINE_NONEZtextAttributesBrailleIndicatorZbrailleSelectorIndicatorr_rrVZqueryHypertextZ	getNLinksZgetLinkZ
startIndex�rangeZendIndexrWZstringToKeysAndDictZenabledBrailledTextAttributesZtextAttributesr�maxrFZallTextSelectionsr+r5�	enumeraterDr3rhr�mapr^)r7r>�textZstringLengthZ
lineEndOffsetZ
regionMaskZ
attrIndicatorZselIndicatorZ
linkIndicatorZscriptZ	hyperTextZnLinks�n�link�i�keysZenabledAttributesr:Z
attributesrarb�maskZattribZ	maskStartZmaskEndZ
selectionsZcontractedMaskr5�mr)r7rr?|s�







zText.getAttributeMaskrcCs*tj||||�\}}}}||j|||fS)N)r'r2rh)r7rGr6r,r+r4r5rBrrrr2�szText.contractLinecCs(tj||�}||j7}|t|j�8}|S)N)r'rJrar=ri)r7rIr:rrrrJ�s
zText.displayToBufferOffsetcCs$tj||�|s |j|j7_dS)N)r'rMr3rh)r7r+rrrrM�szText.setContractedBraille)r!r!NN)T)rT)
rNrOrPrQr8r9r@rUr;r?r2rJrMrrrrr`�s
9
f
r`c@seZdZdZdd�ZdS)�ReviewComponentz@A subclass of Component that is to be used for flat review mode.cCstj||||dd�||_dS)a_Creates a new Component.

        Arguments:
        - accessible: the accessible
        - string: the string to use to represent the component
        - cursorOffset: a 0-based index saying where to draw the cursor
                        for this Region if it gets focus.
        - zone: the flat review Zone associated with this component
        T)r,N)rRr8�zone)r7rSr3r6rzrrrr8�s


zReviewComponent.__init__N)rNrOrPrQr8rrrrry�sryc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�
ReviewTextaA subclass of Region backed by a Text object.  This Region will
    does not react to the caret changes, but will react if one updates
    the cursorPosition.  This class is meant to be used by flat review
    mode to show the current character position.
    cCs&tj||dd�||_||_||_dS)aICreates a new Text region.

        Arguments:
        - accessible: the accessible that implements AccessibleText
        - string: the string to use to represent the component
        - lineOffset: the character offset into where the text line starts
        - zone: the flat review Zone associated with this component
        T)r,N)r'r8rSrerz)r7rSr3rerzrrrr8s	zReviewText.__init__cCs |j|�}|dkrdS|j|S)z�Returns the caret position of the given offset if the object
        has text with a caret.  Otherwise, returns -1.

        Arguments:
        - offset: 0-based offset of the cell on the physical display
        rrrT)rJre)r7r:rrrrUs
zReviewText.getCaretOffsetcCs |j|�}tjjj|j|�dS)z�Processes a cursor routing key press on this Component.  The offset
        is 0-based, where 0 represents the leftmost character of text
        associated with this region.  Note that the zeroeth character may have
        been scrolled off the display.N)rUrrVrWrjrS)r7r:rdrrrr;'s
zReviewText.processRoutingKeyN)rNrOrPrQr8rUr;rrrrr{sr{c@sLeZdZdZddd�Zdd�Zdd�Zdd
d�Zdd
�Zdd�Z	dd�Z
dS)�LinezaA horizontal line on the display.  Each Line is composed of a sequential
    set of Regions.
    NcCsg|_d|_|r|j|�dS)Nr!)�regionsr3�	addRegion)r7�regionrrrr86sz
Line.__init__cCs|jj|�dS)N)r}�append)r7rrrrr~<szLine.addRegioncCs|jj|�dS)N)r}�extend)r7r}rrr�
addRegions?szLine.addRegionsTcCs�d}d}d}g}x@|jD]6}|tkr,t|�}|jr<||j7}|j|�}||7}qWdd�tjd|�D�}g}	xp|D]Z\}
}|	r�||	dtdkr�|j|	�g}	|	s�|
|g}	n||	d<||krr|j|	�g}	qrW|	r�|j|	�||||gS)a,Computes the complete string for this line as well as a
        0-based index where the focused region starts on this line.
        If the region with focus is not on this line, then the index
        will be -1.

        Arguments:
        - getLinkMask: Whether or not we should take the time to get
          the attributeMask for links. Reasons we might not want to
          include knowning that we will fail and/or it taking an
          unreasonable amount of time (AKA Gecko).

        Returns [string, offsetIndex, attributeMask, ranges]
        r!rcSsg|]}|j��qSr)�span)rkZwordrrrrl]sz$Line.getLineInfo.<locals>.<listcomp>z
(^\s+|\S+\s*)rrT)	r}�_regionWithFocusr=r3r?�re�finditer�_displaySizer�)r7r>r3�focusOffset�
attributeMask�rangesrrwZwordsr��start�endrrr�getLineInfoBs4





zLine.getLineInfocCsfd}d}d}x4|jD]*}|}||j}t|�|kr6Pqt|�}qW|t|�krVddgS|||gSdS)a5Finds the Region at the given 0-based offset in this line.

        Returns the [region, offsetinregion] where the region is
        the region at the given offset, and offsetinregion is the
        0-based offset from the beginning of the region, representing
        where in the region the given offset is.Nr!rrrT)r}r3r=)r7r:ZfoundRegionr3�posrrrr�getRegionAtOffsetps
zLine.getRegionAtOffsetcCs |j|�\}}|r|j|�dS)z�Processes a cursor routing key press on this Component.  The offset
        is 0-based, where 0 represents the leftmost character of string
        associated with this line.  Note that the zeroeth character may have
        been scrolled off the display.N)r�r;)r7r:r�regionOffsetrrrr;�szLine.processRoutingKeycCsx|jD]}|j|�qWdS)N)r}rM)r7r+rrrrrM�szLine.setContractedBraille)N)T)rNrOrPrQr8r~r�r�r�r;rMrrrrr|1s

.
r|cCs>tt�dkr2|dtd}td}t|j|�SddgSdS)aBGiven a 1-based cell offset, return the braille region
    associated with that cell in the form of [region, offsetinregion]
    where 'region' is the region associated with the cell and
    'offsetinregion' is the 0-based offset of where the cell is
    in the region, where 0 represents the beginning of the region.
    rrNrT)r=�_lines�viewportr�)�cellr:�lineNumrrr�getRegionAtCell�s
r�cCsT|jd}t|d�\}}|rDt|t�s2t|t�rD|j}|j|�}nd}d}||gS)aNGets the accesible and caret offset associated with the given
    event.  The event should have a BrlAPI event that contains an
    argument value that corresponds to a cell on the display.

    Arguments:
    - event: an instance of input_event.BrailleEvent.  event.event is
    the dictionary form of the expanded BrlAPI event.
    �argumentrNrT)�eventr��
isinstancer`r{rSrU)r�r:rr�rSrdrrr�getCaretContext�s

r�cCsgadaddgadS)zgClears the logical structure, but keeps the Braille display as is
    (until a refresh operation).
    Nr)r�r�r�rrrr�clear�s	r�cCs|adS)N)r�)�linesrrr�setLines�sr�cCstj|�tt�|_dS)a/Adds a line to the logical display for painting.  The line is added to
    the end of the current list of known lines.  It is necessary for the
    viewport to be over the lines and for refresh to be called for the new
    line to be painted.

    Arguments:
    - line: an instance of Line to add.
    N)r�r�r=Z_index)rGrrr�addLine�s

r�cCsttdS)zEReturns the Line that is currently being painted on the display.
    r)r�r�rrrr�getShowingLine�sr�cCs�|a|strdSd}d}xBtD]:}x$|jD]}|tkr.|td<d}Pq.W|rTPq"|d7}q"Wttd}|j|�\}}}	}
tjtdkr�|tjtdd7}td|�td<dS)a/Specififes the region with focus.  This region will be positioned
    at the home position if panToFocus is True.

    Arguments:
    - region: the given region, which much be in a line that has been
      added to the logical display
    - panToFocus: whether or not to position the region at the home
      position
    - getLinkMask: Whether or not we should take the time to get the
      attributeMask for links. Reasons we might not want to include
      knowning that we will fail and/or it taking an unreasonable
      amount of time (AKA Gecko).
    NrFrT)r�r�r}r�r�r6r�ro)rZ
panToFocusr>r��donerGZregr3r:r�r�rrr�setFocus�s&	
r�cCs�t\}}}}tr.ttt�r.tj}tj}	tj}
nd}d}	d}
|rHtdd�tj	d�r�tj	d�r�t
r�ytjdd�Wn&t
jt
jd�t
jt
j�YnXt�dadStt�dk�rt
s�tttj�t
�rytjdd�Wn,t
jt
jd�t
jt
j�t�YnXdadS|dk�r.td|d	}|dk�r�|�r�||k�r�|
|k�r�|dk�r^nN||	k�rn|}n>||	k�r�ttd||	|�}n||	k�r�td	|||	�}ttd	}|j|�\}}
}}d}|
dk�r�|
tj}|�r�|dk�r�t|�tdk�rdtd<n�|�r,td||d	�td<nj|tdk�rJtd|�td<nL|tdtdk�r|td|tdd	�td<nt|�}td|d�td<t�\}}|td<||a t dk�s�t tdk�r�da nt d	7a d
|}t
jt
j!|�t"j#|�d|||�t f}t
jt
j!|�t"j#|�|||�}|�rB|||�}nd||}t
�s`tttj�t
�r&t$j%�}d	|_&t|�|_'x:|j'tdk�r�|d
7}|�r�|d7}|j'd	7_'�q�W||_(t |_)|�r�||_*t
�s�tttj�t
�r&ytj+|�Wn,t
jt
jd�t
jt
j�t�YnXtj,�r�t-�snyt.j/td�a-t-j0�Wnt
jt
jd�da-YnX|�r�|||�}nd}t-�r�t-jt ||�nt-�r�t-j1�da-|dka2|t|�ka3t�r�ttt��r�tjtjtjt fandadS)adRepaints the Braille on the physical display.  This clips the entire
    logical structure by the viewport and also sets the cursor to the
    appropriate location.  [[[TODO: WDW - I'm not sure how BrlTTY handles
    drawing to displays with more than one line, so I'm only going to handle
    drawing one line right now.]]]

    Arguments:

    - panToCursor: if True, will adjust the viewport so the cursor is
      showing.
    - targetCursorCell: Only effective if panToCursor is True.
      0 means automatically place the cursor somewhere on the display so
      as to minimize movement but show as much of the line as possible.
      A positive value is a 1-based target cell from the left side of
      the display and a negative value is a 1-based target cell from the
      right side of the display.
    - getLinkMask: Whether or not we should take the time to get the
      attributeMask for links. Reasons we might not want to include
      knowning that we will fail and/or it taking an unreasonable
      amount of time (AKA Gecko).
    - stopFlash: if True, kill any flashed message that may be showing.
    NrF)�restoreSaved�
enableBraille�enableBrailleMonitorr!z!BrlTTY seems to have disappeared:rzBRAILLE LINE:  '%s'z     VISIBLE:  '%s', cursor=%dr<rAz
brlmon failed)Nrrr)NrrrrT)Nrrr)4�
_lastTextInfor�r�r`rSrdre�	killFlash�_settingsManagerZ
getSetting�_brlAPIRunning�_brlAPIZ	writeTextr	rX�
LEVEL_WARNINGr[�shutdownr=r��init�	_callbackr�ttyr�rFror�r�r6�_getRangeForOffset�_adjustForWordWrap�
cursorCell�
LEVEL_INFO�log�info�brlapiZWriteStructZregionBeginZ
regionSizerr�cursorZattrOr�writer��_monitorrZBrlMonZshow_all�destroy�beginningIsShowing�endIsShowing)�panToCursorZtargetCursorCellr>�	stopFlashZlastTextObjZlastCaretOffsetZlastLineOffsetZlastCursorCellZcurrentTextObjZcurrentCaretOffsetZcurrentLineOffsetrGr3r�r�r�r6ZrangeForOffset�startPos�endPosZlogLineZ	substringZsubmaskZwriteStructZsubMaskrrr�refreshs%















r�cCs$tr t\aaa}tddd�dadS)NF)r�r�r)�_flashEventSourceId�_savedr�r�r�r�)�	flashTimerrr�_flashCallbacks
r�cCs:tr6tdkrtjt�|r2t\aaa}tddd�dadS)NrF)r�r�)r�r�
source_remover�r�r�r�r�)r�r�rrrr�s
r�cCs*tdkr&tjt�td}tj|t�adS)Nr�)r�rr�r��timeout_addr�)r�rrr�resetFlashTimer!s
r�cCsNtrtdkrtjt�danttt|fa|dkr>tj|t�an|dkrJdadS)a�Sets up the state needed to flash a message or clears any existing
    flash if nothing is to be flashed.

    Arguments:
    - flashTime:  if non-0, the number of milliseconds to display the
                  regions before reverting back to what was there before.
                  A 0 means to not do any flashing.  A negative number
                  means display the message until some other message
                  comes along or the user presses a cursor routing key.
    ri�Nif���)	r�rr�r�r�r�r�r�r�)r�rrr�
_initFlash(s
r�cCsZt|�|d}|d}t�t�}x|D]}|j|�q*Wt|�t|�tdd�dS)aDisplays a list of regions on a single line, setting focus to the
       specified region.  The regionInfo parameter is something that is
       typically returned by a call to braille_generator.generateBraille.

    Arguments:
    - regionInfo: a list where the first element is a list of regions
                  to display and the second element is the region
                  with focus (must be in the list from element 0)
    - flashTime:  if non-0, the number of milliseconds to display the
                  regions before reverting back to what was there before.
                  A 0 means to not do any flashing.  A negative number
                  means display the message until some other message
                  comes along or the user presses a cursor routing key.
    rrF)r�N)r�r�r|r~r�r�r�)Z
regionInfor�r}Z
focusedRegionrG�itemrrr�displayRegionsCs
r�cCs<t|�t�t||�}tt|��t|�tddd�dS)aVDisplays a single line, setting the cursor to the given position,
    ensuring that the cursor is in view.

    Arguments:
    - message: the string to display
    - cursor: the 0-based cursor position, where -1 (default) means no cursor
    - flashTime:  if non-0, the number of milliseconds to display the
                  regions before reverting back to what was there before.
                  A 0 means to not do any flashing.  A negative number
                  means display the message until some other message
                  comes along or the user presses a cursor routing key.
    TF)r�N)r�r�r'r�r|r�r�)�messager�r�rrrr�displayMessage_s
r�cCs2|j�}|r.|j�}d||f}t|tjd�dS)z^Displays a KeyboardEvent. Typically reserved for locking keys like
    Caps Lock and Num Lock.z%s %s)r�N)ZgetLockingStateStringZ
getKeyNamer�rZbrailleFlashTime)r�ZlockingStateStringZkeyname�msgrrr�displayKeyEventts
r�cstd��td}d�|f}tjtj|d�ts>tjrF�|fSttd}|j�\}}}}t	t
�fdd�|��}|�r�d|dd|d	df}tjtj|d�|d
d|ddtdkr�d}tjtj|d�n|dd|dd�}�|fS)Nrz!BRAILLE: Current range: (%i, %i).Trcs |d�ko|dkSS)Nrrr)�x)r�rr�<lambda>�sz$_adjustForWordWrap.<locals>.<lambda>z!BRAILLE: Adjusted range: (%i, %i)z?BRAILLE: Not adjusting range which is greater than display sizerTrTrT)r�r�r	rXr�r�rZenableBrailleWordWrapr��list�filter)r�r�rGZ
lineStringr�r�r�r)r�rr�~s" r�cCsRttdj�\}}}}x0|D](}|d|ko<|dknr|SqWddgS)Nrr)r�r�r�)r:r3r�r�r��rrrrr��s

 r�cCsftd}|dkrDt|�\}}t|d�\}}tdt||td��}tdtd|�td<|tdkS)aPans the display to the left, limiting the pan to the beginning
    of the line being displayed.

    Arguments:
    - panAmount: the amount to pan.  A value of 0 means the entire
                 width of the physical display.

    Returns True if a pan actually happened.
    rr)r�r�rorFr�)�	panAmount�oldXZoldStartZoldEndZnewStartZnewEndrrr�panLeft�sr�cCs4td}|dkrtd}td|7<|tdkS)aPans the display to the right, limiting the pan to the length
    of the line being displayed.

    Arguments:
    - panAmount: the amount to pan.  A value of 0 means the entire
                 width of the physical display.

    Returns True if a pan actually happened.
    r)r�r�)r�r�rrr�panRight�s
r�cCsdx*|tdkr*tjtjd|�t�sPqWx2|tdtdkr^tjtjd|�t�s.Pq.WdS)zOAutomatically pan left or right to make sure the current offset is
    showing.rzbraille.panToOffset (left) %dzbraille.panToOffset (right) %dN)r�r	rXrYr�r�r�)r:rrr�panToOffset�s

r�cCstt�td�dS)z�Pans the display so the region with focus is displayed.

    Arguments:
    - inputEvent: the InputEvent instance that caused this to be called.

    Returns True to mean the command should be consumed.
    T)r�r�r�)Z
inputEventrrr�returnToRegionWithFocus�s	r�cCs:|jdtj@dkt_xtD]}|jtj�qWt�dS)z�Turns contracted braille on or off based upon the event.

    Arguments:
    - event: an instance of input_event.BrailleEvent.  event.event is
    the dictionary form of the expanded BrlAPI event.
    �flagsrN)r�r�ZKEY_FLG_TOGGLE_ONrr)r�rMr�)r�rGrrrrM�s	
rMcCsJtrt�dS|jd}tt�dkrF|td}td}t|j|�dS)z�Processes a cursor routing key event.

    Arguments:
    - event: an instance of input_event.BrailleEvent.  event.event is
    the dictionary form of the expanded BrlAPI event.
    Nr�rrT)r�r�r�r=r�r�r;)r�r�r�r�rrrr;�s

r;c	Cs�ttj|�d}tjr<tjdkr<tjtjtj�tjtj�t	rxyt	|�}Wn*tj
tjd�tjtj�d}YnXtjr�tjdkr�tjd�|S)z�Handles BrlTTY command events.  This passes commands on to Orca for
    processing.

    Arguments:
    - event: the BrlAPI input event (expanded)
    FrzIssue processing event:)
r&r	Z
LEVEL_FINErZtimeoutCallbackZtimeoutTime�signal�SIGALRM�alarmr�rXr�r[)r��consumedrrr�_processBrailleEvents

r�c	CsPytjd�}Wn*tjtjd�tjtj�t�dS|rLttj|��t	S)z\Method to read a key from the BrlAPI bindings.  This is a
    gobject IO watch handler.
    Fz!BrlTTY seems to have disappeared:N)
r�ZreadKeyr	rXr�r[r�r�Z
expandKeyCoder�)�sourceZ	condition�keyrrr�_brlAPIKeyReader&sr�cCsftstttj�tsdStjtjdg�tj	tj
Bg}x|D]}|jtj	|B�q<Wtjtj
|�dS)z�Hacky method to tell BrlTTY what to send and not send us via
    the readKey method.  This only works with BrlTTY v3.8 and better.

    Arguments:
    -keys: a list of BrlAPI commands.
    Nr)r�r�r�rr�r�Z
ignoreKeysr�Z
rangeType_allZKEY_TYPE_CMD�
KEY_CMD_ROUTEr�Z
acceptKeysZrangeType_command)rvZkeySetr�rrr�setupKeyRanges5s
r��cCsrtrdStjsdS|ay�tj�ay0tjd}tj	�dat
jt
jdd|�Wnjy0tjd}tj	�dat
jt
jdd|�Wn,tj
|�dat
jt
jd|�YnXYnXtjtjtjtjt�aWnHtk
r�t
jt
jd	�dSt
jt
jd
�t
jt
j�dadStj\}}|dgat�rBtj�dat
jt
jd
tdtdf�t�td�dS)a"Initializes the braille module, connecting to the BrlTTY driver.

    Arguments:
    - callback: the method to call with a BrlTTY input event.
    - tty: the tty port to take ownership of (default = 7)
    Returns False if BrlTTY cannot be accessed or braille has
    not been enabled.
    TFZ
WINDOWPATHz5Braille module has been initialized using WINDOWPATH=z%sZXDG_VTNRz3Braille module has been initialized using XDG_VTNR=z0Braille module has been initialized using tty=%dzBrlApi is not definedzCould not initialize BrlTTY:rNzbraille display size = (%d, %d)r)r�rr�r�r�Z
Connectionr�r�environZenterTtyModeWithPathr	rXZLEVEL_CONFIGURATIONZenterTtyModerZio_add_watchZfileDescriptorZPRIORITY_DEFAULTZIO_INr��_brlAPISourceId�	NameErrorr[ZdisplaySizer�r�r�r�r�)�callbackr�Z
windowPathZvtnrr��yrrrr�Psl




r�cCsptrhdatjt�daytj�WnYnXytj�WnYnXdatr^tj�dat	dga
ndSdS)zYShuts down the braille module.   Returns True if the shutdown procedure
    was run.
    FrNrT)r�rr�r�r�ZleaveTtyModeZcloseConnectionr�r��DEFAULT_DISPLAY_SIZEr�rrrrr��s&

r�)Nrrr)TT)TrTT)T)rrT)rTr)r)r)N)Nr�)�rQZ__id__�__version__Z__date__Z
__copyright__Z__license__r�rr�Z
gi.repositoryrr*�ImportErrorr�r�Z_brlAPIAvailabler�r�r!rrZ
getManagerr�rr�rrr	r
rrZ	getLoggerZ_loggerZnewLogr�Z
orca_platformr
rXrZr�ZdontInteruptSpeechKeysZKEY_CMD_FWINLTZKEY_CMD_FWINRTZKEY_CMD_LNUPZKEY_CMD_LNDNZcommand_nameZBRAILLE_LINE_LEFTZBRAILLE_LINE_RIGHTZBRAILLE_LINE_UPZBRAILLE_LINE_DOWNZBRAILLE_FREEZEZKEY_CMD_FREEZEZBRAILLE_TOP_LEFTZKEY_CMD_TOP_LEFTZBRAILLE_BOTTOM_LEFTZKEY_CMD_BOT_LEFTZBRAILLE_HOMEZKEY_CMD_HOMEZBRAILLE_SIX_DOTSZKEY_CMD_SIXDOTSZBRAILLE_ROUTE_CURSORr�ZBRAILLE_CUT_BEGINZKEY_CMD_CUTBEGINZBRAILLE_CUT_LINEZKEY_CMD_CUTLINEr�r�r�r�r�r�r�r�r�r�r�r�ZCZ_CZ_G1ZES_ES_G1ZFR_CA_G2ZFR_FR_G2ZLV_LV_G1ZNL_NL_G1ZNO_NO_G0ZNO_NO_G1ZNO_NO_G2ZNO_NO_G3ZPL_PL_G1ZPT_PT_G1ZSE_SE_G1ZAR_AR_G1ZCY_CY_G1ZCY_CY_G2ZDE_DE_G0ZDE_DE_G1ZDE_DE_G2ZEN_GB_G2ZEN_GB_G1ZEN_US_G1ZEN_US_G2ZFR_CA_G1ZFR_FR_G1ZGR_GR_G1ZHI_IN_G1Z
HU_HU_8DOTZHU_HU_G1ZIT_IT_G1ZNL_BE_G1rrr#r0r&r'rRr]r`ryr{r|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rMr;r�r�r�r�r�rrrr�<module>s8


	


Ew-i


5
o







 
W