3
7ßL]Ô  ã               @   s†   d dl Z d dlmZ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 e j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ÚprovidesÚUnicode)Ú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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 k	r| j jƒ  d S )N)Ú_splash_screenÚopen)ÚselfZsplash_screen© r   ú5/tmp/pip-install-5sebvq2j/pyface/pyface/ui/qt4/gui.pyÚ__init__3   s    
zGUI.__init__c             O   s   t ||f|ž|Ž d S )N)Ú_FutureCall)ÚclsÚ	millisecsÚcallableÚargsÚkwr   r   r   Úinvoke_after>   s    zGUI.invoke_afterc             O   s   t d|f|ž|Ž d S )Nr   )r   )r   r   r   r   r   r   r   Úinvoke_laterB   s    zGUI.invoke_laterc             C   s   t |t|||ƒ d S )N)r   Úsetattr)r   r   ÚobjÚ
trait_nameÚnewr   r   r   Úset_trait_afterF   s    zGUI.set_trait_afterc             C   s   t dt|||ƒ d S )Nr   )r   r   )r   r   r   r   r   r   r   Úset_trait_laterJ   s    zGUI.set_trait_laterTc             C   s&   | rt jj}nt jj}t jj|ƒ d S )N)r   Z
QEventLoopZ	AllEventsZExcludeUserInputEventsZQCoreApplicationZprocessEvents)Zallow_user_eventsÚeventsr   r   r   Úprocess_eventsN   s    
zGUI.process_eventsc             C   s$   | rt jjtjjƒ n
t jjƒ  d S )N)r   ÚQApplicationÚsetOverrideCursorr   ÚQtÚ
WaitCursorÚrestoreOverrideCursor)Úbusyr   r   r   Úset_busyW   s    zGUI.set_busyc             C   s<   | j d k	r| j jƒ  | j| ddƒ tjdƒ tƒ  d| _d S )NÚstartedTz----------- starting GUI event loop ----------F)r   Úcloser   ÚloggerÚdebugr   r)   )r   r   r   r   Ústart_event_loopb   s    


zGUI.start_event_loopc             C   s   t jdƒ tjjƒ  d S )Nz----------- stopping GUI event loop ----------)r+   r,   r   r"   Úquit)r   r   r   r   Ústop_event_loopo   s    
zGUI.stop_event_loopc             C   s   | j ƒ S )z% The default state location handler. )Z_default_state_location)r   r   r   r   Ú_state_location_defaultw   s    zGUI._state_location_defaultc             C   s$   |rt jjtjjƒ n
t jjƒ  dS )z  The busy trait change handler. N)r   r"   r#   r   r$   r%   r&   )r   r   r   r   r   Ú_busy_changed|   s    zGUI._busy_changed)N)T)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r'   r)   r   Zstate_locationr   Úclassmethodr   r   r   r   Ústaticmethodr!   r(   r-   r/   r0   r1   r   r   r   r   r       s"   

r   c                   sZ   e Zd ZdZg Zejƒ Zejj	ej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 t| ƒjƒ  || _|| _|| _|| _| jjƒ  z| j	j
| ƒ W d | jjƒ  X | jtjjƒ jƒ ƒ tj| jƒ}tjj| |ƒ d S )N)Úsuperr   r   Ú_msÚ	_callableÚ_argsÚ_kwÚ_calls_mutexÚlockÚ_callsÚappendÚunlockZmoveToThreadr   r"   ÚinstanceÚthreadr   ÚQEventÚ_pyface_eventZ	postEvent)r   Úmsr   r   r   Úevent)Ú	__class__r   r   r   ‘   s    
z_FutureCall.__init__c                sh   |j ƒ | jkrX| jdkrBz| j| j| jŽ W dtjjd| j	ƒ X ntjj| j| j
ƒ dS tt| ƒj|ƒS )z  QObject event handler.
        r   NT)ÚtyperE   r9   r:   r;   r<   r   ZQTimerZ
singleShotÚ	_finishedÚ	_dispatchr8   r   rG   )r   rG   )rH   r   r   rG   ª   s    
z_FutureCall.eventc          
   C   s$   z| j | j| jŽ W d| jƒ  X dS )z Invoke the callable.
        N)r:   r;   r<   rJ   )r   r   r   r   rK   ¾   s    z_FutureCall._dispatchc          
   C   s,   | j jƒ  z| jj| ƒ W d| j jƒ  X dS )zH Remove the call from the list, so it can be garbage collected.
        N)r=   r>   r?   ÚremoverA   )r   r   r   r   rJ   Æ   s    
z_FutureCall._finished)r2   r3   r4   r5   r?   r   ZQMutexr=   rD   ÚTypeZregisterEventTyperE   r   rG   rK   rJ   Ú__classcell__r   r   )rH   r   r   …   s   r   )ÚloggingZ	pyface.qtr   r   Z
traits.apir   r   r   r   Zpyface.util.guisupportr   Zpyface.i_guir	   r
   Ú	getLoggerr2   r+   r   ZQObjectr   r   r   r   r   Ú<module>   s   

d