3
8ßL]†  ã               @   s”   d Z ddlmZ ddlmZmZ ddl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dd„ ZG dd„ deƒZdS )z’Creates a PyQt user interface for a specified UI object, where the UI is
   "live", meaning that it immediately updates its underlying object(s).
é    )Úabsolute_import)ÚQtCoreÚQtGui)ÚUndoHistory)Ú
UndoButtonÚRevertButtonÚOKButtonÚCancelButtonÚ
HelpButtoné   )Ú
BaseDialog)Úpanelc             C   s   t | |tjƒ dS )zMCreates a live, non-modal PyQt user interface for a specified UI object.
    N)Ú
_ui_dialogr   ZNONMODAL)ÚuiÚparent© r   ú:/tmp/pip-install-5sebvq2j/traitsui/traitsui/qt4/ui_live.pyÚui_live&   s    r   c             C   s   t | |tjƒ dS )zICreates a live, modal PyQt user interface for a specified UI object.
    N)r   r   ZMODAL)r   r   r   r   r   Úui_livemodal,   s    r   c             C   s   t | |tjƒ dS )zVCreates a live, modal popup PyQt user interface for a specified UI
       object.
    N)r   r   ZPOPUP)r   r   r   r   r   Úui_popup2   s    r   c             C   s$   | j dkrtƒ | _ tj| ||ƒ dS )zBCreates a live PyQt user interface for a specified UI object.
    N)ÚownerÚ_LiveWindowr   Z
display_ui)r   r   Ústyler   r   r   r   9   s    
r   c                   s2   e Zd ZdZdd„ Zd	‡ fdd„	Zdd„ Z‡  ZS )
r   zMUser interface window that immediately updates its underlying object(s).
    c          	      sv  |ˆ _ |jˆ _|j}|j}ˆ jdk	rl|dk	rb|jˆ jddd� |jˆ jddd� |jˆ jddd� |jƒ  nˆ j	||ƒ ˆ j
|jƒ ‡ fdd„|jD ƒ}t|ƒ}|dko¶ˆ j|d	 d
ƒ}| oÜ|d	kpÜ|jpÜ|jpÜ|jpÜ|j}	|	sì|jdk	rü|dkrútƒ }nd}||_| �r^|	�s|j�r^tjƒ }
|d	k�r’|j�rBˆ j|tƒ |j�rVˆ j|tƒ |j�rjˆ j|tƒ |j�r~ˆ j|tƒ |j�r’ˆ j|tƒ �xÌt|j|ƒD �]´\}}||jk}ˆ j|dƒ�rJˆ j ||
tjj!ˆ j"d|d�ˆ _|jˆ jddd� |j#�rˆ jdƒ ˆ j ||
tjj!ˆ j$ddƒˆ _%|jˆ jddd� |j&�rVˆ jdƒ �q¢ˆ j|dƒ�rœˆ j ||
tjj'ˆ j(d|d�ˆ _|jˆ jddd� |j#�rVˆ 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ƒ�r2ˆ j ||
tjj.ˆ j/|d� n$ˆ j|d
ƒ�s¢ˆ j ||
tjj!|d� �q¢W nd}
ˆ j0t1|ƒ|
ƒ dS )z¸Initialise the object.

           FIXME: Note that we treat MODAL and POPUP as equivalent until we
           have an example that demonstrates how POPUP is supposed to work.
        NZundoableT)ÚremoveZredoablec                s   g | ]}ˆ j |ƒ‘qS r   )Zcoerce_button)Ú.0Úbutton)Úselfr   r   ú
<listcomp>a   s    z$_LiveWindow.init.<locals>.<listcomp>r   r   Ú ZUndoF)Údefaultr   )ÚdispatchZRedoZRevertÚOKÚerrorsZCancelZHelp)2r   ÚcontrolÚviewÚhistoryZon_trait_changeZ_on_undoableZ_on_redoableZ_on_revertableÚresetZcreate_dialogZset_iconZiconÚbuttonsÚlenZ	is_buttonÚundoÚrevertÚokÚcancelZmenubarr   Úhelpr   ZQDialogButtonBoxZcheck_buttonr   r   r   r	   r
   ÚzipZdefault_buttonZ
add_buttonZ
ActionRoleZ_on_undoZcan_undoZ_on_redoÚredoZcan_redoZ	ResetRoleÚ
_on_revertZ
AcceptRoleÚacceptZ	_on_errorZ
RejectRoleÚrejectZHelpRoleZ_on_helpZadd_contentsr   )r   r   r   r   r$   r%   r'   Z
nr_buttonsZ
no_buttonsZhas_buttonsZbboxZ
raw_buttonr   r   r   )r   r   ÚinitF   sÌ    




 









z_LiveWindow.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   r5   Í   s    z_LiveWindow.closec             C   s2   t |ƒ}| r$| jjdk	r$| jdƒ | j|ƒ dS )z4Handles the user finishing with the dialog.
        N)Úboolr   r%   r0   r5   )r   Úresultr1   r   r   r   Ú_on_finishedÔ   s    
z_LiveWindow._on_finished)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r3   r5   r:   Ú__classcell__r   r   )r7   r   r   B   s
    r   N)r>   Ú
__future__r   Z	pyface.qtr   r   Ztraitsui.undor   Ztraitsui.menur   r   r   r	   r
   Zui_baser   Zui_panelr   r   r   r   r   r   r   r   r   r   Ú<module>   s   	