3
8ßL]  ã               @   s€   d Z ddlm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.
é    )Úabsolute_import)ÚQtCoreÚQtGui)ÚApplyButtonÚRevertButtonÚOKButtonÚCancelButtonÚ
HelpButtoné   )Ú
BaseDialog)Úpanelc             C   s   t | |tjƒ dS )zCCreates a modal PyQt user interface for a specified UI object.
    N)Ú
_ui_dialogr   ZMODAL)ÚuiÚparent© r   ú;/tmp/pip-install-5sebvq2j/traitsui/traitsui/qt4/ui_modal.pyÚui_modal"   s    r   c             C   s   t | |tjƒ dS )zGCreates a non-modal PyQt user interface for a specified UI object.
    N)r   r   ZNONMODAL)r   r   r   r   r   Úui_nonmodal(   s    r   c             C   s$   | j dkrtƒ | _ tj| ||ƒ 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   .   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   z7Modal dialog box for Traits-based user interfaces.
    c          	      s®  |ˆ _ |jˆ _|j}d }}ˆ jdk	rXtˆ dƒr:ˆ jjƒ }tˆ dƒrNˆ jjƒ }|jƒ  n0ˆ j||ƒ |j	}||_
ˆ j|ƒ|_	ˆ j|ƒ|_ˆ j|jƒ ‡ fdd„|jD ƒ}t|ƒ}	|	dksÌˆ j|d d	ƒ �r–tjƒ }
|	dk�rB|j�rˆ j|tƒ |j�rˆ j|tƒ |j�rˆ j|tƒ |j�r.ˆ j|tƒ |j�rBˆ j|tƒ �xTt|j|ƒD �]<\}}||jk}ˆ j|d
ƒ�r¦ˆ j||
tjj ˆ j!||d�ˆ _|j"ˆ j#ddd� nèˆ j|dƒ�rÔˆ j||
tjj$ˆ j%||d�ˆ _nºˆ j|dƒ�rˆ j||
tjj&ˆ jj'|d�ˆ _|j"ˆ j(ddd� nzˆ j|dƒ�r@ˆ j||
tjj)ˆ jj*|d� nNˆ j|dƒ�rjˆ j||
tjj+ˆ j,|d� n$ˆ j|d	ƒ�sRˆ j||
tjj-|d� �qRW nd}
ˆ j.t/|ƒ|
ƒ dS )zInitialise the object.
        FNÚrevertÚapplyc                s   g | ]}ˆ j |ƒ‘qS r   )Zcoerce_button)Ú.0Úbutton)Úselfr   r   ú
<listcomp>\   s    z%_ModalDialog.init.<locals>.<listcomp>r
   r   Ú ZApply)ZenabledÚdefaultÚmodifiedr   )ÚdispatchZRevertÚOK)r   ÚerrorsZCancelZHelp)0r   Ú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	ApplyRoleÚ	_on_applyZon_trait_changeÚ_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   Úinit?   sœ    












z_ModalDialog.initTc                s&   t t| ƒj|ƒ d | _ | _| _dS )z8Close the dialog and set the given return code.
        N)Úsuperr   Úcloser   r   r/   )r   Úrc)Ú	__class__r   r   r8   ¨   s    z_ModalDialog.closec             C   s<   i }x2|j ƒ D ]&\}}|dk	r,|jƒ ||< qd||< qW |S )z2Creates a copy of a *context* dictionary.
        N)ÚitemsZclone_traits)r   r'   ÚresultÚnameÚvaluer   r   r   r)   ¯   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 )zFApplies 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=   r>   r?   r   r   r   Ú_apply_context»   s    
z_ModalDialog._apply_contextc             C   sD   t |ƒ}|r"| j| jj| jjƒ n| j| jj| jjƒ | j|ƒ dS )z4Handles the user finishing with the dialog.
        N)Úboolr@   r   r'   r(   r*   r8   )r   r<   r4   r   r   r   Ú_on_finishedÉ   s
    z_ModalDialog._on_finishedc             C   s:   | j }| j|j|jƒ | jjdƒ |jj|jƒ d|_	dS )z,Handles a request to apply changes.
        TFN)
r   r@   r'   r(   r   Ú
setEnabledÚhandlerr   Úinfor   )r   r   r   r   r   r1   Õ   s
    z_ModalDialog._on_applyc             C   s   | j j|ƒ dS )zIHandles a change to the "modified" state of the user interface .
        N)r   rC   )r   Ústater   r   r   r2   Þ   s    z_ModalDialog._on_applyablec             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@   r*   r'   r(   r   rC   rD   rE   r   )r   r   r   r   r   r3   ã   s    z_ModalDialog._on_revert)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r6   r8   r)   r@   rB   r1   r2   r3   Ú__classcell__r   r   )r:   r   r   ;   s   i	r   N)rJ   Ú
__future__r   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   