o
    ¹¼tfu  ã                	   @  s’   U d Z ddlmZ ddlmZmZ ddlmZ z
ddlm	Z	m
Z
 W n eefy/   edƒd‚w i Zd	ed
< de	jjdfddd„Zdddd„ZdS )af  Module that provides Qt-specific functionality for psygnal.

This module provides convenience functions for starting and stopping a QTimer that
will monitor "queued" signals and invoke their callbacks.  This is useful when
psygnal is used in a Qt application, and you'd like to emit signals from a thread
but have their callbacks invoked in the main thread.
é    )Úannotations)ÚThreadÚcurrent_threadé   )Úemit_queued)ÚQtÚQTimerzGThe psygnal.qt module requires qtpy and some Qt backend to be installedNzdict[Thread, QTimer]Ú_TIMERSÚmsecÚintÚ
timer_typeúQt.TimerTypeÚthreadúThread | NoneÚreturnÚNonec                 C  sr   |du rt ƒ n|}|tvrtƒ t|< t| j t¡ t|  |¡ t|  ¡ r0t|  | ¡ dS t|  	| ¡ dS )aÊ  Start a QTimer that will monitor the global emission queue.

    If a QTimer is already running in the current thread, then this function will
    update the interval and timer type of that QTimer. (It is safe to call this
    function multiple times in the same thread.)

    When callbacks are connected to signals with `connect(type='queued')`, then they
    are not invoked immediately, but rather added to a global queue.  This function
    starts a QTimer that will periodically check the queue and invoke any callbacks
    that are waiting to be invoked (in whatever thread this QTimer is running in).

    Parameters
    ----------
    msec : int, optional
        The interval (in milliseconds) at which the QTimer will check the global
        emission queue.  By default, the QTimer will check the queue as often as
        possible (i.e. 0 milliseconds).
    timer_type : Qt.TimerType, optional
        The type of timer to use.  By default, Qt.PreciseTimer is used, which is
        the most accurate timer available on the system.
    thread : Thread, optional
        The thread in which to start the QTimer.  By default, the QTimer will be
        started in the thread from which this function is called.
    N)
r   r	   r   ÚtimeoutÚconnectr   ZsetTimerTypeZisActiveZsetIntervalÚstart)r
   r   r   Ú_thread© r   úS/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/psygnal/qt.pyÚstart_emitting_from_queue   s   
r   c                 C  s4   | du rt ƒ n| }t |¡ }dur| ¡  dS dS )zèStop the QTimer that monitors the global emission queue.

    thread : Thread, optional
        The thread in which to stop the QTimer. By default, will stop any QTimers
        in the thread from which this function is called.
    N)r   r	   ÚgetÚstop)r   r   Útimerr   r   r   Ústop_emitting_from_queueC   s   ÿr   )r
   r   r   r   r   r   r   r   )N)r   r   r   r   )Ú__doc__Ú
__future__r   Ú	threadingr   r   Ú_queuer   Zqtpy.QtCorer   r   ÚImportErrorÚRuntimeErrorr	   Ú__annotations__Z	TimerTypeZPreciseTimerr   r   r   r   r   r   Ú<module>   s&    ÿþÿý*