
    җiJ                     8    d dl Z d dlZd dlZd dlZ G d d      Zy)    Nc                       e Zd ZdZdededdfdZddZdddZdd	Z	dd
Z
ddZd ZddZddZddZd ZddZddZddZddZddZy)DriverProxya  
    Proxy to a driver implementation.

    @ivar _module: Module containing the driver implementation
    @type _module: module
    @ivar _engine: Reference to the engine that owns the driver
    @type _engine: L{engine.Engine}
    @ivar _queue: Queue of commands outstanding for the driver
    @type _queue: list
    @ivar _busy: True when the driver is busy processing a command, False when
        not
    @type _busy: bool
    @ivar _name: Name associated with the current utterance
    @type _name: str
    @ivar _debug: Debugging output enabled or not
    @type _debug: bool
    @ivar _iterator: Driver iterator to invoke when in an external run loop
    @type _iterator: iterator
    
driverNamedebugreturnNc                    |sJ t        j                  d|       | _        | j                  j                  t	        j
                  |             | _        || _        g | _        d| _	        d| _
        d| _        || _        d| _        y)aC  
        Constructor.

        @param engine: Reference to the engine that owns the driver
        @type engine: L{engine.Engine}
        @param driverName: Name of the driver module to use under drivers/
        @type driverName: str
        @param debug: Debugging output enabled or not
        @type debug: bool
        zpyttsx3.drivers.TN )	importlibimport_module_modulebuildDriverweakrefproxy_driver_engine_queue_busy_name	_iterator_debug_current_text)selfenginer   r   s       X/home/obispo/Crisostomo_bridge/mision_env/lib/python3.12/site-packages/pyttsx3/driver.py__init__zDriverProxy.__init__   sw     z ..1A*/NO||//d0CD

    c                     t        j                  t        t              5  | j                  j                          d d d        y # 1 sw Y   y xY wN)
contextlibsuppressAttributeError	TypeErrorr   destroyr   s    r   __del__zDriverProxy.__del__5   s7      ; 	#LL  "	# 	# 	#s   AAc                 `    | j                   j                  |||f       | j                          y)a.  
        Adds a command to the queue.

        @param mtd: Method to invoke to process the command
        @type mtd: method
        @param args: Arguments to apply when invoking the method
        @type args: tuple
        @param name: Name associated with the command
        @type name: str
        N)r   append_pumpr   mtdargsnames       r   _pushzDriverProxy._push9   s&     	Ct,-

r   c                    | j                   skt        | j                        rU| j                  j                  d      }|d   | _        	  |d   |d     | j                   st        | j                        rSyyyy# t
        $ r=}| j                  d|       | j                  rt        j                          Y d}~gd}~ww xY w)z
        Attempts to process the next command in the queue if one exists and the
        driver is not currently busy.
        r         error)	exceptionN)
r   lenr   popr   	Exceptionnotifyr   	traceback	print_exc)r   cmdes      r   r(   zDriverProxy._pumpG   s    
 ::3t{{#3++//!$CQDJ*AA	 ::3t{{#3:#3:
  *Gq1;;'')*s   A9 9	B?3B::B?c                 n    d|vs|d   | j                   |d<    | j                  j                  |fi | y)z
        Sends a notification to the engine from the driver.

        @param topic: Notification topic
        @type topic: str
        @param kwargs: Arbitrary keyword arguments
        @type kwargs: dict
        r,   N)r   r   _notify)r   topickwargss      r   r6   zDriverProxy.notifyV   s;     6&>#9!ZZF6NU-f-r   c                 L    || _         | j                   s| j                          yy)z
        Called by the driver to indicate it is busy.

        @param busy: True when busy, false when idle
        @type busy: bool
        N)r   r(   )r   busys     r   setBusyzDriverProxy.setBusyc   s      
zzJJL r   c                     | j                   S )zY
        @return: True if the driver is busy, false if not
        @rtype: bool.
        )r   r$   s    r   isBusyzDriverProxy.isBusyn   s    
 zzr   c                 b    || _         | j                  | j                  j                  |f|       yz
        Called by the engine to push a say command onto the queue.

        @param text: Text to speak
        @type text: unicode
        @param name: Name to associate with the utterance
        @type name: str
        N)r   r-   r   say)r   textr,   s      r   rF   zDriverProxy.sayu   s(     "

4<<##dWd3r   c                     	 	 | j                   d   \  }}}|| j                  j                  k(  rn| j                   j	                  d       J| j
                  j                          y# t        $ r Y &w xY w)zm
        Called by the engine to stop the current utterance and clear the queue
        of commands.
        r   N)r   
IndexErrorr   endLoopr4   r   stopr)   s       r   rK   zDriverProxy.stop   sq     "&++a.T4 dll***KKOOA  	  s   A' '	A32A3c                 V    | j                  | j                  j                  ||f|       yrE   )r-   r   save_to_file)r   rG   filenamer,   s       r   rM   zDriverProxy.save_to_file   s#     	

4<<,,tX.>Er   c                 8    | j                   j                  |      S )z
        Called by the engine to get a driver property value.

        @param name: Name of the property
        @type name: str
        @return: Property value
        @rtype: object
        )r   getProperty)r   r,   s     r   rP   zDriverProxy.getProperty   s     ||''--r   c                 T    | j                  | j                  j                  ||f       y)z
        Called by the engine to set a driver property value.

        @param name: Name of the property
        @type name: str
        @param value: Property value
        @type value: object
        N)r-   r   setProperty)r   r,   values      r   rR   zDriverProxy.setProperty   s      	

4<<++dE];r   c                     | j                  | j                  j                  d       | j                  j	                          y)z
        Called by the engine to start an event loop, process all commands in
        the queue at the start of the loop, and then exit the loop.
         N)r-   r   rJ   r   	startLoopr$   s    r   
runAndWaitzDriverProxy.runAndWait   s,    
 	

4<<'', r   c                 |    |r| j                   j                          y| j                   j                         | _        y)z,Called by the engine to start an event loop.N)r   rV   iterater   r   useDriverLoops     r   rV   zDriverProxy.startLoop   s)    LL""$!\\113DNr   c                     g | _         | j                  j                          |r| j                  j                          nd| _        | j                  d       y)z+Called by the engine to stop an event loop.NT)r   r   rK   rJ   r   rA   rZ   s     r   rJ   zDriverProxy.endLoop   s?    LL  "!DNTr   c                     t        j                  t              5  t        | j                         ddd       y# 1 sw Y   yxY w)z
        Called by the engine to iterate driver commands and notifications from
        within an external event loop.
        N)r   r    StopIterationnextr   r$   s    r   rY   zDriverProxy.iterate   s3    
   / 	! 	! 	! 	!s	   9A)r   Nr   )__name__
__module____qualname____doc__strboolr   r%   r-   r(   r6   rA   rC   rF   rK   rM   rP   rR   rW   rV   rJ   rY   rU   r   r   r   r      sm    ( 3  t    2#*.	
4 	F	.	<!4!r   r   )r   r
   r7   r   r   rU   r   r   <module>rf      s       J! J!r   