3
8Ad]M5  ã               @   s¨   d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	 ddl
mZmZ ddlmZmZmZmZ dd	lmZmZmZmZmZ d
d„ Zdd„ Zdd„ ZG dd„ de	ƒZdS )z> Creates a wxPython user interface for a specified UI object.
é    )Úabsolute_importNé   )Úrestore_windowÚsave_windowÚTraitsUIScrolledPanel)Ú
BaseDialog)ÚpanelÚ	show_help)ÚDefaultTitleÚWindowColorÚ	screen_dyÚscrollbar_dx)ÚApplyButtonÚRevertButtonÚOKButtonÚCancelButtonÚ
HelpButtonc             C   s   t | |dƒ dS )zH Creates a modal wxPython user interface for a specified UI object.
    TN)Ú	ui_dialog)ÚuiÚparent© r   úp/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/traitsui-6.1.2-py3.6.egg/traitsui/wx/ui_modal.pyÚui_modal0   s    r   c             C   s   t | |dƒ dS )zL Creates a non-modal wxPython user interface for a specified UI object.
    FN)r   )r   r   r   r   r   Úui_nonmodal:   s    r   c          	   C   s¨   | j dkrtƒ | _ | j j| ||ƒ | j j| _|| j_y| jƒ  W n2   | jjƒ  d| j_d| _d| _ d| _‚ Y nX | j	j
| jƒ t| ƒ |rš| jjƒ  n
| jjƒ  dS )a   Creates a wxPython dialog box for a specified UI object.

    Changes are not immediately applied to the underlying object. The user must
    click **Apply** or **OK** to apply changes. The user can revert changes by
    clicking **Revert** or **Cancel**.
    NF)ÚownerÚModalDialogÚinitÚcontrolZ_parentZ
prepare_uiZDestroyr   ÚresultÚhandlerÚpositionÚinfor   Z	ShowModalZShow)r   r   Úis_modalr   r   r   r   D   s&    


r   c               @   sz   e Zd ZdZdd„ Zejfdd„Zdd„ Zdd	„ Z	d
d„ Z
ddd„Zddd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r   z8 Modal dialog box for Traits-based user interfaces.
    c                s   |ˆ _ d}|j}|jr |tjO }|j}|dkr2t}d }}|j}	|	d k	r„|	jd ƒ |j	ƒ  t
ˆ dƒrnˆ jjƒ }t
ˆ dƒr‚ˆ jjƒ }n |ˆ _|r¨tj|d||tjB d�}	n tj|d||tjtj @ B d�}	|	jtƒ |	ˆ _ˆ j|jƒ tj|	ˆ jƒ tj|	ˆ jƒ |j}
|
|_ˆ j|
ƒ|_ˆ j|
ƒ|_tjtj ƒ}|j!�rÒtjtj ƒ}t"|	ƒ}t#||ƒ}|j$|dtj%tj&B dƒ |j'ƒ \}}|d	7 }|d	7 }|j(d
d
ƒ dt) d }|j|ƒ |j*tj+|||kt,  t-||ƒƒƒ n
t#||	ƒ}|j$|dtj%ƒ ‡ fdd„|j.D ƒ}t/|ƒ}|dk�s&ˆ j0|d dƒ �rú|j$tj1|	dƒdtj%ƒ tjtj2ƒ}|dk�r¸|j�r|ˆ j3|t4ƒ |j�r|ˆ j3|t5ƒ |j6�r�ˆ j3|t7ƒ |j8�r¤ˆ j3|t9ƒ |j:�r¸ˆ j3|t;ƒ �x&t<|j.|ƒD �]\}}||j=k}ˆ j0|dƒ�rˆ j>||ˆ j?||d�ˆ _|j@ˆ jAddd� nÆˆ j0|dƒ�r>ˆ j>||ˆ jB||d�ˆ _nžˆ j0|dƒ�rvˆ j>||ˆ jC|d�ˆ _6|j@ˆ jDddd� nfˆ j0|dƒ�ršˆ j>||ˆ jE|d� nBˆ j0|dƒ�r¾ˆ j>||ˆ jF|d� nˆ j0|dƒ�sÈˆ j>|||d� �qÈW |j$|dtjGtj&B dƒ ˆ jHƒ  ˆ jIƒ  ˆ jJƒ  |	jK|ƒ d S )Nr   Ú FÚrevertÚapplyr   )Ústyleé   é   é   é   é   c                s   g | ]}ˆ j |ƒ‘qS r   )Zcoerce_button)Ú.0Úbutton)Úselfr   r   ú
<listcomp>­   s    z$ModalDialog.init.<locals>.<listcomp>ZApply)ÚdefaultÚmodifiedr   )ÚdispatchZRevertÚOKÚerrorsZCancelZHelpé   éÿÿÿÿr6   r6   )Lr"   ÚviewZ	resizableÚwxZRESIZE_BORDERÚtitler
   r   ZSetSizerÚresetÚhasattrr$   Z	IsEnabledr%   r   ÚDialogZDEFAULT_DIALOG_STYLEÚFrameZDEFAULT_FRAME_STYLEZSetBackgroundColourr   Zset_iconÚiconZ	EVT_CLOSEÚ_on_close_pageZEVT_CHARÚ_on_keyÚcontextÚ_contextÚ_copy_contextÚ_revertZBoxSizerÚVERTICALZ
scrollabler   r   ÚAddZEXPANDÚALLZGetSizeTupleZSetScrollRater   ÚSetSizeÚSizer   ÚminÚbuttonsÚlenZ	is_buttonZ
StaticLineÚ
HORIZONTALZcheck_buttonr   r   Úokr   Úcancelr   Úhelpr   ÚzipZdefault_buttonZ
add_buttonÚ	_on_applyZon_trait_changeÚ_on_applyableÚ
_on_revertÚ_on_okÚ	_on_errorÚ
_on_cancelZ_on_helpZALIGN_RIGHTZadd_menubarZadd_toolbarZadd_statusbarZSetSizerAndFit)r.   r   r   r"   r&   r7   r9   r$   r%   ÚwindowrA   Zsw_sizerZsizerÚswZtrait_sheetZtsdxZtsdyZmax_dyrK   ZnbuttonsZb_sizerZ
raw_buttonr-   r0   r   )r.   r   r   o   s¸    


















zModalDialog.initc             C   sV   | j }|tjk|_t|ƒ | jr,| jj|ƒ |jƒ  d | _  | _	 | _
 | _| _dS )z# Closes the dialog window.
        N)r   r8   ÚID_OKr   r   r"   r   ZEndModalÚfinishr%   r$   rP   )r.   Úrcr   r   r   r   Úcloseð   s    zModalDialog.closec             C   s<   i }x2|j ƒ D ]&\}}|dk	r,|jƒ ||< qd||< qW |S )z3 Creates a copy of a *context* dictionary.
        N)ÚitemsZclone_traits)r.   rA   r   ÚnameÚvaluer   r   r   rC      s    zModalDialog._copy_contextc             C   s^   x4|j ƒ D ](\}}|dk	r*|| j|ƒ q
d||< q
W || jjkrZ| jjj}|dk	rZ|ƒ  dS )zG Applies the traits in the *from_context* to the *to_context*.
        N)r^   Zcopy_traitsr   rB   r7   Úon_apply)r.   Zfrom_contextZ
to_contextr_   r`   ra   r   r   r   Ú_apply_context  s    
zModalDialog._apply_contextc             C   s$   | j jjr| j|ƒ n
| j|ƒ dS )zJ Handles the user clicking the window/dialog "close" button/icon.
        N)r   r7   Zclose_resultrU   rW   )r.   Úeventr   r   r   r?   "  s    
zModalDialog._on_close_pageNc             C   s8   | j jj| j jdƒr4| j| j j| j jƒ | jtjƒ dS )zJ Closes the window and saves changes (if allowed by the handler).
        TN)	r   r   r]   r!   rb   rA   rB   r8   rZ   )r.   rc   r   r   r   rU   .  s    zModalDialog._on_okc             C   s8   | j jj| j jdƒr4| j| j j| j jƒ | jtjƒ dS )zM Closes the window and discards changes (if allowed by the handler).
        FN)	r   r   r]   r!   rb   rD   rB   r8   Z	ID_CANCEL)r.   rc   r   r   r   rW   9  s    zModalDialog._on_cancelc             C   s   |j ƒ dkr| j|ƒ dS )z3 Handles the user pressing the Escape key.
        é   N)Ú
GetKeyCoder?   )r.   rc   r   r   r   r@   E  s    zModalDialog._on_keyc             C   sD   | j }| j|j|jƒ t| dƒr,| jjdƒ |jj|j	ƒ d|_
dS )z- Handles a request to apply changes.
        r$   TFN)r   rb   rA   rB   r;   r$   ÚEnabler   r%   r!   r1   )r.   rc   r   r   r   r   rR   O  s    
zModalDialog._on_applyc             C   sJ   | j }| j|j|jƒ | j|j|jƒ | jjdƒ |jj|jƒ d|_	dS )z. Handles a request to revert changes.
        FN)
r   rb   rD   rA   rB   r$   rf   r   r!   r1   )r.   rc   r   r   r   r   rT   ]  s    zModalDialog._on_revertc             C   s   | j j|ƒ dS )zJ Handles a change to the "modified" state of the user interface .
        N)r%   rf   )r.   Ústater   r   r   rS   k  s    zModalDialog._on_applyablec             C   s   | j j|dkƒ dS )z! Handles editing errors.
        r   N)rN   rf   )r.   r4   r   r   r   rV   t  s    zModalDialog._on_error)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r8   rZ   r]   rC   rb   r?   rU   rW   r@   rR   rT   rS   rV   r   r   r   r   r   h   s    


	r   )rk   Ú
__future__r   r8   Úhelperr   r   r   Zui_baser   Zui_panelr   r	   Ú	constantsr
   r   r   r   Ztraitsui.menur   r   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   

$