3
8ßL]ö  ã               @   s:  d Z ddlmZmZ ddlZddlZddlZddlmZ ddl	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 dd	lT dd
lmZ edƒržejdƒ‚edddd�ZG dd„ deƒZdd„ Zdd„ Zdd„ Zedd„ ƒZedd„ ƒZedd„ ƒZ ej!e" dƒe#d d!„ ƒƒZ$e#d"d#„ ƒZ%e&d$k�r6eƒ Z'e'j(ƒ  dS )%z3
Test that menu and toolbar actions are triggered.
é    )Úabsolute_importÚprint_functionN)Ú	HasTraits)ÚBool)ÚActionÚActionGroupÚMenuÚMenuBarÚToolBar)ÚItem)ÚView)Ú*)Ú_is_current_backendÚnullz$Not supported using the null backendZTestÚtest_clickedzClick to test)ÚnameÚactionZtooltipc               @   sd   e Zd ZdZedƒZdd„ Zeee	e
ƒdd�ƒZee	e
ƒƒZeedd�ed	d
d�eee
dgd�ZdS )ÚDialogWithToolbarz"Test dialog with toolbar and menu.Fc             C   s   t dƒ d| _d S )Nzperform actionT)ÚprintÚaction_successful)Úself© r   úA/tmp/pip-install-5sebvq2j/traitsui/traitsui/tests/test_actions.pyr   2   s    zDialogWithToolbar.test_clickedz
&Test menu)r   zfClick the button on the toolbar or the menu item.
The 'Action successful' element should turn to True.)Úlabelr   Úreadonly)ÚstyleÚOK)ÚmenubarÚtoolbarÚbuttonsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r	   r   r   Ú
TestActionr   r
   r   r   r   Ztraits_viewr   r   r   r   r   -   s   


r   c          	   C   s:   t ƒ �* tƒ }|jƒ }| |ƒ tjj|jƒ W dQ R X dS )z:Template test for wx, qt4, menu, and toolbar testing.
    N)Zstore_exceptions_on_all_threadsr   Zedit_traitsÚnoseZtoolsZassert_truer   )Ztrigger_action_funcÚdialogÚuir   r   r   Ú_test_actionsK   s
    r(   c             C   s$   |j j| ƒ}|jƒ d }|jƒ  d S )Nr   )ÚcontrolÚ	findChildÚactionsZtrigger)Zcontainer_classr'   r   r   r   r   r   Ú_qt_trigger_action_   s    r,   c             C   s<   ddl m} | jj|ƒ}|jƒ d }t|jƒ ƒ |jƒ  d S )Nr   )ÚQDialogButtonBoxé   )Zpyface.qt.QtGuir-   r)   r*   r   r   ÚtextZclick)r'   r-   ZbboxÚbuttonr   r   r   Ú_qt_click_buttone   s
    r1   c              C   s    t ttjjjjjƒ} t| ƒ d S )N)	Úpartialr,   Úpyfacer'   Úqt4r   Ztool_bar_managerZ_ToolBarr(   )Zqt_trigger_toolbar_actionr   r   r   Útest_qt_toolbar_actionm   s    	r5   c              C   s    t ttjjjjjƒ} t| ƒ d S )N)	r2   r,   r3   r'   r4   r   Zmenu_managerZ_Menur(   )Zqt_trigger_menu_actionr   r   r   Útest_qt_menu_action|   s    	r6   c               C   s   t tƒ d S )N)r(   r1   r   r   r   r   Útest_qt_button_action‹   s    	r7   zIProblem with triggering toolbar actions on Linux and Windows. Issue #428.c                 s    dd l ‰ ‡ fdd„} t| ƒ d S )Nr   c                sL   | j jjd jd }|jd }|j}ˆ jˆ j|ƒ}| jj	dƒ}|j
|ƒ d S )Nr   r   )Úviewr   ÚgroupsÚitemsZ	_wrappersÚ
control_idÚCommandEventZwxEVT_COMMAND_TOOL_CLICKEDr)   ZFindWindowByNameÚProcessEvent)r'   Ztoolbar_itemZtoolbar_item_wrapperr;   Úclick_eventr   )Úwxr   r   Ú_wx_trigger_toolbar_action¤   s    
z:test_wx_toolbar_action.<locals>._wx_trigger_toolbar_action)r?   r(   )r@   r   )r?   r   Útest_wx_toolbar_action™   s    	rA   c                 s    dd l ‰ ‡ fdd„} t| ƒ d S )Nr   c                sL   | j jƒ jƒ d jƒ }|jƒ d jƒ }|jƒ }ˆ jˆ j|ƒ}| j j|ƒ d S )Né   r   )r)   ZGetSizerZGetChildrenZ	GetWindowZGetIdr<   ZwxEVT_COMMAND_BUTTON_CLICKEDr=   )r'   Zbutton_sizerr0   r;   r>   )r?   r   r   Ú_wx_trigger_button_action»   s
    z8test_wx_button_action.<locals>._wx_trigger_button_action)r?   r(   )rC   r   )r?   r   Útest_wx_button_action´   s    rD   Ú__main__))r#   Ú
__future__r   r   r%   r3   ZunittestZtraits.has_traitsr   Ztraits.trait_typesr   Ztraitsui.menur   r   r   r	   r
   Ztraitsui.itemr   Ztraitsui.viewr   Ztraitsui.tests._toolsr   ZSkipTestr$   r   r(   r,   r1   Zskip_if_not_qt4r5   r6   r7   ZskipIfZ	is_mac_osZskip_if_not_wxrA   rD   r    ZvwZconfigure_traitsr   r   r   r   Ú<module>   s@   

