a
    §ˆc8  ã                   @   sŠ   d dl Z d dlmZmZ d dlmZmZmZmZm	Z	 d dl
mZ d dlmZmZ e  e¡ZeeƒG dd„ deeƒƒZG dd	„ d	ejƒZdS )
é    N)ÚQtCoreÚQtGui)ÚBoolÚ	HasTraitsÚobserveÚprovidesÚStr)Ústart_event_loop_qt4)ÚIGUIÚMGUIc                   @   s¤   e Zd ZdZedƒZedƒZeƒ Zddd„Z	e
dd„ ƒZe
dd	„ ƒZe
d
d„ ƒZe
dd„ ƒZeddd„ƒZeddd„ƒZdd„ Zdd„ Zdd„ Zedƒdd„ ƒZdS )ÚGUIzj The toolkit specific implementation of a GUI.  See the IGUI interface
    for the API documentation.
    FNc                 C   s   || _ | j d ur| j  ¡  d S ©N)Ú_splash_screenÚopen)ÚselfZsplash_screen© r   úT/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/ui/qt4/gui.pyÚ__init__2   s    
zGUI.__init__c                 O   s   t ||g|¢R i |¤Ž d S r   ©Ú_FutureCall)ÚclsÚ	millisecsÚcallableÚargsÚkwr   r   r   Úinvoke_after=   s    zGUI.invoke_afterc                 O   s   t d|g|¢R i |¤Ž d S ©Nr   r   )r   r   r   r   r   r   r   Úinvoke_laterA   s    zGUI.invoke_laterc                 C   s   t |t|||ƒ d S r   ©r   Úsetattr)r   r   ÚobjÚ
trait_nameÚnewr   r   r   Úset_trait_afterE   s    zGUI.set_trait_afterc                 C   s   t dt|||ƒ d S r   r   )r   r    r!   r"   r   r   r   Úset_trait_laterI   s    zGUI.set_trait_laterTc                 C   s*   | rt jjj}n
t jjj}t j |¡ d S r   )r   Z
QEventLoopZProcessEventsFlagZ	AllEventsZExcludeUserInputEventsZQCoreApplicationZprocessEvents)Zallow_user_eventsÚeventsr   r   r   Úprocess_eventsM   s    
zGUI.process_eventsc                 C   s&   | rt j tjjj¡ n
t j ¡  d S r   )r   ÚQApplicationÚsetOverrideCursorr   ÚQtÚCursorShapeÚ
WaitCursorÚrestoreOverrideCursor)Úbusyr   r   r   Úset_busyV   s    zGUI.set_busyc                 C   s<   | j d ur| j  ¡  |  | dd¡ t d¡ tƒ  d| _d S )NÚstartedTz----------- starting GUI event loop ----------F)r   Úcloser$   ÚloggerÚdebugr	   r/   ©r   r   r   r   Ústart_event_loopa   s    


zGUI.start_event_loopc                 C   s   t  d¡ tj ¡  d S )Nz----------- stopping GUI event loop ----------)r1   r2   r   r'   Úquitr3   r   r   r   Ústop_event_loopn   s    
zGUI.stop_event_loopc                 C   s   |   ¡ S )z% The default state location handler. )Z_default_state_locationr3   r   r   r   Ú_state_location_defaultv   s    zGUI._state_location_defaultr-   c                 C   s,   |j }|rtj tjjj¡ n
tj ¡  dS )z  The busy trait change handler. N)	r"   r   r'   r(   r   r)   r*   r+   r,   )r   Úeventr"   r   r   r   Ú_update_busy_state{   s    zGUI._update_busy_state)N)T)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r-   r/   r   Zstate_locationr   Úclassmethodr   r   r#   r$   Ústaticmethodr&   r.   r4   r6   r7   r   r9   r   r   r   r   r       s,   





r   c                       sZ   e Zd ZdZg Ze ¡ Zej 	ej 
¡ ¡Z‡ fdd„Z‡ fdd„Zdd„ Zdd	„ Z‡  ZS )
r   zD This is a helper class that is similar to the wx FutureCall class. c                    s†   t ƒ  ¡  || _|| _|| _|| _| j ¡  z| j 	| ¡ W | j 
¡  n| j 
¡  0 |  tj ¡  ¡ ¡ t | j¡}tj | |¡ d S r   )Úsuperr   Ú_msÚ	_callableÚ_argsÚ_kwÚ_calls_mutexÚlockÚ_callsÚappendÚunlockZmoveToThreadr   r'   ÚinstanceÚthreadr   ÚQEventÚ_pyface_eventZ	postEvent)r   Úmsr   r   r   r8   ©Ú	__class__r   r   r   ‘   s    

z_FutureCall.__init__c              
      sx   |  ¡ | jkrl| jdkrVz(| j| ji | j¤Ž W tj d| j	¡ qhtj d| j	¡ 0 ntj | j| j
¡ dS tƒ  |¡S )z  QObject event handler.
        r   T)ÚtyperM   rA   rB   rC   rD   r   ZQTimerZ
singleShotÚ	_finishedÚ	_dispatchr@   r8   )r   r8   rO   r   r   r8   ª   s    
&z_FutureCall.eventc                 C   s0   z | j | ji | j¤Ž W |  ¡  n
|  ¡  0 dS )z Invoke the callable.
        N)rB   rC   rD   rR   r3   r   r   r   rS   ¾   s    z_FutureCall._dispatchc                 C   s6   | j  ¡  z| j | ¡ W | j  ¡  n| j  ¡  0 dS )zH Remove the call from the list, so it can be garbage collected.
        N)rE   rF   rG   ÚremoverI   r3   r   r   r   rR   Æ   s    
z_FutureCall._finished)r:   r;   r<   r=   rG   r   ZQMutexrE   rL   ÚTypeZregisterEventTyperM   r   r8   rS   rR   Ú__classcell__r   r   rO   r   r   …   s   r   )ÚloggingZ	pyface.qtr   r   Z
traits.apir   r   r   r   r   Zpyface.util.guisupportr	   Zpyface.i_guir
   r   Ú	getLoggerr:   r1   r   ZQObjectr   r   r   r   r   Ú<module>   s   
d