3
8ßL]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   ú:/tmp/pip-install-5sebvq2j/traitsui/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ÚcontrolÚ_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é   éÿÿÿÿr7   r7   )Lr#   ÚviewZ	resizableÚwxZRESIZE_BORDERÚtitler
   r   ZSetSizerÚresetÚhasattrr%   Z	IsEnabledr&   r   ÚDialogZDEFAULT_DIALOG_STYLEZFrameZDEFAULT_FRAME_STYLEZSetBackgroundColourr   Zset_iconZiconZ	EVT_CLOSEÚ_on_close_pageZEVT_CHARÚ_on_keyÚcontextÚ_contextÚ_copy_contextÚ_revertZBoxSizerZVERTICALZ
scrollabler   r   ÚAddZEXPANDÚALLZGetSizeTupleZSetScrollRater   ZSetSizeÚSizer   ÚminÚbuttonsÚlenZ	is_buttonZ
StaticLineZ
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'   r8   r:   r%   r&   Zwindowr@   Zsw_sizerZsizerÚswZtrait_sheetZtsdxZtsdyZmax_dyrH   ZnbuttonsZb_sizerZ
raw_buttonr.   r1   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   r9   ÚID_OKr   r   r#   r   ZEndModalÚfinishr&   r%   rL   )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/   r@   r   ÚnameÚvaluer   r   r   rB      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)rY   Zcopy_traitsr   rA   r8   Úon_apply)r/   Zfrom_contextZ
to_contextrZ   r[   r\   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   r8   Zclose_resultrQ   rS   )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    rX   r"   r]   r@   rA   r9   rU   )r/   r^   r   r   r   rQ   .  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    rX   r"   r]   rC   rA   r9   Z	ID_CANCEL)r/   r^   r   r   r   rS   9  s    zModalDialog._on_cancelc             C   s   |j ƒ dkr| j|ƒ dS )z3 Handles the user pressing the Escape key.
        é   N)Z
GetKeyCoder>   )r/   r^   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   r]   r@   rA   r<   r%   ÚEnabler    r&   r"   r2   )r/   r^   r   r   r   r   rN   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   r]   rC   r@   rA   r%   r`   r    r"   r2   )r/   r^   r   r   r   r   rP   ]  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&   r`   )r/   Ústater   r   r   rO   k  s    zModalDialog._on_applyablec             C   s   | j j|dkƒ dS )z! Handles editing errors.
        r   N)rJ   r`   )r/   r5   r   r   r   rR   t  s    zModalDialog._on_error)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r9   rU   rX   rB   r]   r>   rQ   rS   r?   rN   rP   rO   rR   r   r   r   r   r   h   s    


	r   )re   Ú
__future__r   r9   Ú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   

$