
    g
f\1                         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
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Z G d d      Z G d d      Z G d dej.                        Zy)z;Utilities for obtaining sounds to be presented for objects.z$Id:$z$Revision:$z$Date:$zCopyright (c) 2016 Igalia, S.L.LGPL    NAtspiz2.0)r      )	generator)settings_manager)AXObject)AXUtilities)AXValue	_generatec                   "    e Zd ZdZd Zd Zd Zy)Iconz9Sound file representing a particular aspect of an object.c                 N    t         j                  j                  ||      | _        y N)ospathjoin)selflocationfilenames      6/usr/lib/python3/dist-packages/orca/sound_generator.py__init__zIcon.__init__/   s    GGLL84	    c                 D    d| j                    d| j                          dS )NzIcon(path: z, isValid: ))r   isValidr   s    r   __str__zIcon.__str__2   s"    TYYK{4<<>2B!DDr   c                 T    t         j                  j                  | j                        S r   )r   r   isfiler   s    r   r   zIcon.isValid5   s    ww~~dii((r   N)__name__
__module____qualname____doc__r   r   r    r   r   r   r   ,   s    C5E)r   r   c                   V    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdefdZd Zy)Tonez3Tone representing a particular aspect of an object.r   r                        	   
         c                     || _         t        t        d|      d      | _        t	        j
                         j                  d      |z  | _        || _        y )Nr   i N  soundVolume)	durationminmax	frequencyr   
getManager
getSettingvolumewave)r   r4   r7   volumeMultiplierr;   s        r   r   zTone.__init__I   sF     SI.6&113>>}MP``	r   c           	      p    d| j                    d| j                   d| j                   d| j                   d	S )NzTone(duration: z, frequency: z
, volume: z, wave: r   )r4   r7   r:   r;   r   s    r   r   zTone.__str__O   sD    dmm_ -..) *{{m $YYKq"	
r   N)r    r!   r"   r#   	SINE_WAVESQUARE_WAVESAW_WAVETRIANGLE_WAVESILENCEWHITE_UNIFORM_NOISE
PINK_NOISESINE_WAVE_USING_TABLEPERIODIC_TICKSWHITE_GAUSSIAN_NOISE	RED_NOISEINVERTED_PINK_NOISEINVERTED_RED_NOISEr   r   r$   r   r   r&   r&   8   sZ    =IKHMGJNI=>Y 
r   r&   c                        e Zd ZdZ fdZd Zd Z fdZ fdZ fdZ	 fdZ
 fd	Z fd
Z fdZ fdZ fdZ fdZ fdZ fdZd Zd Zd Z fdZ fdZd Zd Z xZS )SoundGeneratorz@Takes accessible objects and produces the sound(s) to be played.c                     t         |   |d       t        j                  j	                  t        j                         j                         d      | _        y )Nsoundsounds)	superr   r   r   r   r   r8   getPrefsDir_sounds)r   script	__class__s     r   r   zSoundGenerator.__init__Z   s<    )ww||$4$?$?$A$M$M$OQYZr   c                 T    t        | j                  |      }|j                         r|S y r   )r   rR   r   )r   r   icons      r   _convertFilenameToIconz%SoundGenerator._convertFilenameToIcon^   s#    DLL(+<<>Kr   c                 (     | j                   |fi |S )z@Returns an array of sounds for the complete presentation of obj.)generater   objargss      r   generateSoundzSoundGenerator.generateSounde   s     t}}S)D))r   c                     t        j                         j                  d      sg S t        |   |fi |}t        t        | j                  |            }|r|S g S )z8Returns an array of sounds indicating obj is grayed out.playSoundForState)r   r8   r9   rP   _generateAvailabilitylistmaprW   r   r[   r\   	filenamesresultrT   s        r   r`   z$SoundGenerator._generateAvailabilityp   Z      **,778KLIG1#>>	c$55yABM	r   c                     t        j                         j                  d      sg S t        |   |fi |}t        t        | j                  |            }|r|S g S z?Returns an array of sounds indicating the checked state of obj.r_   )r   r8   r9   rP   _generateCheckedStatera   rb   rW   rc   s        r   ri   z$SoundGenerator._generateCheckedState}   rf   r   c                     t        j                         j                  d      sg S t        |   |fi |}t        t        | j                  |            }|r|S g S )z7Returns an array of sounds indicating obj is clickable.r_   )r   r8   r9   rP   _generateClickablera   rb   rW   rc   s        r   rk   z!SoundGenerator._generateClickable   sZ      **,778KLIG.s;d;	c$55yABM	r   c                     t        j                         j                  d      sg S t        |   |fi |}t        t        | j                  |            }|r|S g S )z@Returns an array of sounds indicating the expanded state of obj.r_   )r   r8   r9   rP   _generateExpandableStatera   rb   rW   rc   s        r   rm   z'SoundGenerator._generateExpandableState   sZ      **,778KLIG4SADA	c$55yABM	r   c                     t        j                         j                  d      sg S t        |   |fi |}t        t        | j                  |            }|r|S g S )z9Returns an array of sounds indicating obj has a longdesc.r_   )r   r8   r9   rP   _generateHasLongDescra   rb   rW   rc   s        r   ro   z#SoundGenerator._generateHasLongDesc   Z      **,778KLIG0==	c$55yABM	r   c                     t        j                         j                  d      sg S t        |   |fi |}t        t        | j                  |            }|r|S g S rh   )r   r8   r9   rP   _generateMenuItemCheckedStatera   rb   rW   rc   s        r   rr   z,SoundGenerator._generateMenuItemCheckedState   Z      **,778KLIG9#FF	c$55yABM	r   c                     t        j                         j                  d      sg S t        |   |fi |}t        t        | j                  |            }|r|S g S )z=Returns an array of sounds indicating obj is multiselectable.r_   )r   r8   r9   rP   _generateMultiselectableStatera   rb   rW   rc   s        r   ru   z,SoundGenerator._generateMultiselectableState   rs   r   c                     t        j                         j                  d      sg S t        |   |fi |}t        t        | j                  |            }|r|S g S )z@Returns an array of sounds indicating the selected state of obj.r_   )r   r8   r9   rP   _generateRadioStatera   rb   rW   rc   s        r   rw   z"SoundGenerator._generateRadioState   sZ      **,778KLIG/<t<	c$55yABM	r   c                     t        j                         j                  d      sg S t        |   |fi |}t        t        | j                  |            }|r|S g S )z7Returns an array of sounds indicating obj is read only.r_   )r   r8   r9   rP   _generateReadOnlyra   rb   rW   rc   s        r   ry   z SoundGenerator._generateReadOnly   Z      **,778KLIG-c:T:	c$55yABM	r   c                     t        j                         j                  d      sg S t        |   |fi |}t        t        | j                  |            }|r|S g S )z6Returns an array of sounds indicating obj is required.r_   )r   r8   r9   rP   _generateRequiredra   rb   rW   rc   s        r   r|   z SoundGenerator._generateRequired   rz   r   c                     t        j                         j                  d      sg S t        |   |fi |}t        t        | j                  |            }|r|S g S )z>Returns an array of sounds indicating the on/off state of obj.r_   )r   r8   r9   rP   _generateSwitchStatera   rb   rW   rc   s        r   r~   z#SoundGenerator._generateSwitchState   rp   r   c                     t        j                         j                  d      sg S t        |   |fi |}t        t        | j                  |            }|r|S g S )z?Returns an array of sounds indicating the toggled state of obj.r_   )r   r8   r9   rP   _generateToggleStatera   rb   rW   rc   s        r   r   z#SoundGenerator._generateToggleState   rp   r   c                 Z   t        j                         j                  d      sg S |j                  dd      s| j                  |d<   d|d<   t        j                  |      rJ | j                  j                  j                  di |g}t        t        | j                  |            }|r|S g S )z?Returns an array of sounds indicating the visited state of obj.r_   modeNvisited
stringTyper$   )r   r8   r9   get_moder	   
is_visited_script
formatting	getStringra   rb   rW   )r   r[   r\   rd   re   s        r   _generateVisitedStatez$SoundGenerator._generateVisitedState  s      **,778KLIxx%::DL&\!!#&:00::BTBCI#d999EFF	r   c                     t        j                         j                  d      sg S t        j                  |      }|g S g S )z<Returns an array of sounds reflecting the percentage of obj.playSoundForValue)r   r8   r9   r
   get_value_as_percent)r   r[   r\   percents       r   _generatePercentagez"SoundGenerator._generatePercentage$  s@      **,778KLI..s3?I	r   c                 r   |j                  d      r | j                  |fi |s'g S t        j                         j	                  d      sg S t        j                  |      }|g S |dk\  rd}nd}d|dz  z
  }|dk  rt        d|d	z  z         }nt        |d
z        }t        |||t        j                        gS )z?Returns an array of sounds representing the progress bar value.isProgressBarUpdater   c   r   g333333?x   r,   b   g@   )
r   _shouldPresentProgressBarUpdater   r8   r9   r
   r   intr&   r>   )r   r[   r\   r   r4   r<   r7   s          r   _generateProgressBarValuez(SoundGenerator._generateProgressBarValue0  s     88)*7477DtD	!,,.99:MNI..s3?I b=HH #. Q;B3./IGbL)IXy*:DNNKLLr   c                     t        j                         j                  d      }|t        |          S t        |      S )NprogressBarBeepInterval)r   r8   r9   rP   _getProgressBarUpdateIntervalr   )r   intervalrT   s     r   r   z,SoundGenerator._getProgressBarUpdateIntervalN  s;    #..0;;<UV78::8}r   c                 l    t        j                         j                  d      syt        |   |fi |S )NbeepProgressBarUpdatesF)r   r8   r9   rP   r   )r   r[   r\   rT   s      r   r   z.SoundGenerator._shouldPresentProgressBarUpdateU  s3    **,778PQw6sCdCCr   c                 P    t        j                         j                  d      sg S g S )z>Returns an array of sounds reflecting the set position of obj.playSoundForPositionInSet)r   r8   r9   rZ   s      r   _generatePositionInSetz%SoundGenerator._generatePositionInSeta  s(      **,778STI 	r   c                    t        j                         j                  d      sg S |j                  dt	        j
                  |            }t        j                  |      j                  dd      }| j                  |      }|r|gS g S )z6Returns an array of sounds indicating the role of obj.playSoundForRolerole _)
r   r8   r9   r   r   get_roler   role_get_namereplacerW   )r   r[   r\   r   r   re   s         r   _generateRoleNamez SoundGenerator._generateRoleNamem  sx      **,778JKIxx 1 1# 67&&t,44S#>,,X68O	r   )r    r!   r"   r#   r   rW   r]   r`   ri   rk   rm   ro   rr   ru   rw   ry   r|   r~   r   r   r   r   r   r   r   r   __classcell__)rT   s   @r   rL   rL   W   sw    J[*0
M<D
r   rL   )r#   __id____version____date____copyright____license__girequire_versiongi.repositoryr   r    r   r   	ax_objectr   ax_utilitiesr	   ax_valuer
   METHOD_PREFIXr   r&   	GeneratorrL   r$   r   r   <module>r      s{   , B1 	   7E "  	    % 
) 
)
 
>bY(( br   