a
    §ˆcî  ã                   @   sˆ   d 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).
é    )ÚQtCoreÚQtGui)ÚUndoHistory)Ú
UndoButtonÚRevertButtonÚOKButtonÚCancelButtonÚ
HelpButtoné   )Ú
BaseDialog)Úpanelc                 C   s   t | |tjƒ dS )zHCreates a live, non-modal PyQt user interface for a specified UI object.N)Ú
_ui_dialogr   ZNONMODAL©ÚuiÚparent© r   úW/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/qt4/ui_live.pyÚui_live2   s    r   c                 C   s   t | |tjƒ dS )zDCreates a live, modal PyQt user interface for a specified UI object.N)r   r   ZMODALr   r   r   r   Úui_livemodal7   s    r   c                 C   s   t | |tjƒ dS )zSCreates a live, modal popup PyQt user interface for a specified UI
    object.
    N)r   r   ZPOPUPr   r   r   r   Úui_popup<   s    r   c                 C   s$   | j du rtƒ | _ t | ||¡ dS )z=Creates a live PyQt user interface for a specified UI object.N)ÚownerÚ_LiveWindowr   Z
display_ui)r   r   Ústyler   r   r   r   C   s    
r   c                       s2   e Zd ZdZdd„ Zd	‡ fdd„	Zdd„ Z‡  ZS )
r   zHUser interface window that immediately updates its underlying object(s).c              	      s†  |ˆ _ |jˆ _|j}|j}ˆ jdurr|durh|jˆ jdddd� |jˆ jdddd� |jˆ jdddd� | ¡  nˆ  	||¡ ˆ  
|j¡ ‡ fdd„|jD ƒ}t|ƒ}|d	ko¼ˆ  |d
 d¡}| oâ|d
kpâ|jpâ|jpâ|jpâ|j}	|	sô|jdu�r|du �r
tƒ }nd}||_|�sn|	�s$|j�rnt ¡ }
|d
k�rš|j�rJˆ  |t¡ |j�r^ˆ  |t¡ |j�rrˆ  |t¡ |j�r†ˆ  |t¡ |j�ršˆ  |t¡ t|j|ƒD �]Â\}}||jk}ˆ  |d¡�rRˆ j ||
tjj!j"ˆ j#d|d�ˆ _|jˆ jddd� |j$�rˆ  d¡ ˆ   ||
tjj!j"ˆ j%dd¡ˆ _&|jˆ jddd� |j'�rhˆ  d¡ �q¦ˆ  |d¡�r¦ˆ j ||
tjj!j(ˆ j)d|d�ˆ _|jˆ jddd� |j$�rhˆ  d¡ nÂˆ  |d¡�rèˆ j ||
tjj!j*ˆ jj+|d�ˆ _|jˆ j,ddd� n€ˆ  |d¡�rˆ j ||
tjj!j-ˆ jj.|d� nRˆ  |d¡�rBˆ j ||
tjj!j/ˆ j0|d� n&ˆ  |d¡�s¦ˆ j ||
tjj!j"|d� �q¦nd}
ˆ  1t2|ƒ|
¡ 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undoableTr   )ÚremoveÚdispatchZredoablec                    s   g | ]}ˆ   |¡‘qS r   )Zcoerce_button)Ú.0Úbutton©Úselfr   r   Ú
<listcomp>l   ó    z$_LiveWindow.init.<locals>.<listcomp>r
   r   Ú ZUndoF)Údefault)r   ZRedoZRevertÚOKÚerrorsZCancelZHelp)3r   ÚcontrolÚviewÚhistoryZobserveZ_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
ButtonRoleZ
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   ÚinitN   sü    

ÿ
ÿ
ÿ
ÿþýû


úÿ
úÿúÿûûûüz_LiveWindow.initTc                    s"   t ƒ  |¡ d | _ | _| _dS )z/Close the dialog and set the given return code.N)ÚsuperÚcloser+   r1   r,   )r   Úrc©Ú	__class__r   r   r7   é   s    z_LiveWindow.closec                 C   s0   t |ƒ}|s"| jjdur"|  d¡ |  |¡ dS )z+Handles the user finishing with the dialog.N)Úboolr   r'   r2   r7   )r   Úresultr3   r   r   r   Ú_on_finishedï   s    
z_LiveWindow._on_finished)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r5   r7   r=   Ú__classcell__r   r   r9   r   r   K   s
    r   N)rA   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   