3
8ßL]›  ã               @   sè   d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZmZmZmZmZ ddlmZ ed	ƒZejd
kZerŽG dd„ deƒZG dd„ deƒZG dd„ deƒZeedƒdddgd�ZejedƒG dd„ deejƒƒZdS )é    )Úabsolute_importN)ÚCallbackTimer)Útoolkit_object)Ú	HasTraitsÚInstanceÚInt)ÚHandlerÚItemÚUIInfoÚViewÚtoolkité   )Úis_current_backend_qt4z(util.gui_test_assistant:GuiTestAssistantZUnimplementedc               @   s   e Zd ZdS )ÚGuiTestAssistantN)Ú__name__Ú
__module__Ú__qualname__© r   r   úJ/tmp/pip-install-5sebvq2j/traitsui/traitsui/tests/test_view_application.pyr      s   r   c               @   s   e Zd ZeZdS )ÚSimpleModelN)r   r   r   r   Úcellr   r   r   r   r      s   r   c               @   s$   e Zd ZeeƒZdd„ Zdd„ ZdS )ÚClosableHandlerc             C   s
   || _ dS )NT)Úinfo)Úselfr   r   r   r   Úinit$   s    zClosableHandler.initc             C   s   | j jjƒ  d S )N)r   ÚuiZdispose)r   r   r   r   Ú
test_close(   s    zClosableHandler.test_closeN)r   r   r   r   r
   r   r   r   r   r   r   r   r       s   r   r   zEnter IDs and conditionsÚOKÚCancel)ÚtitleZbuttonszNo GuiTestAssistantc               @   s¾   e Zd Zdd„ Zd.dd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ ZdS )/ÚTestViewApplicationc          	   C   sj   t j| ƒ tƒ | _tƒ | _d| _d| _tƒ rft	| j
jƒ ƒdkrf| jdd�� | jj| j
jƒ W d Q R X d S )NFr   é   )Úrepeat)r   ÚsetUpr   Úmodelr   ÚhandlerÚevent_loop_timeoutÚclosedr   ÚlenZqt_appZtopLevelWidgetsZevent_loop_with_timeoutÚguiÚinvoke_laterZcloseAllWindows)r   r   r   r   r#   6   s    
zTestViewApplication.setUpNc             C   sh   |d kr| j j| jƒ n| j j| j|d� tj| jdd�}ztƒ j| j	t
|| jd�| _W d |jƒ  X d S )N)Útextg      ð?)ÚcallbackÚinterval)ÚcontextÚviewÚkindr%   )r)   r*   Úclose_dialogÚclick_buttonr   Zsingle_shotÚstop_event_loopr   Úview_applicationr$   Úsimple_viewr%   ÚresultÚstop)r   r0   ÚbuttonZtimerr   r   r   r4   B   s    z$TestViewApplication.view_applicationc                sP   ˆ j ‡ fdd„ƒ�4 ˆ jjtƒ jˆ jt|ˆ jd� ˆ jjdˆ j	ƒ W d Q R X d S )Nc                  s   ˆ j S )N)r'   r   )r   r   r   Ú<lambda>W   s    zATestViewApplication.view_application_event_loop.<locals>.<lambda>)r.   r/   r0   r%   éd   )
Zevent_loop_until_conditionr)   r*   r   r4   r$   r5   r%   Zinvoke_afterr1   )r   r0   r   )r   r   Úview_application_event_loopV   s    
z/TestViewApplication.view_application_event_loopc             C   s*   t ƒ r| jjjjjƒ  d| _ntdƒ‚d S )NTzCan't close current backend)r   r%   r   r   ÚcontrolÚcloser'   ÚNotImplementedError)r   r   r   r   r1   a   s    z TestViewApplication.close_dialogc                sl   t ƒ r`ddlm} ddlm} || jjjj|‡ fdd„ƒ}|d krPt	dj
ˆ ƒƒ‚|jƒ  d| _ntdƒ‚d S )	Nr   )ÚQPushButton)Úfind_qt_widgetc                s   | j ƒ ˆ kS )N)r+   )Zwidget)r+   r   r   r9   p   s    z2TestViewApplication.click_button.<locals>.<lambda>zCan't find {} buttonTzCan't click current backend)r   Zpyface.qt.QtGuir?   Zpyface.ui.qt4.util.testingr@   r%   r   r   r<   ÚRuntimeErrorÚformatZclickr'   r>   )r   r+   r?   r@   r8   r   )r+   r   r2   h   s    
z TestViewApplication.click_buttonc             C   s   | j jƒ  d| _d S )NT)r)   r3   r&   )r   r   r   r   r3   y   s    
z#TestViewApplication.stop_event_loopc             C   s2   | j dƒ | j| jƒ | j| jƒ | j| jƒ d S )NÚmodal)r4   Ú
assertTruer'   ÚassertFalser&   r6   )r   r   r   r   Ú!test_modal_view_application_close}   s    
z5TestViewApplication.test_modal_view_application_closec             C   s2   | j dƒ | j| jƒ | j| jƒ | j| jƒ d S )NÚnonmodal)r4   rD   r'   rE   r&   r6   )r   r   r   r   Ú$test_nonmodal_view_application_close„   s    
z8TestViewApplication.test_nonmodal_view_application_closec             C   s2   | j dƒ | j| jƒ | j| jƒ | j| jƒ d S )NÚ	livemodal)r4   rD   r'   rE   r&   r6   )r   r   r   r   Ú%test_livemodal_view_application_close‹   s    
z9TestViewApplication.test_livemodal_view_application_closec             C   s2   | j dƒ | j| jƒ | j| jƒ | j| jƒ d S )NÚlive)r4   rD   r'   rE   r&   r6   )r   r   r   r   Ú test_live_view_application_close’   s    
z4TestViewApplication.test_live_view_application_closec             C   s6   | j ddd� | j| jƒ | j| jƒ | j| jƒ d S )NrC   r   )r8   )r4   rD   r'   rE   r&   r6   )r   r   r   r   Útest_modal_view_application_ok™   s    z2TestViewApplication.test_modal_view_application_okc             C   s6   | j ddd� | j| jƒ | j| jƒ | j| jƒ d S )NrG   r   )r8   )r4   rD   r'   rE   r&   r6   )r   r   r   r   Ú!test_nonmodal_view_application_ok    s    z5TestViewApplication.test_nonmodal_view_application_okc             C   s6   | j ddd� | j| jƒ | j| jƒ | j| jƒ d S )NrI   r   )r8   )r4   rD   r'   rE   r&   r6   )r   r   r   r   Ú"test_livemodal_view_application_ok§   s    z6TestViewApplication.test_livemodal_view_application_okc             C   s6   | j ddd� | j| jƒ | j| jƒ | j| jƒ d S )NrK   r   )r8   )r4   rD   r'   rE   r&   r6   )r   r   r   r   Útest_live_view_application_ok®   s    z1TestViewApplication.test_live_view_application_okc             C   s6   | j ddd� | j| jƒ | j| jƒ | j| jƒ d S )NrC   r   )r8   )r4   rD   r'   rE   r&   r6   )r   r   r   r   Ú"test_modal_view_application_cancelµ   s    z6TestViewApplication.test_modal_view_application_cancelc             C   s6   | j ddd� | j| jƒ | j| jƒ | j| jƒ d S )NrG   r   )r8   )r4   rD   r'   rE   r&   r6   )r   r   r   r   Ú%test_nonmodal_view_application_cancel¼   s    z9TestViewApplication.test_nonmodal_view_application_cancelc             C   s6   | j ddd� | j| jƒ | j| jƒ | j| jƒ d S )NrI   r   )r8   )r4   rD   r'   rE   r&   r6   )r   r   r   r   Ú&test_livemodal_view_application_cancelÃ   s    z:TestViewApplication.test_livemodal_view_application_cancelc             C   s6   | j ddd� | j| jƒ | j| jƒ | j| jƒ d S )NrK   r   )r8   )r4   rD   r'   rE   r&   r6   )r   r   r   r   Ú!test_live_view_application_cancelÊ   s    z5TestViewApplication.test_live_view_application_cancelc             C   s&   | j dƒ | j| jƒ | j| jƒ d S )NrC   )r;   rD   r'   rE   r&   )r   r   r   r   Ú+test_modal_view_application_eventloop_closeÑ   s    
z?TestViewApplication.test_modal_view_application_eventloop_closec             C   s&   | j dƒ | j| jƒ | j| jƒ d S )NrG   )r;   rD   r'   rE   r&   )r   r   r   r   Ú.test_nonmodal_view_application_eventloop_close×   s    
zBTestViewApplication.test_nonmodal_view_application_eventloop_closec             C   s&   | j dƒ | j| jƒ | j| jƒ d S )NrI   )r;   rD   r'   rE   r&   )r   r   r   r   Ú/test_livemodal_view_application_eventloop_closeÝ   s    
zCTestViewApplication.test_livemodal_view_application_eventloop_closec             C   s&   | j dƒ | j| jƒ | j| jƒ d S )NrK   )r;   rD   r'   rE   r&   )r   r   r   r   Ú*test_live_view_application_eventloop_closeã   s    
z>TestViewApplication.test_live_view_application_eventloop_close)N)r   r   r   r#   r4   r;   r1   r2   r3   rF   rH   rJ   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   r   r   r   r   r    3   s,   
r    )Ú
__future__r   ZunittestZpyface.timer.apir   Zpyface.toolkitr   Z
traits.apir   r   r   Ztraitsui.apir   r	   r
   r   r   Z_toolsr   r   r   Zno_gui_test_assistantÚobjectr   r   r5   ZskipIfZTestCaser    r   r   r   r   Ú<module>	   s$   
