
    $hJ                     8    S SK r S SKrS SKrS SKr " S S5      rg)    Nc                       \ rS rSrSrS\S\SS4S jrSS jrSSS	 jjr	SS
 jr
SS jrSS jrS rSS jrSS jrSS jrS rSS jrSS jrSS jrSS jrSS jrSrg)DriverProxy   ap  
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                    U(       d   e[         R                  " SU 35      U l        U R                  R                  [        R
                  " U 5      5      U l        Xl        / U l        SU l	        SU l
        SU l        X0l        SU l        g)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/
@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       H/home/james-whalen/.local/lib/python3.13/site-packages/pyttsx3/driver.py__init__DriverProxy.__init__   ss     z ..1A*/NO||//d0CD

    c                     [         R                  " [        [        5         U R                  R                  5         S S S 5        g ! , (       d  f       g = fN)
contextlibsuppressAttributeError	TypeErrorr   destroyr   s    r   __del__DriverProxy.__del__5   s.      ;LL  " <;;s   A
Ac                 ^    U R                   R                  XU45        U R                  5         g)z
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   _pushDriverProxy._push9   s$     	Ct,-

r   c                    U R                   (       d{  [        U R                  5      (       a`  U R                  R                  S5      nUS   U l         US   " US   6   U R                   (       d  [        U R                  5      (       a  M^  gggg! [
         a@  nU R                  SUS9  U R                  (       a  [        R                  " 5          SnANvSnAff = f)zg
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+   DriverProxy._pumpG   s    
 ::3t{{#3#3++//!$CQDJ*AA	 ::3t{{#3#3:#3:
  *Gq1;;'')*s   B 
C6CCc                 t    SU;  d  US   c  U R                   US'   U R                  R                  " U40 UD6  g)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   r:   DriverProxy.notifyV   s9     6&>#9!ZZF6NU-f-r   c                 T    Xl         U R                   (       d  U R                  5         gg)zm
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   setBusyDriverProxy.setBusyc   s     
zzJJL r   c                     U R                   $ )zA
@return: True if the driver is busy, false if not
@rtype: bool.
)r   r&   s    r   isBusyDriverProxy.isBusyn   s    
 zzr   c                 `    Xl         U R                  U R                  R                  U4U5        g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   r0   r   say)r   textr/   s      r   rN   DriverProxy.sayu   s&     "

4<<##dWd3r   c                       U R                   S   u  pnXR                  R                  :X  a  OU R                   R	                  S5        MJ  U R
                  R                  5         g! [         a     M(  f = f)zU
Called by the engine to stop the current utterance and clear the queue
of commands.
r   N)r   
IndexErrorr   endLoopr8   r   stopr,   s       r   rT   DriverProxy.stop   sm     "&++a.4 ll***KKOOA  	  s   A' '
A54A5c                 T    U R                  U R                  R                  X4U5        grM   )r0   r   save_to_file)r   rO   filenamer/   s       r   rW   DriverProxy.save_to_file   s!     	

4<<,,t.>Er   c                 8    U R                   R                  U5      $ )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   r[   DriverProxy.getProperty   s     ||''--r   c                 R    U R                  U R                  R                  X45        g)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)r0   r   setProperty)r   r/   values      r   r^   DriverProxy.setProperty   s     	

4<<++d];r   c                     U R                  U R                  R                  S5        U R                  R	                  5         g)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)r0   r   rS   r   	startLoopr&   s    r   
runAndWaitDriverProxy.runAndWait   s,    
 	

4<<'', r   c                     U(       a  U R                   R                  5         gU R                   R                  5       U l        g)z,Called by the engine to start an event loop.N)r   rc   iterater   r   useDriverLoops     r   rc   DriverProxy.startLoop   s)    LL""$!\\113DNr   c                     / U l         U R                  R                  5         U(       a  U R                  R                  5         OSU l        U R                  S5        g)z+Called by the engine to stop an event loop.NT)r   r   rT   rS   r   rG   rh   s     r   rS   DriverProxy.endLoop   s?    LL  "!DNTr   c                     [         R                  " [        5         [        U R                  5        SSS5        g! , (       d  f       g= f)zg
Called by the engine to iterate driver commands and notifications from
within an external event loop.
N)r!   r"   StopIterationnextr   r&   s    r   rg   DriverProxy.iterate   s*    
   /  0//s	   :
A)	r   r   r   r   r   r   r   r   r   )r   Nr    )__name__
__module____qualname____firstlineno____doc__strboolr   r'   r0   r+   r:   rG   rJ   rN   rT   rW   r[   r^   rd   rc   rS   rg   __static_attributes__rb   r   r   r   r      sm    ( 3  t    2#*.	
4 	F	.	<!4!r   r   )r!   r   r;   r   r   rb   r   r   <module>ry      s       J! J!r   