
    g
f_                     .   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 G d d      Z e       Zd Zy)zModule for flat-review commandsz$Id$z
$Revision$z$Date$zQCopyright (c) 2005-2008 Sun Microsystems Inc.Copyright (c) 2016-2023 Igalia, S.L.LGPL    NGtkz3.0)r      )braille)cmdnames)debug)flat_review)focus_manager)	guilabels)input_event)keybindings)messages)
orca_state)script_manager)settings_manager)settingsc                      e Zd ZdZd Zd Zd5dZd6dZd Zd7dZ	d	 Z
d
 Zd Zd Zd8dZd8dZd5dZd5dZd5dZd5dZd5dZd5dZd5dZd5dZd5dZd5dZd5dZd5dZd9dZd5dZd5dZd5dZd5dZ d5d Z!d5d!Z"d5d"Z#d5d#Z$d5d$Z%d5d%Z&d5d&Z'd5d'Z(d5d(Z)d5d)Z*d5d*Z+d5d+Z,d5d,Z-d5d-Z.d5d.Z/d5d/Z0d5d0Z1d5d1Z2d:d2Z3d;d3Z4d:d4Z5y)<FlatReviewPresenterz5Provides access to on-screen objects via flat-review.c                    d | _         d| _        t        j                         j	                  d      | _        | j                  d      | _        t        j                         | _
        t        j                         | _        d | _        y )N flatReviewIsRestrictedT)_context_current_contentsr   
getManager
getSetting	_restrictget_handlers	_handlersr   KeyBindings_desktop_bindings_laptop_bindings_guiselfs    </usr/lib/python3/dist-packages/orca/flat_review_presenter.py__init__zFlatReviewPresenter.__init__5   sh    !#)446AABZ[**40!,!8!8!: + 7 7 9	    c                     | j                   duS )z4Returns True if the flat review presenter is active.N)r   r#   s    r%   	is_activezFlatReviewPresenter.is_active>   s     }}D((r'   Nc                 J   | j                   sd| j                   }t        j                  t        j                  |d       | j                  rBt        j                         j                         \  }}t        j                  ||      | _         nt        j                  |      | _         t        j                         j                  | j                   j                         t
        j                         |d|_        |j                         |_        | j                   S d| j                   }t        j                  t        j                  |d       t        j                         j                         \  }}|xs" t        j                         j!                         }|t
        j                  k7  r|| j                   j                         k7  rj| j                  s^d| j                   j                         d|g}t        j"                  t        j                  |d       | j                   j%                  |       | j                  rU|t
        j                  k7  rBd}t        j                  t        j                  |d       t        j                  ||      | _         | j                   S )	z;Returns the flat review context, creating one if necessary.z7FLAT REVIEW PRESENTER: Creating new context. Restrict: T)rootmodez9FLAT REVIEW PRESENTER: Using existing context. Restrict: z9FLAT REVIEW PRESENTER: Attempting to update location fromtoz7FLAT REVIEW PRESENTER: Creating new restricted context.)r   r   r   printMessage
LEVEL_INFOr
   r   &get_active_mode_and_object_of_interestr	   Contextemit_region_changedgetCurrentAccessibleFLAT_REVIEWjustEnteredFlatReviewModegetBrailleCursorCelltargetCursorCellget_locus_of_focusprintTokenssetCurrentToZoneWithObject)r$   scriptmsgr-   objtokenss         r%   get_or_create_contextz)FlatReviewPresenter.get_or_create_contextC   s    }}KDNNK[\Cu//d;~~)446]]_	c + 3 3F E + 3 3F ;$$&::224=;T;T ; V!370*0*E*E*G'== I$..IYZ5++S$7 ",,.UUW	cD]--/BBD=,,,8Z8Z8\1\>>Qmm88:D#GFe..=MM44S9 >>dm&?&??KCu//d;'//<DM}}r'   c                 \   |r8d}t        j                  t         j                  |d       | j                          nY|r+| j                  j                         r| j                          n,|s*| j                  j                         r| j                          |r| j                  S | j                  S )z.Returns the flat-review-presenter keybindings.z+FLAT REVIEW PRESENTER: Refreshing bindings.T)r   r/   r0   _setup_bindingsr    isEmptyr!   )r$   refresh
is_desktopr=   s       r%   get_bindingsz FlatReviewPresenter.get_bindingsx   s     ?Cu//d;  "D22::<  " 5 5 = = ?  ")))$$$r'   c                    i }	 | j                   j                  d      |t        j                  j                  <   | j                   j                  d      |t        j                  j
                  <   | j                   j                  d      |t        j                  j                  <   | j                   j                  d      |t        j                  j                  <   | j                   j                  d      |t        j                  j                  <   |S # t        $ r5}d|g}t        j                  t        j                  |d       i cY d}~S d}~ww xY w)	z3Returns the flat-review-presenter braille bindings.reviewAboveHandlerreviewBelowHandlertoggleFlatReviewModeHandlerreviewHomeHandlerreviewBottomLeftHandlerz:FLAT REVIEW PRESENTER: Exception getting braille bindings:TN)r   getr   brlapiKEY_CMD_LNUPKEY_CMD_LNDNKEY_CMD_FREEZEKEY_CMD_TOP_LEFTKEY_CMD_BOT_LEFT	Exceptionr   r:   r0   )r$   bindingserrorr?   s       r%   get_braille_bindingsz(FlatReviewPresenter.get_braille_bindings   s    	""#78 W^^001 ""#78 W^^001 ""#@A W^^223 ""#67 W^^445 ""#<= W^^445 	  	RTYZFe..=I	s   DD 	E*EEEc                     |r7d}t        j                  t         j                  |d       | j                          | j                  S )z+Returns the flat-review-presenter handlers.z*WHERE AM I PRESENTER: Refreshing handlers.T)r   r/   r0   _setup_handlersr   )r$   rD   r=   s      r%   r   z FlatReviewPresenter.get_handlers   s:     >Cu//d;  "~~r'   c                 D    | j                          | j                          y)z/Sets up the flat-review-presenter key bindings.N)_setup_desktop_bindings_setup_laptop_bindingsr#   s    r%   rB   z#FlatReviewPresenter._setup_bindings   s     	$$&##%r'   c                 H   i | _         t        j                  | j                  t        j
                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   t        j                  | j                  t        j                        | j                   d<   t        j                  | j                   t        j"                        | j                   d<   t        j                  | j$                  t        j&                        | j                   d<   t        j                  | j(                  t        j*                        | j                   d	<   t        j                  | j,                  t        j.                        | j                   d
<   t        j                  | j0                  t        j2                        | j                   d<   t        j                  | j4                  t        j6                        | j                   d<   t        j                  | j8                  t        j:                        | j                   d<   t        j                  | j<                  t        j>                        | j                   d<   t        j                  | j@                  t        jB                        | j                   d<   t        j                  | jD                  t        jF                        | j                   d<   t        j                  | jH                  t        jJ                        | j                   d<   t        j                  | jL                  t        jN                        | j                   d<   t        j                  | jP                  t        jR                        | j                   d<   t        j                  | jT                  t        jV                        | j                   d<   t        j                  | jX                  t        jZ                        | j                   d<   t        j                  | j\                  t        j^                        | j                   d<   t        j                  | j`                  t        jb                        | j                   d<   t        j                  | jd                  t        jf                        | j                   d<   t        j                  | jh                  t        jj                        | j                   d<   t        j                  | jl                  t        jn                        | j                   d<   t        j                  | jp                  t        jr                        | j                   d<   t        j                  | jt                  t        jv                        | j                   d<   d}ty        jz                  tx        j|                  |d       y) z7Sets up the flat-review-presenter input event handlers.rJ   rK   reviewEndHandlerrL   reviewPreviousLineHandlerreviewCurrentLineHandlerreviewNextLineHandlerreviewSpellCurrentLineHandler reviewPhoneticCurrentLineHandlerreviewEndOfLineHandlerreviewPreviousItemHandlerreviewCurrentItemHandlerreviewNextItemHandlerreviewSpellCurrentItemHandler reviewPhoneticCurrentItemHandlerreviewPreviousCharacterHandlerreviewCurrentCharacterHandler"reviewSpellCurrentCharacterHandler$reviewUnicodeCurrentCharacterHandlerreviewNextCharacterHandlerreviewCurrentAccessibleHandlerrH   rI   showContentsHandlerflatReviewCopyHandlerflatReviewAppendHandlerflatReviewSayAllHandlerflatReviewToggleRestrictHandlerz'FLAT REVIEW PRESENTER: Handlers set up.TN)?r   r   InputEventHandlertoggle_flat_review_moder   TOGGLE_FLAT_REVIEWgo_homeREVIEW_HOMEgo_end
REVIEW_ENDgo_bottom_leftREVIEW_BOTTOM_LEFTgo_previous_lineREVIEW_PREVIOUS_LINEpresent_lineREVIEW_CURRENT_LINEgo_next_lineREVIEW_NEXT_LINE
spell_lineREVIEW_SPELL_CURRENT_LINEphonetic_lineREVIEW_PHONETIC_CURRENT_LINEgo_end_of_lineREVIEW_END_OF_LINEgo_previous_itemREVIEW_PREVIOUS_ITEMpresent_itemREVIEW_CURRENT_ITEMgo_next_itemREVIEW_NEXT_ITEM
spell_itemREVIEW_SPELL_CURRENT_ITEMphonetic_itemREVIEW_PHONETIC_CURRENT_ITEMgo_previous_characterREVIEW_PREVIOUS_CHARACTERpresent_characterREVIEW_CURRENT_CHARACTERspell_characterREVIEW_SPELL_CURRENT_CHARACTERunicode_current_character REVIEW_UNICODE_CURRENT_CHARACTERgo_next_characterREVIEW_NEXT_CHARACTERpresent_objectREVIEW_CURRENT_ACCESSIBLEgo_aboveREVIEW_ABOVEgo_belowREVIEW_BELOWshow_contentsFLAT_REVIEW_SHOW_CONTENTScopy_to_clipboardFLAT_REVIEW_COPYappend_to_clipboardFLAT_REVIEW_APPENDsay_allSAY_ALL_FLAT_REVIEWtoggle_restrictTOGGLE_RESTRICT_FLAT_REVIEWr   r/   r0   r$   r=   s     r%   rY   z#FlatReviewPresenter._setup_handlers   sx     )),,++- 	45 ))$$& 	*+ ))##% 	)* ))##++- 	01 ))%%--/ 	23 ))!!,,. 	12 ))!!))+ 	./ ))224 	67 ))""557 	9: ))##++- 	/0 ))%%--/ 	23 ))!!,,. 	12 ))!!))+ 	./ ))224 	67 ))""557 	9: ))**224 	78 ))&&113 	67 ))$$779 	;< ))..99; 	=> ))&&..0 	34 ))##224 	78 ))%%' 	+, ))%%' 	+, ))""224 	,- ))&&))+ 	./ ))((++- 	01 )),,. 	01 ))$$446 	89
 85++S$7r'   c           
         t        j                         | _        | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  d	t         j
                  t         j                  | j                  j                  d
      d             | j                  j                  t        j                  d	t         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  d	t         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  d t         j
                  t         j                  | j                  j                  d!      d             | j                  j                  t        j                  d t         j
                  t         j                  | j                  j                  d"      d             | j                  j                  t        j                  d t         j
                  t         j                  | j                  j                  d#      d             | j                  j                  t        j                  d$t         j
                  t         j                  | j                  j                  d%                   | j                  j                  t        j                  d&t         j
                  t         j                  | j                  j                  d'                   | j                  j                  t        j                  d&t         j
                  t         j                  | j                  j                  d(                   | j                  j                  t        j                  d&t         j
                  t         j                  | j                  j                  d)                   | j                  j                  t        j                  d&t         j
                  t         j                  | j                  j                  d*                   d+}t        j                  t        j                  |d,       y-).z7Sets up the flat-review-presenter desktop key bindings.KP_SubtractrJ   KP_Addrs      KP_HomerK   r_   KP_Upr`   r   rb   rc      
KP_Page_Upra   r^   KP_Leftre   rH   KP_Beginrf   rh   ri   ro   KP_Rightrg   rI   KP_Endrj   rd   KP_Downrk   rl   rm   KP_Page_Downrn   r   rp   rq   rr   rt   z/FLAT REVIEW PRESENTER: Desktop bindings set up.TN)r   r   r    add
KeyBindingdefaultModifierMaskNO_MODIFIER_MASKr   rM   ORCA_MODIFIER_MASKr   r/   r0   r   s     r%   r[   z+FlatReviewPresenter._setup_desktop_bindingsA  sd    "-!8!8!:""""//,,""#@A	C	D 	""""//,,""#<=	 	""""//..""#67	9	: 	""""//,,""#>?	A	B 	""""//,,""#=>	 	""""//,,""#BC	 	""""//,,""#EF	 	""""//,,""#:;	=	> 	""""//..""#56	8	9 	""""//,,""#>?	A	B 	""""//..""#78	:	; 	""""//,,""#=>	 	""""//,,""#BC	 	""""//,,""#EF	 	""""//..""#CD	F	G 	""""//,,""#:;	=	> 	""""//..""#78	:	; 	""""//,,""#CD	F	G 	""""//..""#;<	>	? 	""""//,,""#BC	 	""""//,,""#GH	 	""""//,,""#IJ	 	""""//,,""#?@	B	C 	""""//,,""#89	;	< 	""""//,,""#:;	=	> 	""""//,,""#<=	?	@ 	""""//,,""#DE	G	H @5++S$7r'   c           
         t        j                         | _        | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  d	t         j
                  t         j                  | j                  j                  d
      d             | j                  j                  t        j                  d	t         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  d	t         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d      d             | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   | j                  j                  t        j                  d t         j
                  t         j                  | j                  j                  d!      d             | j                  j                  t        j                  d t         j
                  t         j                  | j                  j                  d"      d             | j                  j                  t        j                  d t         j
                  t         j                  | j                  j                  d#      d             | j                  j                  t        j                  d$t         j
                  t         j                  | j                  j                  d%                   | j                  j                  t        j                  d&t         j
                  t         j                  | j                  j                  d'                   | j                  j                  t        j                  d&t         j
                  t         j                  | j                  j                  d(                   | j                  j                  t        j                  d&t         j
                  t         j                  | j                  j                  d)                   | j                  j                  t        j                  d&t         j
                  t         j                  | j                  j                  d*                   d+}t        j                  t        j                  |d,       y-).zBSets up and returns the flat-review-presenter laptop key bindings.prJ   	semicolonrs   r   ur_   rK   ir`   r   rb   rc   r   ora   r^   jre   rH   krf   rh   ri   ro   lrg   rI   mrj   rd   commark   rl   rm   periodrn   r   rp   rq   rr   rt   z.FLAT REVIEW PRESENTER: Laptop bindings set up.TN)r   r   r!   r   r   r   r   r   rM   ORCA_CTRL_MODIFIER_MASKr   r   r/   r0   r   s     r%   r\   z*FlatReviewPresenter._setup_laptop_bindings  sc    !, 7 7 9!!""//..""#@A	C	D 	!!""//..""#<=	 	!!""//..""#>?	A	B 	!!""//33""#67	9	: 	!!""//..""#=>	 	!!""//..""#BC	 	!!""//..""#EF	 	!!""//..""#:;	=	> 	!!""//33""#56	8	9 	!!""//..""#>?	A	B 	!!""//33""#78	:	; 	!!""//..""#=>	 	!!""//..""#BC	 	!!""//..""#EF	 	!!""//33""#CD	F	G 	!!""//..""#:;	=	> 	!!""//33""#78	:	; 	!!""//..""#CD	F	G 	!!""//33""#;<	>	? 	!!""//..""#BC	 	!!""//..""#GH	 	!!""//..""#IJ	 	!!""//..""#?@	B	C 	!!""//,,""#89	;	< 	!!""//,,""#:;	=	> 	!!""//,,""#<=	?	@ 	!!""//,,""#DE	G	H ?5++S$7r'   c                 
   | j                   r(d}t        j                  t        j                  |d       yd}t        j                  t        j                  |d       |"t	        j
                         j                         }| j                  |       |yt        j
                         j                  d      t        j                  k7  r|j                  t        j                         | j                  |||j                          y)zStarts flat review.z-FLAT REVIEW PRESENTER: Already in flat reviewTNz+FLAT REVIEW PRESENTER: Starting flat reviewspeechVerbosityLevel)r   r   r/   r0   r   r   getActiveScriptr@   r   r   r   VERBOSITY_LEVEL_BRIEFpresentMessager   FLAT_REVIEW_START_item_presentationr8   )r$   r<   eventr=   s       r%   startzFlatReviewPresenter.start  s     ==ACu//d;;5++S$7>#..0@@BF""6*=&&(334JK,,-!!("<"<=v/F/FGr'   c                 D   | j                   (d}t        j                  t        j                  |d       yd}t        j                  t        j                  |d       d| _         t	        j
                         j                         }t	        j
                         j                  |t        j                         ||yt        j
                         j                  d      t        j                  k7  r|j                  t        j                         |j!                  |       y)zQuits flat review.Nz)FLAT REVIEW PRESENTER: Not in flat reviewTz+FLAT REVIEW PRESENTER: Quitting flat reviewr,   r   )r   r   r/   r0   r
   r   r9   r3   FOCUS_TRACKINGr   r   r   r   r   r   FLAT_REVIEW_STOPupdateBraille)r$   r<   r   r=   focuss        r%   quitzFlatReviewPresenter.quit  s     == =Cu//d;;5++S$7((*==?  "66u=C_C_6`=FN&&(334JK,,-!!(";";<U#r'   c                 n    | j                         r| j                  ||       y| j                  ||       y)z9Toggles between flat review mode and focus tracking mode.T)r)   r   r   r$   r<   r   s      r%   rv   z+FlatReviewPresenter.toggle_flat_review_mode  s0     >>IIfe$

65!r'   c                     | j                  |      | _        | j                  j                  t        j                  j
                         | j                  ||       |j                         |_        y)z,Moves to the top left of the current window.T)	r@   r   goBeginr	   r2   WINDOWr   r7   r8   r   s      r%   rx   zFlatReviewPresenter.go_home  sX     226:k11889&%("("="="?r'   c                     | j                  |      | _        | j                  j                  t        j                  j
                         | j                  ||       |j                         |_        y)z0Moves to the bottom right of the current window.T)	r@   r   goEndr	   r2   r   r   r7   r8   r   s      r%   rz   zFlatReviewPresenter.go_end  sX     226:K//667&%("("="="?r'   c                 J   | j                  |      | _        | j                  j                  t        j                  j
                         | j                  j                  t        j                  j                         | j                  ||       |j                         |_
        y)z/Moves to the bottom left of the current window.T)r@   r   r   r	   r2   r   r   LINEr   r7   r8   r   s      r%   r|   z"FlatReviewPresenter.go_bottom_left(  sv     226:K//667k11667&%("("="="?r'   c                    | j                  |      | _        | j                  j                  t        j                  j
                  t        j                  j                        r'| j                  ||       |j                         |_	        y)zMoves to the previous line.T)
r@   r   
goPreviousr	   r2   r   	WRAP_LINEr   r7   r8   r   s      r%   r~   z$FlatReviewPresenter.go_previous_line2  f     226:==##K$7$7$<$<k>Q>Q>[>[\fe,&,&A&A&CF#r'   c                 *    | j                  ||d       y)Presents the current line.r   T_line_presentationr   s      r%   r   z FlatReviewPresenter.present_line;       	q1r'   c                    | j                  |      | _        | j                  j                  t        j                  j
                  t        j                  j                        r'| j                  ||       |j                         |_	        y)zMoves to the next line.T)
r@   r   goNextr	   r2   r   r   r   r7   r8   r   s      r%   r   z FlatReviewPresenter.go_next_lineA  sf     226:== 3 3 8 8+:M:M:W:WXfe,&,&A&A&CF#r'   c                 *    | j                  ||d       y)z+Presents the current line letter by letter.r   Tr   r   s      r%   r   zFlatReviewPresenter.spell_lineJ  r   r'   c                 *    | j                  ||d       y)z8Presents the current line letter by letter phonetically.r   Tr   r   s      r%   r   z!FlatReviewPresenter.phonetic_lineP  r   r'   c                     | j                  |      | _        | j                  j                  t        j                  j
                         | j                  ||       |j                         |_        y)z+Moves to the beginning of the current line.T	r@   r   r   r	   r2   r   r   r7   r8   r   s      r%   go_start_of_linez$FlatReviewPresenter.go_start_of_lineV  X     226:K//445vu-"("="="?r'   c                     | j                  |      | _        | j                  j                  t        j                  j
                         | j                  ||       |j                         |_        y)zMoves to the end of the line.Tr   r   s      r%   r   z"FlatReviewPresenter.go_end_of_line_  r   r'   c                    | j                  |      | _        | j                  j                  t        j                  j
                  t        j                  j                        r'| j                  ||       |j                         |_	        y)z#Moves to the previous item or word.T)
r@   r   r   r	   r2   WORDr   r   r7   r8   r   s      r%   r   z$FlatReviewPresenter.go_previous_itemh  r   r'   c                 ,    | j                  |||d       y)Presents the current item/word.r   T)r   )r$   r<   r   target_cursor_cells       r%   r   z FlatReviewPresenter.present_itemq  s     	/A1Er'   c                    | j                  |      | _        | j                  j                  t        j                  j
                  t        j                  j                        r'| j                  ||       |j                         |_	        y)zMoves to the next item or word.T)
r@   r   r   r	   r2   r   r   r   r7   r8   r   s      r%   r   z FlatReviewPresenter.go_next_itemw  sf     226:== 3 3 8 8+:M:M:W:WXfe,&,&A&A&CF#r'   c                 @    | j                  |||j                  d       y)z0Presents the current item/word letter by letter.r   Tr   r8   r   s      r%   r   zFlatReviewPresenter.spell_item  !     	v/F/FJr'   c                 @    | j                  |||j                  d       y)z8Presents the current word letter by letter phonetically.r   Tr   r   s      r%   r   z!FlatReviewPresenter.phonetic_item  r  r'   c                    | j                  |      | _        | j                  j                  t        j                  j
                  t        j                  j                        r'| j                  ||       |j                         |_	        y)z Moves to the previous character.T)
r@   r   r   r	   r2   CHARr   r   r7   r8   r   s      r%   r   z)FlatReviewPresenter.go_previous_character  sf     226:==##K$7$7$<$<k>Q>Q>[>[\""651&,&A&A&CF#r'   c                 *    | j                  ||d       y)Presents the current character.r   T_character_presentationr   s      r%   r   z%FlatReviewPresenter.present_character       	$$VUA6r'   c                    | j                  |      | _        | j                  j                  t        j                  j
                  t        j                  j                        r'| j                  ||       |j                         |_	        y)zMoves to the next character.T)
r@   r   r   r	   r2   r  r   r   r7   r8   r   s      r%   r   z%FlatReviewPresenter.go_next_character  sf     226:== 3 3 8 8+:M:M:W:WX""651&,&A&A&CF#r'   c                 *    | j                  ||d       y)z,Presents the current character phonetically.r   Tr  r   s      r%   r   z#FlatReviewPresenter.spell_character  r	  r'   c                 *    | j                  ||d       y)z/Presents the current character's unicode value.r   Tr  r   s      r%   r   z-FlatReviewPresenter.unicode_current_character  r	  r'   c                    | j                  |      | _        | j                  j                  t        j                  j
                  t        j                  j                        r| j                  |||j                         y)zMoves to the character above.T)	r@   r   goAbover	   r2   r  r   r   r8   r   s      r%   r   zFlatReviewPresenter.go_above  ]     226:==  !4!4!9!9;;N;N;X;XYfeV-D-DEr'   c                    | j                  |      | _        | j                  j                  t        j                  j
                  t        j                  j                        r| j                  |||j                         y)zMoves to the character below.T)	r@   r   goBelowr	   r2   r  r   r   r8   r   s      r%   r   zFlatReviewPresenter.go_below  r  r'   c                 b    | j                  |      | _        | j                  j                         S )z&Returns the current accessible object.)r@   r   r4   r   s      r%   get_current_objectz&FlatReviewPresenter.get_current_object  s)     226:}}1133r'   c                 P   | j                  |      | _        t        |t        j                        s+|j                  | j                  j                         d       t        j                         j                  | j                  j                         t        j                         y)z'Presents the current accessible object.T)
speechonlyr,   )r@   r   
isinstancer   BrailleEventpresentObjectr4   r
   r   r3   r5   r   s      r%   r   z"FlatReviewPresenter.present_object  s     226:%!9!9:  !C!C!ERV W  "66MM..0}7P7P 	7 	Rr'   c                 d    | j                  |      | _        | j                  j                  d      S )>Attempts to synthesize a left click on the current accessible.r   r@   r   clickCurrentr   s      r%   left_click_on_objectz(FlatReviewPresenter.left_click_on_object  +     226:}}))!,,r'   c                 d    | j                  |      | _        | j                  j                  d      S )r  r   r  r   s      r%   right_click_on_objectz)FlatReviewPresenter.right_click_on_object  r  r'   c                 b    | j                  |      | _        | j                  j                         S )z3Routes the mouse pointer to the current accessible.)r@   r   routeToCurrentr   s      r%   route_pointer_to_objectz+FlatReviewPresenter.route_pointer_to_object  s)     226:}}++--r'   c                 p    | j                  |      | _        | j                  j                         \  }}||gS )zAReturns the braille regions and region with focus being reviewed.)r@   r   getCurrentBrailleRegions)r$   r<   r   regionsfocused_regions        r%   get_braille_regionsz'FlatReviewPresenter.get_braille_regions  s8     226:"&--"H"H"J((r'   c                 \   g }| j                  |      | _        | j                  j                  t        j                  j
                         | j                  j                  t        j                  j                        d   }||j                  |j                  d             | j                  j                  t        j                  j                  t        j                  j                        s	 |S | j                  j                  t        j                  j                        d   }||S )z:Returns a list of textual lines representing the contents.r   
)r@   r   r   r	   r2   r   
getCurrentr   appendrstripr   r   )r$   r<   r   linesstrings        r%   _get_all_linesz"FlatReviewPresenter._get_all_lines  s     226:k11889))+*=*=*B*BCAF LLt,-==''(;(;(@(@+BUBUB_B_` ]]--k.A.A.F.FGJF	  
 r'   c                     | j                  ||      D ]?  }|j                         r|j                  ||j                  j	                  |             A y)z)Speaks the contents of the entire window.r/  T)r0  isspacespeakMessagespeechGeneratorvoice)r$   r<   r   r/  s       r%   r   zFlatReviewPresenter.say_all  sV     ))&%8 	YF>>###FF,B,B,H,HPV,H,WX	Y r'   c                    d}t        j                  t         j                  |d       dj                  | j	                  ||            }t
        j                  }t        |||      | _        | j                  j                          y)z8Displays the entire flat review contents in a text view.z(FLAT REVIEW PRESENTER: Showing contents.Tr*  )
r   r/   r0   joinr0  r   FLAT_REVIEW_CONTENTSFlatReviewContextGUIr"   show_gui)r$   r<   r   r=   texttitles         r%   r   z!FlatReviewPresenter.show_contents  sj     95++S$7yy,,VU;<..(=			r'   c                 
   | j                         s |j                  t        j                         y|j                  j                  | j                  j                  d             |j                  t        j                         y)z2Copies the string just presented to the clipboard.Tr*  )	r)   r   r   FLAT_REVIEW_NOT_IN	utilitiessetClipboardTextr   r-  FLAT_REVIEW_COPIEDr   s      r%   r   z%FlatReviewPresenter.copy_to_clipboard  sa     ~~!!("="=>))$*@*@*G*G*MNh99:r'   c                 
   | j                         s |j                  t        j                         y|j                  j                  | j                  j                  d             |j                  t        j                         y)z3Appends the string just presented to the clipboard.Tr*  )	r)   r   r   r?  r@  appendTextToClipboardr   r-  FLAT_REVIEW_APPENDEDr   s      r%   r   z'FlatReviewPresenter.append_to_clipboard  sa     ~~!!("="=>..t/E/E/L/LT/RSh;;<r'   c                 h   | j                    | _         t        j                         j                  d| j                          | j                   r |j	                  t
        j                         n|j	                  t
        j                         | j                         rd| _	        | j                          y)z? Toggles the restricting of flat review to the current object. r   NT)r   r   r   
setSettingr   r   FLAT_REVIEW_RESTRICTEDFLAT_REVIEW_UNRESTRICTEDr)   r   r   r   s      r%   r   z#FlatReviewPresenter.toggle_restrict$  s|     "^^+##%001I4>>Z>>!!("A"AB!!("C"CD>> DMJJLr'   c                    | j                  |      | _        | j                  j                  t        j                  j
                        d   xs d}|j                  j                  |      }t        |t        j                        s|r|dk(  r |j                  t        j                         n|j                         r |j                  t        j                         n|j!                         r|dk  s|dkD  r|j                  ||       n[|dk(  r|j#                  |       nD|dk(  r|j%                  |       n-|j&                  j)                  |      }|j                  ||       t+        j,                         j/                  | j                  j1                         t*        j2                         |j5                          || _        y)	r   r   r   r2  r*  r   r   r,   T)r@   r   r+  r	   r2   r   r5  r6  r  r   r  r4  r   BLANKr3  WHITE_SPACEisupperspellCurrentItemphoneticSpellCurrentItemr@  adjustForRepeatsr
   r   r3   r4   r5   updateBrailleReviewr   )r$   r<   r   speech_typeline_stringr6  s         r%   r   z&FlatReviewPresenter._line_presentation5  sk    226:mm..{/B/B/G/GHKQr&&,,K,@%!9!9:+"5##HNN3$$&##H$8$89$$&K!O{Q##K7!''4!//<$..??L##K7  "66MM..0}7P7P 	7 	R""$!,r'   c                 V   | j                  |      | _        | j                  j                  t        j                  j
                        d   xs d}|j                  j                  |      }t        |t        j                        s?|r|dk(  r!|j                  t        j                         n| j                  j                  t        j                  j                        d   xs d}|dk(  r |j                  t        j                         n|j                         r |j                  t        j                          n|j#                         r|dk(  r|j                  ||       n`|dk(  r|j%                  |       nI|dk(  r|j'                  |       n2|dk(  r-|j(                  j+                  |      }|j                  ||       t-        j.                         j1                  | j                  j3                         t,        j4                         |j7                  |       || _        y	)
r   r   r   r2  r*  r   r   r   r,   T)r@   r   r+  r	   r2   r   r5  r6  r  r   r  r4  r   rK  r   r3  rL  rM  rN  rO  r@  rP  r
   r   r3   r4   r5   rQ  r   )r$   r<   r   r   rR  word_stringr6  rS  s           r%   r   z&FlatReviewPresenter._item_presentationQ  s    226:mm..{/B/B/G/GHKQr&&,,K,@%!9!9:+"5##HNN3"mm66{7J7J7O7OPQRSYWY$&''7 ((*''(<(<= ((*{a/?''U; A%++K8 A%33K@ A%"("2"2"C"CK"PK''U;  "66MM..0}7P7P 	7 	R""#56!,r'   c                 &   | j                  |      | _        | j                  j                  t        j                  j
                        d   xs d}t        |t        j                        s|s |j                  t        j                         n| j                  j                  t        j                  j                        d   xs d}|dk(  r%|dk7  r |j                  t        j                         n?|dk(  r|j                  |       n(|dk(  r|j                  |       n|j                  |       t!        j"                         j%                  | j                  j'                         t         j(                         |j+                          || _        y)r  r   r   r*  r   r   r,   T)r@   r   r+  r	   r2   r  r  r   r  r4  r   rK  r   speakUnicodeCharacterrO  speakCharacterr
   r   r3   r4   r5   rQ  r   )r$   r<   r   rR  char_stringrS  s         r%   r  z+FlatReviewPresenter._character_presentationp  s8    226:mm..{/B/B/G/GHKQr%!9!9:##HNN3"mm66{7J7J7O7OPQRSYWY$&;!+;''7 A%00= A%33K@))+6  "66MM..0}7P7P 	7 	R""$!,r'   N)FT)F)NN)Nr   )r   )r   r   )6__name__
__module____qualname____doc__r&   r)   r@   rF   rW   r   rB   rY   r[   r\   r   r   rv   rx   rz   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(  r0  r   r   r   r   r   r   r   r   r'   r%   r   r   2   s   ?)
3j% *&R8hM8^M8^H.$,4	--.)
		"8>r'   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)r:  z6Presents the entire flat review context in a text viewc                 @    || _         | j                  ||      | _        y rZ  )_script_create_dialogr"   )r$   r<   r=  r<  s       r%   r&   zFlatReviewContextGUI.__init__  s    ''t4	r'   c                 n   t        j                  |dt         j                  j                  t         j                  t         j
                  j                  f      }|j                  dd       t        j                         }|j                  t         j                  j                  t         j                  j                         t        j                         }|j                  |       |j                  |j                                t        j                   |      }|j#                  t         j$                  j&                         |j)                  |       |j+                  d       |j-                  d       |j/                         j1                  |ddd       |j3                  d| j4                         |S )zCreates the dialog.Ni   iX  )bufferTr   response)r   DialogDialogFlagsMODALSTOCK_CLOSEResponseTypeCLOSEset_default_sizeScrolledWindow
set_policy
PolicyType	AUTOMATIC
TextBufferset_textplace_cursorget_start_iterTextViewset_wrap_modeWrapModer   r   set_hexpandset_vexpandget_content_area
pack_startconnecton_response)r$   r=  r<  dialogscrolled_window
textbuffertextviews          r%   rc  z#FlatReviewContextGUI._create_dialog  s8    E OO11 __c.>.>.D.DEG 	S),,.""3>>#;#;S^^=U=UV^^%
D!
 9 9 ;<<<z2s||001H%##D)##D)!,,_dD!Lz4#3#34r'   c                 t    |t         j                  j                  k(  r| j                  j	                          yy)z0Handler for the 'response' signal of the dialog.N)r   rk  rl  r"   destroy)r$   r  rf  s      r%   r~  z FlatReviewContextGUI.on_response  s-     s''---II .r'   c                     | j                   j                          t        j                  j                  }|dk(  rt        j                         }| j                   j                  |       y)zShows the dialog.r   N)r"   show_allr   lastInputEvent	timestampr   get_current_event_timepresent_with_time)r$   
time_stamps     r%   r;  zFlatReviewContextGUI.show_gui  sL     			..88
?335J		##J/r'   N)r[  r\  r]  r^  r&   rc  r~  r;  r_  r'   r%   r:  r:    s    @56 0r'   r:  c                      t         S )z!Returns the Flat Review Presenter)
_presenterr_  r'   r%   getPresenterr    s
     r'   )r^  __id____version____date____copyright____license__girequire_versiongi.repositoryr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r:  r  r  r_  r'   r%   <module>r     s   * &7 	   5%                U Un"/0 /0d !"
r'   