a
    §ˆcÛ%  ã                   @   sœ   d Z ddlZddlmZ ddlmZm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„ 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.
é    N)ÚSystemMetricsé   )Úsave_windowÚTraitsUIScrolledPanel)Ú
BaseDialog)Úpanel)ÚDefaultTitleÚWindowColorÚscrollbar_dx)ÚApplyButtonÚRevertButtonÚOKButtonÚCancelButtonÚ
HelpButtonc                 C   s   t | |tjƒ dS )zBCreates a modal wxPython user interface for a specified UI object.N)Ú
_ui_dialogr   ÚMODAL©ÚuiÚparent© r   úW/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/wx/ui_modal.pyÚui_modal$   s    r   c                 C   s   t | |tjƒ dS )zFCreates a non-modal wxPython user interface for a specified UI object.N)r   r   ZNONMODALr   r   r   r   Úui_nonmodal)   s    r   c                 C   s$   | j du rtƒ | _ t | ||¡ 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**.
    N)ÚownerÚModalDialogr   Z
display_ui)r   r   Ústyler   r   r   r   .   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   z2Modal dialog box for Traits-based user interfaces.c                    s(  |ˆ j kˆ _d}|j}|jr&|tjO }|j}|dkr8t}d }}|j}|d urŠ| 	d ¡ | 
¡  tˆ dƒrtˆ j ¡ }tˆ dƒrˆˆ j ¡ }n¦|ˆ _ˆ jr°tj|d||tjB d�}n tj|d||tjtj @ B d�}| t¡ |ˆ _ˆ  |j¡ | tjˆ j¡ | tjˆ j¡ |j}	|	|_ˆ  |	¡|_ˆ  |	¡|_ t !tj"¡}
|j#�rât !tj"¡}t$|ƒ}t%||ƒ}| &|dtj'tj(B d	¡ | )¡ \}}|d
7 }|d
7 }| *dd¡ dt+ƒ j, d }| 	|¡ | -t .|||kt/  t0||ƒ¡¡ n
t%||ƒ}|
 &|dtj'¡ ‡ fdd„|j1D ƒ}t2|ƒ}|dk�s4ˆ  3|d d¡�s|
 &t 4|d¡dtj'¡ t !tj5¡}|dk�rÆ|j�rŠˆ  6|t7¡ |j�rŠˆ  6|t8¡ |j9�ržˆ  6|t:¡ |j;�r²ˆ  6|t<¡ |j=�rÆˆ  6|t>¡ t?|j1|ƒD �]\}}||j@k}ˆ  3|d¡�r ˆ jA||ˆ jB||d�ˆ _|jCˆ jDddd� nÆˆ  3|d¡�rHˆ jA||ˆ jE||d�ˆ _nžˆ  3|d¡�r€ˆ jA||ˆ jF|d�ˆ _9|jCˆ jGddd� nfˆ  3|d¡�r¤ˆ jA||ˆ jH|d� nBˆ  3|d¡�rÈˆ jA||ˆ jI|d� nˆ  3|d¡�sÒˆ jA|||d� �qÒ|
 &|dtjJtj(B d¡ ˆ  K¡  ˆ  L¡  ˆ  M¡  | N|
¡ d S )Nr   Ú FÚrevertÚapplyéÿÿÿÿ)r   r   é   é   é   é   é   c                    s   g | ]}ˆ   |¡‘qS r   )Zcoerce_button)Ú.0Úbutton©Úselfr   r   Ú
<listcomp>…   ó    z$ModalDialog.init.<locals>.<listcomp>ZApply)ÚdefaultÚmodifiedr   )ÚdispatchZRevertÚOKÚerrorsZCancelZHelpé   )Or   Úis_modalÚviewZ	resizableÚwxZRESIZE_BORDERÚtitler   ÚcontrolZSetSizerÚresetÚhasattrr   Z	IsEnabledr   r   ÚDialogZDEFAULT_DIALOG_STYLEZFrameZDEFAULT_FRAME_STYLEZSetBackgroundColourr	   Zset_iconZiconZBindÚ	EVT_CLOSEÚ_on_close_pageÚEVT_CHARÚ_on_keyÚcontextÚ_contextÚ_copy_contextÚ_revertZBoxSizerZVERTICALZ
scrollabler   r   ÚAddZEXPANDÚALLZGetSizeZSetScrollRater   Zscreen_heightZSetSizeÚSizer
   ÚminÚbuttonsÚlenZ	is_buttonZ
StaticLineZ
HORIZONTALZcheck_buttonr   r   Úokr   Úcancelr   Úhelpr   ÚzipZdefault_buttonZ
add_buttonÚ	_on_applyZobserveÚ_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   r2   r4   r   r   Zwindowr=   Zsw_sizerZsizerÚswZtrait_sheetZtsdxZtsdyZmax_dyrE   ZnbuttonsZb_sizerZ
raw_buttonr&   r+   r   r'   r   Úinit>   sÚ    




ÿÿü


ÿÿ


ÿû

ÿ
ÿ
ÿzModalDialog.initc                 C   sr   | j }|tjk|_t|ƒ | jr,| j |¡ | j tj	¡ | j tj
¡ | ¡  d | _  | _ | _ | _| _dS )zCloses the dialog window.N)r   r3   ÚID_OKÚresultr   r1   r5   ZEndModalZUnbindr9   r;   Úfinishr   r   rI   )r(   Úrcr   r   r   r   ÚcloseË   s    zModalDialog.closec                 C   s8   i }|  ¡ D ]&\}}|dur*| ¡ ||< qd||< q|S )z)Creates a copy of a *context* dictionary.N)ÚitemsZclone_traits)r(   r=   rT   ÚnameÚvaluer   r   r   r?   Ù   s    
zModalDialog._copy_contextc                 C   sZ   |  ¡ D ](\}}|dur(||  |¡ qd||< q|| jju rV| jjj}|durV|ƒ  dS )z=Applies the traits in the *from_context* to the *to_context*.N)rX   Zcopy_traitsr   r>   r2   Úon_apply)r(   Zfrom_contextZ
to_contextrY   rZ   r[   r   r   r   Ú_apply_contextä   s    

zModalDialog._apply_contextc                 C   s$   | j jjr|  |¡ n
|  |¡ dS )z@Handles the user clicking the window/dialog "close" button/icon.N)r   r2   Zclose_resultrN   rP   ©r(   Úeventr   r   r   r:   ñ   s    
zModalDialog._on_close_pageNc                 C   s8   | j j | j jd¡r4|  | j j| j j¡ |  tj¡ dS )z@Closes the window and saves changes (if allowed by the handler).TN)	r   ÚhandlerrW   Úinfor\   r=   r>   r3   rS   r]   r   r   r   rN   ø   s    zModalDialog._on_okc                 C   s8   | j j | j jd¡r4|  | j j| j j¡ |  tj¡ dS )zCCloses the window and discards changes (if allowed by the handler).FN)	r   r_   rW   r`   r\   r@   r>   r3   Z	ID_CANCELr]   r   r   r   rP   þ   s    zModalDialog._on_cancelc                 C   s   |  ¡ dkr|  |¡ dS )z)Handles the user pressing the Escape key.é   N)Z
GetKeyCoder:   r]   r   r   r   r<     s    zModalDialog._on_keyc                 C   sD   | j }|  |j|j¡ t| dƒr,| j d¡ |j |j	¡ d|_
dS )z#Handles a request to apply changes.r   TFN)r   r\   r=   r>   r7   r   ÚEnabler_   r   r`   r,   ©r(   r^   r   r   r   r   rK   	  s    
zModalDialog._on_applyc                 C   sJ   | j }|  |j|j¡ |  |j|j¡ | j d¡ |j |j¡ d|_	dS )z$Handles a request to revert changes.FN)
r   r\   r@   r=   r>   r   rb   r_   r`   r,   rc   r   r   r   rM     s    zModalDialog._on_revertc                 C   s   |j }| j |¡ dS )z@Handles a change to the "modified" state of the user interface .N)Únewr   rb   )r(   r^   Ústater   r   r   rL     s    zModalDialog._on_applyablec                 C   s   |j }| j |dk¡ dS )zHandles editing errors.r   N)rd   rG   rb   )r(   r^   r/   r   r   r   rO      s    zModalDialog._on_error)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rR   r3   rS   rW   r?   r\   r:   rN   rP   r<   rK   rM   rL   rO   r   r   r   r   r   ;   s    

		r   )ri   r3   Z
pyface.apir   Úhelperr   r   Zui_baser   Zui_panelr   Ú	constantsr   r	   r
   Ztraitsui.menur   r   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s   	