
    f                     r    d dl mZmZmZ d dlmZ d dlmZ d dlZ ej                  e
      Z G d de      Zy)    )divisionprint_functionunicode_literals)unicode_strNc                   R    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y)Soundz5
    Sound singleton.
    Wrapper for osk.Audio.
    zonboard-key-feedbackc                     t        | d      s8t        j                  | g|i || _        | j                  j	                          | j                  S )z"
        Singleton magic.
        self)hasattrobject__new__r
   	construct)clsargskwargss      //usr/lib/python3/dist-packages/Onboard/Sound.pyr   zSound.__new__(   sA     sF#~~c;D;F;CHHH xx    c                      y)z4
        Called multiple times, do not use.
        N r
   s    r   __init__zSound.__init__1   s     	r   c                 
   d | _         	 t        j                         | _         | j                          | j                  | j                         y # t        $ r+}t        j                  dt        |      z          Y d }~[d }~ww xY w)NzFailed to create osk.Audio: )

_osk_audiooskAudio	Exception_loggerwarningr   enablecache_samplekey_feedbackr
   exs     r   r   zSound.construct7   sh    	N!iikDO 	$++,	  	NOO:[_LMM	Ns   A 	B!A==Bc                     | j                   duS )z+ Check initialization of the audio backend N)r   r   s    r   is_validzSound.is_validB   s    d**r   c                     	 | j                         r | j                  j                  |||||       yy# t        $ r+}t        j                  dt        |      z          Y d}~yd}~ww xY w)z Play a sound zFailed to play sound: N)r%   r   playr   r   r   r   )r
   event_idxyxsysr#   s          r   r'   z
Sound.playF   s[    	H}}$$Xq!R<  	HOO4{2FGG	Hs   /3 	A'!A""A'c                     	 | j                         r| j                  j                          yy# t        $ r+}t        j                  dt        |      z          Y d}~yd}~ww xY w)z Cancel all playing sounds zFailed to cancel sound: N)r%   r   cancelr   r   r   r   r"   s     r   r.   zSound.cancelN   Q    	J}}&&(  	JOO6RHII	J   *. 	A"!AA"c                     	 | j                         r| j                  j                  |       yy# t        $ r+}t        j                  dt        |      z          Y d}~yd}~ww xY w)z Set the XDG sound theme zFailed to set sound theme: N)r%   r   	set_themer   r   r   r   )r
   namer#   s      r   r2   zSound.set_themeV   sS    	M}}))$/  	MOO9KOKLL	M   +/ 	A#!AA#c                     	 | j                         r| j                  j                          yy# t        $ r+}t        j                  dt        |      z          Y d}~yd}~ww xY w)z Enable canberra audio output zFailed to enable audio: N)r%   r   r   r   r   r   r   r"   s     r   r   zSound.enable^   r/   r0   c                     	 | j                         r| j                  j                          yy# t        $ r+}t        j                  dt        |      z          Y d}~yd}~ww xY w)z Disable canberra audio output zFailed to disable audio: N)r%   r   disabler   r   r   r   r"   s     r   r7   zSound.disablef   sQ    	K}}'')  	KOO7+b/IJJ	Kr0   c                     	 | j                         r| j                  j                  |       yy# t        $ r+}t        j                  dt        |      z          Y d}~yd}~ww xY w)z3 Upload sample to the sound server. Blocking call. zFailed to cache sample: N)r%   r   r    r   r   r   r   )r
   r(   r#   s      r   r    zSound.cache_samplen   sS    	J}},,X6  	JOO6RHII	Jr4   N)__name__
__module____qualname____doc__r!   r   r   r   r%   r'   r.   r2   r   r7   r    r   r   r   r   r      sI    
 &)L	-+HJMJKJr   r   )
__future__r   r   r   Onboard.utilsr   Onboard.oskr   logging	getLoggerr9   r   r   r   r   r   r   <module>rB      s9   * B A &  
'

H
%UJF UJr   