o
    CZhs                     @   s4   d dl Z d dlZd dlZd dlZG dd deZdS )    Nc                   @   s   e Zd ZdZdd Zdd Zd#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dd Zdd Zdd Zdd  Zd!d" ZdS )$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
    c                 C   s   |du rt jdkrd}n
t jdkrd}nd}d| }t|| _| jt| | _|| _	g | _
d| _d| _d| _|| _d	| _dS )
a~  
        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/ or
            None to select the default for the platform
        @type driverName: str
        @param debug: Debugging output enabled or not
        @type debug: bool
        NdarwinZnssswin32Zsapi5Zespeakzpyttsx3.drivers.%sT )sysplatform	importlibimport_module_moduleZbuildDriverweakrefproxy_driver_engine_queue_busy_name	_iterator_debug_current_text)selfZengineZ
driverNamedebugname r   =/var/www/auris/lib/python3.10/site-packages/pyttsx3/driver.py__init__   s    


zDriverProxy.__init__c              	   C   s*   z| j   W d S  ttfy   Y d S w N)r   destroyAttributeError	TypeErrorr   r   r   r   __del__>   s
   zDriverProxy.__del__Nc                 C   s   | j |||f |   dS )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   Zmtdargsr   r   r   r   _pushD   s   zDriverProxy._pushc              
   C   s   | j sHt| jrJ| jd}|d | _z
|d |d   W n  ty= } z| jd|d | jr3t	  W Y d}~nd}~ww | j sLt| jsdS dS dS dS )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er   r   r   r"   R   s   
 zDriverProxy._pumpc                 K   s6   d|vs
|d du r| j |d< | jj|fi | dS )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   Z_notify)r   Ztopickwargsr   r   r   r-   a   s   	
zDriverProxy.notifyc                 C   s   || _ | j s|   dS dS )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   busyr   r   r   setBusyn   s   zDriverProxy.setBusyc                 C   s   | j S )zX
        @return: True if the driver is busy, false if not
        @rtype: bool
        )r   r   r   r   r   isBusyy   s   zDriverProxy.isBusyc                 C   s   || _ | | jj|f| dS 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   r   r   r   r7      s   	zDriverProxy.sayc                 C   sT   	 z
| j d \}}}W n	 ty   Y nw || jjkrn| j d q| j  dS )zm
        Called by the engine to stop the current utterance and clear the queue
        of commands.
        Tr   N)r   
IndexErrorr   endLoopr+   r   stopr#   r   r   r   r;      s   zDriverProxy.stopc                 C   s   |  | jj||f| dS r6   )r%   r   save_to_file)r   r8   filenamer   r   r   r   r<      s   	zDriverProxy.save_to_filec                 C   s   | 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   r   r   r   r>      s   	zDriverProxy.getPropertyc                 C   s   |  | jj||f dS )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   valuer   r   r   r?      s   	zDriverProxy.setPropertyc                 C   s    |  | jjt  | j  dS )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   r:   tupler   	startLoopr   r   r   r   
runAndWait   s   zDriverProxy.runAndWaitc                 C   s"   |r	| j   dS | j  | _dS )z>
        Called by the engine to start an event loop.
        N)r   rB   iterater   r   ZuseDriverLoopr   r   r   rB      s   zDriverProxy.startLoopc                 C   s4   g | _ | j  |r| j  nd| _| d dS )z=
        Called by the engine to stop an event loop.
        NT)r   r   r;   r:   r   r4   rE   r   r   r   r:      s   
zDriverProxy.endLoopc                 C   s&   zt | j W dS  ty   Y dS w )z
        Called by the engine to iterate driver commands and notifications from
        within an external event loop.
        N)nextr   StopIterationr   r   r   r   rD      s
   zDriverProxy.iterater   )__name__
__module____qualname____doc__r   r    r%   r"   r-   r4   r5   r7   r;   r<   r>   r?   rC   rB   r:   rD   r   r   r   r   r      s$    "
	r   )r   r.   r   r   objectr   r   r   r   r   <module>   s
    