
    g
f~R                     @   d Z dZdZdZdZdZddlZ ej                  dd	       dd
lm	Z	 ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  G d d      Z e       gZ G d dej>                        Z y)z:Utilities for obtaining braille presentations for objects.z$Id$z
$Revision$z$Date$z-Copyright (c) 2005-2009 Sun Microsystems Inc.LGPL    NAtspiz2.0)r      )braille)debug)focus_manager)	generator)messages)object_properties)settings)settings_manager)AXObject)AXText)AXUtilities)AXValue)shortRoleNamesc                       e Zd ZdZddZy)SpacezxA dummy class to indicate we want to insert a space into an
    utterance, but only if there is text prior to the space.c                     || _         y N)	delimiterselfr   s     8/usr/lib/python3/dist-packages/orca/braille_generator.py__init__zSpace.__init__2   s	    "    N )__name__
__module____qualname____doc__r    r   r   r   r   /   s    @#r   r   c                       e Zd ZdZej
                  j                  ej
                  j                  ej
                  j                  ej
                  j                  ej
                  j                  ej
                  j                  fZd Zd Zd Zd Zd Z fdZd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Z fdZ fdZd Z d Z!d Z"ddZ#ddZ$ xZ%S )BrailleGeneratora  Takes 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.c                 F    t         j                  j                  | |d       y )Nr   )r	   	Generatorr   )r   scripts     r   r   zBrailleGenerator.__init__D   s    $$T69=r   c                    t         j                  j                  | |       | j                  |d<   t        j
                  |d<   t        j                  |d<   t        j                  |d<   t        j                  |d<   | j                  |d<   y)zCOther things to make available from the formatting string.
        space	ComponentRegionTextLinkasStringN)
r	   r'   _addGlobalsr*   r   r+   r,   r-   r.   r/   )r   globalsDicts     r   r0   zBrailleGenerator._addGlobalsG   sp     	''k:#zzG#*#4#4K  'H%llF%llF"&--Jr   c                    t        |t        j                  t        j                  f      syt	        j
                  ||j                        syt        j                  |      t        j                  |j                        k(  S )NF)	
isinstancer   r+   r-   r   have_same_role
accessibler   get_name)r   objregions      r   _isCandidateFocusedRegionz*BrailleGenerator._isCandidateFocusedRegionR   s^    &7#4#4gll"CD))#v/@/@A  %):):6;L;L)MMMr   c                     t        j                         j                  d      sLt        j                         j                  d      s)t        j                  t        j
                  dd       g d gS t        j                         j                         k(  r|j                  dd       sd|d<     j                  fi |}	 |d   }|D ]  }t        |t        j                  t        j                  f      r8 j                  j                   j#                  |j$                  d      r|} ||gS t        |t        j                        r>t'        j(                        r)t+        j,                  |j$                        k(  r|} ||gS t        |t        j                        st'        j.                        st+        j,                  |j$                        k(  s|} ||gS   fd}t1        t3        ||            }d	d
|g}t        j4                  t        j
                  |d       t7        |      dk(  r|d   }||gS # t        $ r d }Y w xY w)NenableBrailleenableBrailleMonitorz&BRAILLE GENERATOR: generation disabledT
formatTypefocusedr   c                 (    j                  |       S r   )r9   )xr7   r   s    r   predz.BrailleGenerator.generateBraille.<locals>.pred   s    55c1==r   z9BRAILLE GENERATOR: Could not determine focused region forzCandidates:r   )r   
getManager
getSettingr   printMessage
LEVEL_INFOr   get_locus_of_focusgetgenerate	Exceptionr3   r   r+   r-   _script	utilitiesisSameObjectr5   r   is_combo_boxr   
get_parentis_table_celllistfilterprintTokenslen)	r   r7   argsresultfocusedRegionr8   rA   
candidatestokenss	   ``       r   generateBraillez BrailleGenerator.generateBraille[   s   **,77H#..0;;<RSu//1Y[_`:-**,??AA88L$/!*Ds+d+	!"1IM  	.F&7#4#4gll"CD<<))66v7H7H#tT &. &&- FGLL1 --c2(():):;sB &$ &&# FG$5$56 ..s3(():):;sB & &&7	."> fT623JQ=*6Fe..=:!# *1&&=  	! M	!s   I IIc                    |j                  d      r%t        j                         j                  d      sg S g }|j                  dt	        j
                  |            }t        j                         j                  d      }t        j                  j                  t        j                  j                  t        j                  j                  t        j                  j                  t        j                  j                  g}t        j                  t	        j                  |            r$|j!                  t	        j
                  |             |t"        j$                  k(  rC|j'                  t        j                  j(                  t        j                  j*                  g       |t        j                  j,                  k(  rI| j.                  j0                  j3                  |      }|j!                  t4        j6                  |z         |S |t"        j8                  k(  r8|j                  dd      s&||vr"|j!                   | j:                  |fi |       |S )a   Returns the role name for the object in an array of strings, with
        the exception that the Atspi.Role.UNKNOWN role will yield an
        empty array.  Note that a 'role' attribute in args will
        override the accessible role of the obj.
        isProgressBarUpdatebrailleProgressBarUpdatesrolebrailleVerbosityLevel
readingRowF)rG   r   rB   rC   r   get_roler   RoleUNKNOWNREDUNDANT_OBJECTFILLEREXTENDEDLINKr   is_list_boxrN   appendr   VERBOSITY_LEVEL_BRIEFextendICONCANVASHEADINGrJ   rK   headingLevelr   ROLE_HEADING_LEVEL_BRAILLEVERBOSITY_LEVEL_VERBOSEgetLocalizedRoleName)r   r7   rT   rU   r]   verbosityLeveldoNotPresentlevels           r   _generateRoleNamez"BrailleGenerator._generateRoleName   s    88)*#..0;;<WXIxx 1 1# 67)446AABYZ

**

33

))

++

	) ""8#6#6s#;< 1 1# 67X;;;%**2C2C DE5::%%%LL**77<EMM+FFNO
  x???88L%0T5MMM3$33C@4@Ar   c                    t        j                         j                  d      t        j                  k(  r>|j                  dt        j                  |            }t        j
                  |      }|r|S t        | (  |fi |S )zReturns the localized name of the given Accessible object; the name
        is suitable to be brailled.

        Arguments:
        - obj: an Accessible object
        brailleRolenameStyler]   )r   rB   rC   r   BRAILLE_ROLENAME_STYLE_SHORTrG   r   r`   r   superrq   )r   r7   rT   r]   rv	__class__s        r   rq   z%BrailleGenerator.getLocalizedRoleName   ss     &&(334JK88988FH$5$5c$:;D##D)B	w+C8488r   c                     g }| j                   j                  j                  |      }|D ]&  } | j                  |fi |}|j	                  |       ( |S r   )rJ   rK   unrelatedLabels_generateNamerj   )r   r7   rT   rU   labelslabelnames          r   _generateUnrelatedLabelsz)BrailleGenerator._generateUnrelatedLabels   sZ    ''77< 	 E%4%%e4t4DMM$	  r   c                     t        j                         j                  d      }|t        j                  k(  rg S g }| j
                  j                  j                  |      \  }}}|r|j                  d|z   dz          |S )zReturns 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.
        r^   ())	r   rB   rC   r   ri   rJ   rK   mnemonicShortcutAcceleratorrh   )r   r7   rT   rr   rU   mnemonicshortcutaccelerators           r   _generateAcceleratorz%BrailleGenerator._generateAccelerator   sw     *446AABYZX;;;ILL"">>sC 	*8[MM#+c12r   c                     g }	 | j                   j                  j                  |      }|dkD  r$|j	                  t        j                  |             |S # t        $ r d}Y 8w xY w)zReturns 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   )rJ   rK   unfocusedAlertAndDialogCountrI   rh   r
   dialogCountBraille)r   r7   rT   rU   alertAndDialogCounts        r   _generateAlertAndDialogCountz-BrailleGenerator._generateAlertAndDialogCount   si    
 	$&&CCCH   "]]8667JKL  	$"#	$s   %A A"!A"c                    g }t        j                         j                  d      s|S d|d<   |j                  dt	        j
                  |            }|t        j                  j                  k(  }t	        j                  |      }|r6t	        j
                  |      | j                  v rt	        j                  |      }|rg }t	        j
                  |      }|t        j                  j                  k7  r|t        j                  j                  k7  r|t        j                  j                  k7  rw|t        j                  j                  k7  rZ|t        j                  j                  k7  r=| j                   j"                  j%                  |      s||d<    | j&                  |fi |}|t        j                  j                  t        j                  j(                  fv rr| j                   j"                  j+                  |      }|rKt-        |      r@|j/                         s0|s,t	        j
                  |      |d<    | j&                  |fi |}nd}|r&|r$|j1                  t3        j4                  d             |j7                  |       |t        j                  j8                  k(  rnt	        j                  |      }|r|j;                          |S )aE  Returns 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]   r   )r   rB   rC   rG   r   r`   r   ra   RADIO_BUTTONget_parent_checkedSKIP_CONTEXT_ROLESrd   INVALIDSECTION
SPLIT_PANEDESKTOP_FRAMErJ   rK   isLayoutOnlyrH   PANELdisplayedLabelrS   isspacerh   r   r,   rj   EMBEDDEDreverse)	r   r7   rT   rU   r]   excludeRadioButtonGroupparentparentResultr   s	            r   _generateAncestorsz#BrailleGenerator._generateAncestors  s+    **,778NOM!& xx 1 1# 67"&%***A*A"A,,S1x((0D4K4KK008FL $$V,Duzz(((EJJ...EJJ...EJJ111EJJ444..;;FC#V,t}}V<t< 

))5::+;+;<<..==fESZ2'/'8'8'@V'4t}}V'Dt'D27/,gnnS12MM,'uzz***008FM N 	r   c                    g }|j                  dt        j                  |            }|t        j                  j
                  t        j                  j                  fvr|S t        j                  |      r&| j                  j                  j                  |      }nt        j                  |      g}|r|d   s|S t        | j                  |      D ]  }|j                  |        |S )Nr]   r   )rG   r   r`   r   ra   LISTLIST_BOXsupports_selectionrJ   rK   selectedChildrenr   get_focused_objectmapr~   rj   )r   r7   rT   rU   r]   itemsitems          r   _generateFocusedItemz%BrailleGenerator._generateFocusedItemJ  s    xx 1 1# 67

)<)<==M&&s+LL**;;C@E 33C89E%(M**E2 	 DMM$	  r   c                     | j                   j                  j                  |      }|dk  rg S dt        j                  |       dgS )Nr   r   r   )rJ   rK   getValueCountForTermr
   valueCountForTerm)r   r7   rT   counts       r   _generateTermValueCountz(BrailleGenerator._generateTermValueCount\  sF    &&;;C@19IH..u56a899r   c                 :   t        j                  |      sg S | j                  j                  j	                  |      }|r||gk(  rg S g }|D ]M  }| j                  |d      }|s|j                  |       |j                  t        j                  d             O |S NF)r   r   )
r   is_status_barrJ   rK   statusBarItemsrH   rj   rh   r   r,   )r   r7   rT   r   rU   childchildResults          r   _generateStatusBarz#BrailleGenerator._generateStatusBarc  s    ((-I&&55c:#I 	3E--e-DKk*gnnS12		3 r   c                    t        j                  t        j                  |            sg S g }t        j                  |      D ]H  }|j                  | j                  |d             |j                  t        j                  d             J |S r   )
r   rg   r   rN   get_all_widgetsrj   rH   rh   r   r,   )r   r7   rT   rU   widgets        r   _generateListBoxItemWidgetsz,BrailleGenerator._generateListBoxItemWidgetst  st    &&x':':3'?@I!11#6 	/FMM$--u-EFMM'..-.	/ r   c                     |j                  d      r | j                  |fi |sg S | j                         \  }}}||k7  r| j                  |      \  }}| gS g S )Nr[   )rG   _shouldPresentProgressBarUpdate_getMostRecentProgressBarUpdategetProgressBarNumberAndCount)r   r7   rT   acc
updateTimeupdateValuenumberr   s           r   _generateProgressBarIndexz*BrailleGenerator._generateProgressBarIndex~  sh    xx-.6$66sCdCI'+'K'K'M$Z#: ==cBMFEh= 	r   c                     |j                  d      r | j                  |fi |sg S  | j                  |fi |}|t        j                         j                         k(  r|sdgS |S )Nr[    )rG   r   _generatePercentager   rB   rF   )r   r7   rT   rU   s       r   _generateProgressBarValuez*BrailleGenerator._generateProgressBarValue  sh    88)*7477DtDI)))#66-**,??AA&4Kr   c                 @    t        j                  |      }|| dgS g S )N%)r   get_value_as_percent)r   r7   rT   percents       r   r   z$BrailleGenerator._generatePercentage  s+    ..s3iqM?"	r   c                     t        j                         j                  d      }|t        |          S t        |      S )NprogressBarBrailleInterval)r   rB   rC   ry   _getProgressBarUpdateIntervalint)r   intervalr{   s     r   r   z.BrailleGenerator._getProgressBarUpdateInterval  s;    #..0;;<XY78::8}r   c                 l    t        j                         j                  d      syt        |   |fi |S )Nr\   F)r   rB   rC   ry   r   )r   r7   rT   r{   s      r   r   z0BrailleGenerator._shouldPresentProgressBarUpdate  s3    **,778STw6sCdCCr   c                 8   g }| j                   j                  j                  |      }|D ]%  }|j                   | j                  |fi |        n |sF| j                  d|      }|j                   | j                  |fi |       | j                  ||       |S )zIf 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.
        REAL_ROLE_SCROLL_PANE)rJ   rK   labelsForObjectrj   rH   _overrideRole_restoreRole)r   r7   rT   rU   r   r   oldRoles          r   _generateAsPageTabOrScrollPanez/BrailleGenerator._generateAsPageTabOrScrollPane  s     ''77< 	EMM-$--667	  (()@$GGMM-$--4t45gt,r   c                    |j                  d      ryt        j                         j                  d      }|s|S | j                  j
                  j                  |      st        j                  |      rt        j                  |      d   dk(  }|ret        j                  |t        j                  j                        }|r5| j                  j
                  j                  |j!                  d             }|S )z]Returns True or False to indicate whether context should be
        included or not.
        r[   Fr   r   r   )rG   r   rB   rC   rJ   rK   
isTextArear   is_labelr   get_line_at_offsetr   get_relationr   RelationType
FLOWS_FROM
get_target)r   r7   rT   includerelations        r   _generateIncludeContextz(BrailleGenerator._generateIncludeContext  s    
 88)* #--/::;QRN<<!!,,S1[5I5I#5N//4Q71<G#00e6H6H6S6ST"&,,"8"8"C"CHDWDWXYDZ"[[Gr   c                 ^   t        j                         j                  d      rg S t        j                  |      s'| j
                  j                  j                  |      sg S |j                  dd       s| j                  |d<   d|d<    | j
                  j                  j                  di |gS )NdisableBrailleEOLmodeeol
stringTyper#   )r   rB   rC   r   is_editablerJ   rK   isCoderG   _mode
formatting	getString)r   r7   rT   s      r   _generateEolzBrailleGenerator._generateEol  s    &&(334GHI'',0F0F0M0Mc0RIxx%::DL"\1''119D9::r   c                 0    |dk(  rt         S t        |      gS )Nr   )SPACEr   r   s     r   r*   zBrailleGenerator.space  s    L)$%%r   c                    d}d }t        |t              r|}|S |rt        |t              r|r.t        |d   t              r|dd  }|rt        |d   t              r|r.t        |d   t              r|dd }|rt        |d   t              r|D ]^  }t        |t              r|r||j                  z  }d }'| j                  |      }| j                  j                  j                  |||      }` |S )Nr   r   r   )	r3   strrP   r   r   r/   rJ   rK   appendString)r   contentr   combinedpriorelements         r   r/   zBrailleGenerator.asString  s    gs#H   GT2 jU;!!"+ jU;je<!!B- je<" 4gu-% 1 11H E MM'2E#||55BB % 4H4 r   r   )&r   r    r!   r"   r   ra   MENUMENU_BARPAGE_TAB_LISTrc   rb   	COMBO_BOXr   r   r0   r9   rY   ru   rq   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r*   r/   __classcell__)r{   s   @r   r%   r%   7   s    =
  **//**--**22**55**,,**..0>	0N4'x#J9". EN$:"
	D.<
;&r   r%   )!r"   __id____version____date____copyright____license__girequire_versiongi.repositoryr   r   r   r   r   r	   r
   r   r   r   	ax_objectr   ax_textr   ax_utilitiesr   ax_valuer   braille_rolenamesr   r   r   r'   r%   r#   r   r   <module>r     s   ( A? 	   7E "            %  -# # 
	Sy** Sr   