a
    §ˆcü  ã                   @   st   d Z ddlmZ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„ Zd	d
„ Zdd„ ZG dd„ deƒZdS )z9Creates a PyQt user interface for a specified UI object.
é    )ÚQtCoreÚQtGui)ÚApplyButtonÚRevertButtonÚOKButtonÚCancelButtonÚ
HelpButtoné   )Ú
BaseDialog)Úpanelc                 C   s   t | |tjƒ dS )z>Creates a modal PyQt user interface for a specified UI object.N)Ú
_ui_dialogr
   ZMODAL©ÚuiÚparent© r   úX/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/ui_modal.pyÚui_modal/   s    r   c                 C   s   t | |tjƒ dS )zBCreates a non-modal PyQt user interface for a specified UI object.N)r   r
   ZNONMODALr   r   r   r   Úui_nonmodal4   s    r   c                 C   s$   | j du rtƒ | _ t | ||¡ dS )a  Creates a PyQt 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   9   s    
r   c                       sZ   e Zd ZdZdd„ Zd‡ fdd„	Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Z‡  ZS )r   z2Modal dialog box for Traits-based user interfaces.c              	      s²  |ˆ _ |jˆ _|j}d }}ˆ jdurXtˆ dƒr:ˆ j ¡ }tˆ dƒrNˆ j ¡ }| ¡  n0ˆ  ||¡ |j	}||_
ˆ  |¡|_	ˆ  |¡|_ˆ  |j¡ ‡ fdd„|jD ƒ}t|ƒ}	|	dksÊˆ  |d d	¡�sšt ¡ }
|	dk�r@|j�rˆ  |t¡ |j�rˆ  |t¡ |j�rˆ  |t¡ |j�r,ˆ  |t¡ |j�r@ˆ  |t¡ t|j|ƒD �]H\}}||jk}ˆ  |d
¡�r¢ˆ j||
tjj j!ˆ j"||d�ˆ _|j#ˆ j$ddd� nòˆ  |d¡�rÒˆ j||
tjj j%ˆ j&||d�ˆ _nÂˆ  |d¡�rˆ j||
tjj j'ˆ jj(|d�ˆ _|j#ˆ j)ddd� n€ˆ  |d¡�rBˆ j||
tjj j*ˆ jj+|d� nRˆ  |d¡�rnˆ j||
tjj j,ˆ j-|d� n&ˆ  |d	¡�sLˆ j||
tjj j.|d� �qLnd}
ˆ  /t0|ƒ|
¡ dS )zInitialise the object.FNÚrevertÚapplyc                    s   g | ]}ˆ   |¡‘qS r   )Zcoerce_button)Ú.0Úbutton©Úselfr   r   Ú
<listcomp>e   ó    z%_ModalDialog.init.<locals>.<listcomp>r	   r   Ú ZApply)ZenabledÚdefaultÚmodifiedr   )ÚdispatchZRevertÚOK)r    ÚerrorsZCancelZHelp)1r   ÚcontrolÚviewÚhasattrr   Z	isEnabledr   ÚresetZcreate_dialogÚcontextÚ_contextÚ_copy_contextÚ_revertZset_iconZiconÚbuttonsÚlenZ	is_buttonr   ZQDialogButtonBoxZcheck_buttonr   r   Úokr   Úcancelr   Úhelpr   ÚzipZdefault_buttonZ
add_buttonZ
ButtonRoleZ	ApplyRoleÚ	_on_applyZobserveÚ_on_applyableZ	ResetRoleÚ
_on_revertZ
AcceptRoleÚacceptZ	_on_errorZ
RejectRoleÚrejectZHelpRoleZ_on_helpZ
ActionRoleZadd_contentsr   )r   r   r   r   r&   r   r   r)   r-   Z
nr_buttonsZbboxZ
raw_buttonr   r    r   r   r   ÚinitI   s¬    







úú
	ûûûüz_ModalDialog.initTc                    s"   t ƒ  |¡ d | _ | _| _dS )z/Close the dialog and set the given return code.N)ÚsuperÚcloser   r   r1   )r   Úrc©Ú	__class__r   r   r:   ¹   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)   ÚresultÚ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)r>   Zcopy_traitsr   r*   r&   Úon_apply)r   Zfrom_contextZ
to_contextr@   rA   rB   r   r   r   Ú_apply_contextÊ   s    

z_ModalDialog._apply_contextc                 C   sD   t |ƒ}|r"|  | jj| jj¡ n|  | jj| jj¡ |  |¡ dS )z+Handles the user finishing with the dialog.N)ÚboolrC   r   r)   r*   r,   r:   )r   r?   r6   r   r   r   Ú_on_finished×   s
    z_ModalDialog._on_finishedc                 C   s:   | j }|  |j|j¡ | j d¡ |j |j¡ d|_	dS )z#Handles a request to apply changes.TFN)
r   rC   r)   r*   r   Ú
setEnabledÚhandlerr   Úinfor!   ©r   r   r   r   r   r3   â   s
    z_ModalDialog._on_applyc                 C   s   |j }| j |¡ dS )z@Handles a change to the "modified" state of the user interface .N)Únewr   rF   )r   ÚeventÚstater   r   r   r4   ê   s    z_ModalDialog._on_applyablec                 C   sJ   | j }|  |j|j¡ |  |j|j¡ | j d¡ |j |j¡ d|_	dS )z$Handles a request to revert changes.FN)
r   rC   r,   r)   r*   r   rF   rG   rH   r!   rI   r   r   r   r5   ï   s    z_ModalDialog._on_revert)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r8   r:   r+   rC   rE   r3   r4   r5   Ú__classcell__r   r   r<   r   r   F   s   pr   N)rP   Z	pyface.qtr   r   Ztraitsui.menur   r   r   r   r   Zui_baser
   Zui_panelr   r   r   r   r   r   r   r   r   Ú<module>   s   