o
    tf                     @  s   d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZ dd	lmZmZ dd
lmZ ddgZd&ddZededfd'ddZ	d(d)ddZd Zd!Zd*d"d#Zd*d$d%ZdS )+z@These utilities may help when using signals and evented objects.    )annotations)contextmanagersuppress)partial)Path)AnyCallable	GeneratorIterator)warn   )EmissionInfoSignalGroup)SignalInstancemonitor_eventsiter_signal_instancesinfor   returnNonec                 C  s   t | jj d| j d S )Nz.emit)printsignalnameargs)r    r   V/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/psygnal/utils.py_default_event_monitor   s   r   NFobj
Any | NoneloggerCallable[[EmissionInfo], Any]include_private_attrsboolIterator[None]c           
      #  s   t  dd}t|o|jdk}| du r"|rtdtj }t_n6|r*tddd t }t| |D ]%}|rA|dd fdd}n
|dd fdd}|	t
|j|| q2zdV  W | du rf|t_dS |D ]}	|	  qhdS | du rx|t_w |D ]}	|	  qzw )a  Context manager to print or collect events emitted by SignalInstances on `obj`.

    Parameters
    ----------
    obj : object, optional
        Any object that has an attribute that has a SignalInstance (or SignalGroup).
        If None, all SignalInstances will be monitored.
    logger : Callable[[EmissionInfo], None], optional
        A optional function to handle the logging of the event emission.  This function
        must take two positional args: a signal name string, and a tuple that contains
        the emitted arguments. The default logger simply prints the signal name and
        emitted args.
    include_private_attrs : bool
        Whether private signals (starting with an underscore) should also be logged,
        by default False
    __code__Nr   zFlogger function must take a single argument (an EmissionInfo instance)z{logger functions must now take a single argument (an instance of psygnal.EmissionInfo). Please update your logger function.   )
stacklevel)r   r   r   r   r   r   r   c                   s    | j | d S N)r   r   r   r   r   r   _report@   s   zmonitor_events.<locals>._reportc                   s    t | | d S r&   )r   r'   r(   r   r   r)   E   s   )r   r   r   r   r   r   )getattrr!   co_argcount
ValueErrorr   Z_debug_hookr   setr   addr   Z
disconnectconnect)
r   r   r    codeZ_old_apibeforeZdisconnectorsZsiginstr)   Zdisconnectorr   r(   r   r      s@   
r   %Generator[SignalInstance, None, None]c              	   c  s    t | tr| D ]}| | V  qdS t| D ]5}|s |dr qttt t| |}t |tr3|V  t |tr<|j	V  W d   n1 sFw   Y  qdS )a  Yield all `SignalInstance` attributes found on `obj`.

    Parameters
    ----------
    obj : object
        Any object that has an attribute that has a SignalInstance (or SignalGroup).
    include_private_attrs : bool
        Whether private signals (starting with an underscore) should also be logged,
        by default False

    Yields
    ------
    SignalInstance
        SignalInstances (and SignalGroups) found as attributes on `obj`.
    N_)

isinstancer   dir
startswithr   AttributeErrorFutureWarningr*   r   Z_psygnal_relay)r   r    signattrr   r   r   r   T   s$   



)z.soz.pyd_BAKc                  C  sB   t D ]} ttjd|  D ]}|||  t  qqdS )zMangle names of mypyc-compiled files so that they aren't used.

    This function requires write permissions to the psygnal source directory.
    **/*N)_COMPILED_EXTSr   __file__parentrglobrenamewith_suffixr<   suffixpathr   r   r   	decompile|   s
   rG   c                  C  s>   t D ]} ttjd|  t D ]
}|||  qqdS )zFix all name-mangled mypyc-compiled files so that they ARE used.

    This function requires write permissions to the psygnal source directory.
    r=   N)r>   r   r?   r@   rA   r<   rB   rC   rD   r   r   r   	recompile   s
   rH   )r   r   r   r   )r   r   r   r   r    r!   r   r"   )F)r   r   r    r!   r   r2   )r   r   )__doc__
__future__r   
contextlibr   r   	functoolsr   pathlibr   typingr   r   r	   r
   warningsr   _groupr   r   _signalr   __all__r   r   r   r>   r<   rG   rH   r   r   r   r   <module>   s,    
?$

