
    g
f5T                         d Z dZdZdZdZd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  ej$                         Z G d d      Z e       Zd Zy)z5Module for configuring speech and verbosity settings.z$Id$z
$Revision$z$Date$zQCopyright (c) 2005-2008 Sun Microsystems Inc.Copyright (c) 2016-2023 Igalia, S.L.LGPL   )cmdnames)debug)focus_manager)input_event)keybindings)messages)settings)settings_manager)speech)AXTablec                       e Zd ZdZd ZddZddZd Zd Zd Z	dd	Z
dd
ZddZddZddZddZd Zd ZddZddZddZddZddZddZddZddZddZy)SpeechAndVerbosityManagerz)Configures speech and verbosity settings.c                 b    | j                  d      | _        t        j                         | _        y )NT)get_handlers	_handlersr   KeyBindings	_bindingsselfs    C/usr/lib/python3/dist-packages/orca/speech_and_verbosity_manager.py__init__z"SpeechAndVerbosityManager.__init__.   s$    **40$002    c                     |rCd}t        j                  t         j                  |d       | j                          | j                  S | j                  j                         r| j                          | j                  S )z5Returns the speech and verbosity manager keybindings.z2SPEECH AND VERBOSITY MANAGER: Refreshing bindings.T)r   printMessage
LEVEL_INFO_setup_bindingsr   isEmpty)r   refresh
is_desktopmsgs       r   get_bindingsz&SpeechAndVerbosityManager.get_bindings2   sd     FCu//d;  " ~~ ^^##%  "~~r   c                     |r7d}t        j                  t         j                  |d       | j                          | j                  S )z2Returns the speech and verbosity manager handlers.z2SPEECH AND VERBOSITY MANAGER: Refreshing handlers.T)r   r   r   _setup_handlersr   )r   r   r!   s      r   r   z&SpeechAndVerbosityManager.get_handlers>   s:     FCu//d;  "~~r   c                 J   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<   d}tE        jF                  tD        jH                  |d       y)z6Sets up the speech and verbosity input event handlers.cycleCapitalizationStyleHandler$cycleSpeakingPunctuationLevelHandlercycleSynthesizerHandlercycleKeyEchoHandlerchangeNumberStyleHandlertoggleSilenceSpeechHandlertoggleSpeechVerbosityHandler-toggleSpeakingIndentationJustificationHandlertoggleTableCellReadModeHandlerdecreaseSpeechRateHandlerincreaseSpeechRateHandlerdecreaseSpeechPitchHandlerincreaseSpeechPitchHandlerdecreaseSpeechVolumeHandlerincreaseSpeechVolumeHandlerz.SPEECH AND VERBOSITY MANAGER: Handlers set up.TN)%r   r   InputEventHandlercycle_capitalization_styler   CYCLE_CAPITALIZATION_STYLEcycle_punctuation_levelCYCLE_PUNCTUATION_LEVELcycle_synthesizerCYCLE_SYNTHESIZERcycle_key_echoCYCLE_KEY_ECHOchange_number_styleCHANGE_NUMBER_STYLEtoggle_speechTOGGLE_SPEECHtoggle_verbosityTOGGLE_SPEECH_VERBOSITY$toggle_indentation_and_justification+TOGGLE_SPOKEN_INDENTATION_AND_JUSTIFICATIONtoggle_table_cell_reading_modeTOGGLE_TABLE_CELL_READ_MODEdecrease_rateDECREASE_SPEECH_RATEincrease_rateINCREASE_SPEECH_RATEdecrease_pitchDECREASE_SPEECH_PITCHincrease_pitchINCREASE_SPEECH_PITCHdecrease_volumeDECREASE_SPEECH_VOLUMEincrease_volumeINCREASE_SPEECH_VOLUMEr   r   r   r   r!   s     r   r$   z)SpeechAndVerbosityManager._setup_handlersH   s
     ))//335 	89 )),,002 	=> ))&&**, 	01 ))##'') 	,- ))((,,. 	12 ))""&&( 	34 ))%%002 	56 ))99DDF 	FG ))33446 	78 ))""--/ 	23 ))""--/ 	23 ))##..0 	34 ))##..0 	34 ))$$//1 	45 ))$$//1 	45
 ?5++S$7r   c           
      x   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                   | 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	                   | 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                   | j                  j                  t        j                  dt         j
                  t         j                  | j                  j                  d                   d}t        j                  t        j                  |d       y)z.Sets up the speech and verbosity key bindings. r&   r'   r(   r)   r*   r/   r0   r1   r2   r3   r4   r-   sr+   vr,   F11r.   z.SPEECH AND VERBOSITY MANAGER: Bindings set up.TN)r   r   r   add
KeyBindingdefaultModifierMaskNO_MODIFIER_MASKr   getORCA_MODIFIER_MASKr   r   r   rT   s     r   r   z)SpeechAndVerbosityManager._setup_bindings   s    %002""//,,""#DE	G	H 	""//,,""#IJ	L	M 	""//,,""#<=	?	@ 	""//,,""#89	;	< 	""//,,""#=>	@	A 	""//,,""#>?	A	B 	""//,,""#>?	A	B 	""//,,""#?@	B	C 	""//,,""#?@	B	C 	""//,,""#@A	C	D 	""//,,""#@A	C	D 	""//,,""#RS	U	V 	""//..""#?@	B	C 	""//..""#AB	D	E 	""//..""#CD	F	G ?5++S$7r   c                 *    t        j                         S N)r   getSpeechServerr   s    r   _get_serverz%SpeechAndVerbosityManager._get_server  s    %%''r   Nc                     | j                         }|(d}t        j                  t        j                  |d       y|j	                          y)zDecreases the speech rate7SPEECH AND VERBOSITY MANAGER: Cannot get speech server.T)rc   r   r   r   decreaseSpeechRater   scripteventserverr!   s        r   rH   z'SpeechAndVerbosityManager.decrease_rate  F     !!#>KCu//d;!!#r   c                     | j                         }|(d}t        j                  t        j                  |d       y|j	                          y)zIncreases the speech ratere   T)rc   r   r   r   increaseSpeechRaterg   s        r   rJ   z'SpeechAndVerbosityManager.increase_rate  rk   r   c                     | j                         }|(d}t        j                  t        j                  |d       y|j	                          y)zDecreases the speech pitchre   T)rc   r   r   r   decreaseSpeechPitchrg   s        r   rL   z(SpeechAndVerbosityManager.decrease_pitch'  F     !!#>KCu//d;""$r   c                     | j                         }|(d}t        j                  t        j                  |d       y|j	                          y)zIncrease the speech pitchre   T)rc   r   r   r   increaseSpeechPitchrg   s        r   rN   z(SpeechAndVerbosityManager.increase_pitch3  rp   r   c                     | j                         }|(d}t        j                  t        j                  |d       y|j	                          y)zDecreases the speech volumere   T)rc   r   r   r   decreaseSpeechVolumerg   s        r   rP   z)SpeechAndVerbosityManager.decrease_volume?  F     !!#>KCu//d;##%r   c                     | j                         }|(d}t        j                  t        j                  |d       y|j	                          y)zIncreases the speech volumere   T)rc   r   r   r   increaseSpeechVolumerg   s        r   rR   z)SpeechAndVerbosityManager.increase_volumeK  ru   r   c                     | j                         }|(d}t        j                  t        j                  |d       y|j	                          y)z@Updates the capitalization style based on the value in settings.re   T)rc   r   r   r   updateCapitalizationStyler   rj   r!   s      r   update_capitalization_stylez5SpeechAndVerbosityManager.update_capitalization_styleW  sF     !!#>KCu//d;((*r   c                     | j                         }|(d}t        j                  t        j                  |d       y|j	                          y)z=Updates the punctuation level based on the value in settings.re   T)rc   r   r   r   updatePunctuationLevelrz   s      r   update_punctuation_levelz2SpeechAndVerbosityManager.update_punctuation_levelc  sF     !!#>KCu//d;%%'r   c                    | j                         }|(d}t        j                  t        j                  |d       y|j	                         }|s(d}t        j                  t        j                  |d       y|j                         }|s(d}t        j                  t        j                  |d       y|j                  |      dz   }|t        |      k(  rd}|j                  ||          |j                  ||          y)z?Cycle through the speech-dispatcher's available output modules.re   Tz8SPEECH AND VERBOSITY MANAGER: Cannot get output modules.z?SPEECH AND VERBOSITY MANAGER: Cannot get current output module.r       )
rc   r   r   r   list_output_modulesgetOutputModuleindexlensetOutputModulepresentMessage)r   rh   ri   rj   r!   	availablecurrentr   s           r   r:   z+SpeechAndVerbosityManager.cycle_synthesizero  s     !!#>KCu//d;..0	LCu//d;((*SCu//d;(1,C	N"Ey/0i./r   c                    t         j                  d      }|t        j                  k(  r1t        j                  }t
        j                  }t
        j                  }nt|t        j                  k(  r1t        j                  }t
        j                  }t
        j                  }n0t        j                  }t
        j                  }t
        j                  }t         j                  d|       |j                  ||       | j                          y)z:Cycle through the speech-dispatcher capitalization styles.capitalizationStyleT)_settings_manager
getSettingr
   CAPITALIZATION_STYLE_NONECAPITALIZATION_STYLE_SPELLr	   CAPITALIZATION_SPELL_FULLCAPITALIZATION_SPELL_BRIEFCAPITALIZATION_STYLE_ICONCAPITALIZATION_ICON_FULLCAPITALIZATION_ICON_BRIEFCAPITALIZATION_NONE_FULLCAPITALIZATION_NONE_BRIEF
setSettingr   r{   )r   rh   ri   current_style	new_stylefullbriefs          r   r6   z4SpeechAndVerbosityManager.cycle_capitalization_style  s     *445JKH>>> ;;I55D77EhAAA ::I44D66E ::I44D66E$$%:IFdE*((*r   c                    t         j                  d      }|t        j                  k(  r1t        j                  }t
        j                  }t
        j                  }n|t        j                  k(  r1t        j                  }t
        j                  }t
        j                  }nt|t        j                  k(  r1t        j                  }t
        j                  }t
        j                  }n0t        j                  }t
        j                  }t
        j                  }t         j!                  d|       |j#                  ||       | j%                          y)z0Cycle through the punctuation levels for speech.verbalizePunctuationStyleT)r   r   r
   PUNCTUATION_STYLE_NONEPUNCTUATION_STYLE_SOMEr	   PUNCTUATION_SOME_FULLPUNCTUATION_SOME_BRIEFPUNCTUATION_STYLE_MOSTPUNCTUATION_MOST_FULLPUNCTUATION_MOST_BRIEFPUNCTUATION_STYLE_ALLPUNCTUATION_ALL_FULLPUNCTUATION_ALL_BRIEFPUNCTUATION_NONE_FULLPUNCTUATION_NONE_BRIEFr   r   r~   )r   rh   ri   current_level	new_levelr   r   s          r   r8   z1SpeechAndVerbosityManager.cycle_punctuation_level  s     *445PQH;;; 77I11D33Eh=== 77I11D33Eh=== 66I00D22E 77I11D33E$$%@)LdE*%%'r   c                 X   d\  }}}t         j                  d      }t         j                  d      }t         j                  d      }|||fdk(  r'd\  }}}t        j                  }	t        j                  }
n|||fdk(  r'd\  }}}t        j
                  }	t        j                  }
n|||fdk(  r'd\  }}}t        j                  }	t        j                  }
n|||fdk(  r'd\  }}}t        j                  }	t        j                  }
nU|||fdk(  r'd	\  }}}t        j                  }	t        j                  }
n&d\  }}}t        j                  }	t        j                  }
t         j                  d|       t         j                  d|       t         j                  d|       |j!                  |	|
       y
)z"Cycle through the key echo levels.)FFFenableKeyEchoenableEchoByWordenableEchoBySentence)TFF)FTF)FFT)TTF)FTTT)r   r   r	   KEY_ECHO_KEY_FULLKEY_ECHO_KEY_BRIEFKEY_ECHO_WORD_FULLKEY_ECHO_WORD_BRIEFKEY_ECHO_SENTENCE_FULLKEY_ECHO_SENTENCE_BRIEFKEY_ECHO_KEY_AND_WORD_FULLKEY_ECHO_KEY_AND_WORD_BRIEFKEY_ECHO_WORD_AND_SENTENCE_FULL KEY_ECHO_WORD_AND_SENTENCE_BRIEFKEY_ECHO_NONE_FULLKEY_ECHO_NONE_BRIEFr   r   )r   rh   ri   new_keynew_wordnew_sentencekeywordsentencer   r   s              r   r<   z(SpeechAndVerbosityManager.cycle_key_echo  s   ,A)(L**?; ++,>?$//0FGx $990D-Wh--D//E4"&::0D-Wh..D00E4"&::0D-Wh22D44E4"&::0C-Wh66D88E4"&990C-Wh;;D==E0E-Wh..D00E$$_g>$$%7B$$%;\JdE*r   c                    t         j                  d      }|r!t        j                  }t        j                  }n t        j
                  }t        j                  }t         j                  d|        |j                  ||       y)z5Changes spoken number style between digits and words.speakNumbersAsDigitsT)	r   r   r	   NUMBER_STYLE_WORDS_BRIEFNUMBER_STYLE_WORDS_FULLNUMBER_STYLE_DIGITS_BRIEFNUMBER_STYLE_DIGITS_FULLr   r   )r   rh   ri   speak_digitsr   r   s         r   r>   z-SpeechAndVerbosityManager.change_number_style  sk     )334JK55E33D66E44D$$%;=MNdE*r   c                    |j                          t        j                  d      r6t        j                  dd       |j	                  t
        j                         yt        j                  d      sJt        j                  dd       t        j                          |j	                  t
        j                         y|j	                  t
        j                         t        j                  dd       y)zToggles speech.silenceSpeechFenableSpeechT)
presentationInterruptr   r   r   r   r	   SPEECH_ENABLEDr   initSPEECH_DISABLED)r   rh   ri   s      r   r@   z'SpeechAndVerbosityManager.toggle_speech  s     	$$&''8((%@!!("9"9:  #--n=((>KKM!!("9"9:  !!(":":;(($?r   c                 b   t         j                  d      }|t        j                  k(  rD|j	                  t
        j                         t         j                  dt        j                         y|j	                  t
        j                         t         j                  dt        j                         y)z9Toggles speech verbosity level between verbose and brief.speechVerbosityLevelT)
r   r   r
   VERBOSITY_LEVEL_BRIEFr   r	   SPEECH_VERBOSITY_VERBOSEr   VERBOSITY_LEVEL_VERBOSESPEECH_VERBOSITY_BRIEF)r   rh   ri   values       r   rB   z*SpeechAndVerbosityManager.toggle_verbosity  s     ",,-CDH222!!("C"CD(()?AaAab  !!("A"AB(()?A_A_`r   c                 ,   t         j                  d      }t         j                  d|        t         j                  d      r!t        j                  }t        j
                  }n t        j                  }t        j                  }|j                  ||       y)z6Toggles the speaking of indentation and justification.enableSpeechIndentationT)	r   r   r   r	   !INDENTATION_JUSTIFICATION_ON_FULL"INDENTATION_JUSTIFICATION_ON_BRIEF"INDENTATION_JUSTIFICATION_OFF_FULL#INDENTATION_JUSTIFICATION_OFF_BRIEFr   )r   rh   ri   r   r   r   s         r   rD   z>SpeechAndVerbosityManager.toggle_indentation_and_justification  sv     ",,-FG$$%>E	J''(AB==D??E>>D@@EdE*r   c                    t        j                  t        j                         j	                               }| |j                  t        j                         y|j                  j                  |      sd}n |j                  j                  |      rd}nd}t        j                  |      }t        j                  ||        |st        j                  }nt        j                  }|j                  |       y)z)Toggles between speak cell and speak row.TreadFullRowInGUITablereadFullRowInSpreadSheetreadFullRowInDocumentTable)r   	get_tabler   
getManagerget_locus_of_focusr   r	   TABLE_NOT_IN_A	utilitiesgetDocumentForObjectisSpreadSheetTabler   r   r   TABLE_MODE_ROWTABLE_MODE_CELL)r   rh   ri   tablesetting_name	speak_rowr!   s          r   rF   z8SpeechAndVerbosityManager.toggle_table_cell_reading_mode  s     !!-":":"<"O"O"QR=!!("9"9:44U;2L0075L7L%00>	$$\y=A))C**Cc"r   )FT)Fra   )__name__
__module____qualname____doc__r   r"   r   r$   r   rc   rH   rJ   rL   rN   rP   rR   r{   r~   r:   r6   r8   r<   r>   r@   rB   rD   rF    r   r   r   r   +   s}    33
Q8fo8b(







:,4$L 
r   r   c                      t         S )z(Returns the Speech and Verbosity Manager)_managerr   r   r   r   r   6  s	     Or   N)r   __id____version____date____copyright____license__rV   r   r   r   r   r   r	   r
   r   r   ax_tabler   r   r   r   r   r   r   r   <module>r      sq   * <7          /$//1 H HT %&r   