a
    §ˆc	9  ã                   @   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 dd
lmZmZmZmZmZ dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZG dd„ deƒZG dd„ dejƒZdS )z˜ Creates a wxPython user interface for a specified UI object, where the UI
    is "live", meaning that it immediately updates its underlying object(s).
é    N)ÚSystemMetricsé   )Úsave_windowÚTraitsUIScrolledPanel)Ú
BaseDialog)Úpanel)ÚDefaultTitleÚWindowColorÚscrollbar_dx)ÚUndoHistory)Ú
UndoButtonÚRevertButtonÚOKButtonÚCancelButtonÚ
HelpButtonc                 C   s   t | |tjƒ dS )zUCreates a live, non-modal wxPython user interface for a specified UI
    object.
    N)Ú
_ui_dialogr   ÚNONMODAL©ÚuiÚparent© r   úV/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/wx/ui_live.pyÚui_live+   s    r   c                 C   s   t | |tjƒ dS )zHCreates a live, modal wxPython user interface for a specified UI object.N)r   r   ÚMODALr   r   r   r   Úui_livemodal2   s    r   c                 C   s   t | |tjƒ dS ©z[Creates a live, temporary popup wxPython user interface for a specified
    UI object.
    N)r   r   ZPOPUPr   r   r   r   Úui_popup7   s    r   c                 C   s   t | |tjƒ dS r   )r   r   ZPOPOVERr   r   r   r   Ú
ui_popover>   s    r   c                 C   s   t | |tjƒ dS r   )r   r   ÚINFOr   r   r   r   Úui_infoE   s    r   c                 C   s$   | j du rtƒ | _ t | ||¡ dS )zACreates a live wxPython user interface for a specified UI object.N)ÚownerÚ
LiveWindowr   Z
display_ui)r   r   Ústyler   r   r   r   L   s    
r   c                   @   sx   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„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r!   zHUser interface window that immediately updates its underlying object(s).c                    sÀ  |ˆ j kˆ _d}|j}|jr&|tjO }|j}|dkr8t}|j}|j	}|d ur¦|d ur�|j
ˆ jdddd� |j
ˆ jdddd� |j
ˆ jdddd� | d ¡ | ¡  �n.|ˆ _|ˆ j kræ|jrÌ|tjtjB O }tj|d||tjB d	�}n¾|ˆ jk�r.|d u�r|tjtjB O }tj|d||tjtj @ B d	�}nv|dk�r>tj}|d u�rX|tjtjB O }t|tƒ�r~tjd dd|d	�}||_ntj|dd|d	�}|jj|_t |ƒˆ _!| "t#¡ |ˆ _	| $tj%ˆ j&¡ | $tj'ˆ j(¡ ˆ  )|j*¡ ‡ fd
d„|j+D ƒ}	t,|	ƒ}
|
dk�oˆ  -|	d d¡}| �oD|
dk�pD|j.�pD|j/�pD|j0�pD|j1}|�sX|j2d u�rj|d u �rnt3ƒ }nd }||_t 4tj5¡}|j6�rt 4tj5¡}t7|ƒ}t8||ƒ}| 9|dtj:¡ | ;¡ \}}| <dd¡ dt=ƒ j> d }| |¡ | ?t @|||ktA  tB||ƒ¡¡ n
t8||ƒ}| 9|dtj:¡ | C| ;¡ ¡ |�s’|�sJ|jD�r’| 9t E|d¡dtj:¡ t 4tjF¡}|
dk�rÜ|j.�rŒˆ  G|	tH¡ |j/�r ˆ  G|	tI¡ |j0�r´ˆ  G|	tJ¡ |j1�rÈˆ  G|	tK¡ |jD�rÜˆ  G|	tL¡ tM|j+|	ƒD �]Ž\}}ˆ  N|¡}||jOk}ˆ  -|d¡�rŒˆ jP||ˆ jQd|d�ˆ _.ˆ  P||ˆ jRdd¡ˆ _S|j
ˆ jddd� |j
ˆ jddd� |jT�rxˆ  d¡ |jU�rvˆ  d¡ nêˆ  -|d¡�rØˆ jP||ˆ jVd|d�ˆ _/|j
ˆ jddd� |jT�rvˆ  d¡ nžˆ  -|d¡�rˆ jP||ˆ jW|d�ˆ _0|j
ˆ jXddd� nfˆ  -|d¡�r4ˆ jP||ˆ jY|d� nBˆ  -|d¡�rXˆ jP||ˆ jZ|d� nˆ  -|d¡�sèˆ jP|||d� �qè| 9|dtj[tj\B d¡ ˆ  ]¡  ˆ  ^¡  ˆ  _¡  | |¡ | `¡  d S )Nr   Ú ZundoableTr   )ÚremoveÚdispatchZredoableéÿÿÿÿ)r"   c                    s   g | ]}ˆ   |¡‘qS r   )Úcoerce_button)Ú.0Úbutton©Úselfr   r   Ú
<listcomp>    ó    z#LiveWindow.init.<locals>.<listcomp>r   é   é   é   ZUndoF)ÚdefaultZRedo)r%   ZRevertÚOKÚerrorsZCancelZHelpé   )ar   Úis_modalÚviewZ	resizableÚwxZRESIZE_BORDERÚtitler   ÚhistoryÚcontrolZobserveÚ_on_undoableÚ_on_redoableÚ_on_revertableZSetSizerÚresetr   ZMAXIMIZE_BOXZMINIMIZE_BOXÚDialogZDEFAULT_DIALOG_STYLEr   ZFRAME_FLOAT_ON_PARENTZFRAME_NO_TASKBARZFrameZDEFAULT_FRAME_STYLEZSIMPLE_BORDERÚ
isinstanceÚtupleÚ_control_regionÚkindÚ_kindÚMouseMonitorÚ_monitorZSetBackgroundColourr	   ZBindÚ	EVT_CLOSEÚ_on_close_pageÚEVT_CHARÚ_on_keyZset_iconZiconÚbuttonsÚlenZ	is_buttonÚundoÚrevertÚokÚcancelZmenubarr   ZBoxSizerZVERTICALZ
scrollabler   r   ÚAddZEXPANDÚGetSizeZSetScrollRater   Zscreen_heightZSetSizeÚSizer
   ÚminZ
SetMinSizeÚhelpZ
StaticLineZ
HORIZONTALZcheck_buttonr   r   r   r   r   Úzipr'   Zdefault_buttonZ
add_buttonZ_on_undoZ_on_redoÚredoZcan_undoZcan_redoÚ
_on_revertÚ_on_okÚ	_on_errorÚ
_on_cancelZ_on_helpZALIGN_RIGHTÚALLZadd_menubarZadd_toolbarZadd_statusbarZFit)r+   r   r   r"   Zwindow_styler6   r8   r9   ZwindowrK   ZnbuttonsZ
no_buttonsZhas_buttonsZsw_sizerZsizerÚswZtrait_sheetZtsdxZtsdyZmax_dyZb_sizerZ
raw_buttonr)   r1   r   r*   r   ÚinitW   sN   

ÿ
ÿ
ÿ

ü

ÿÿü


ÿ



ÿþýû


ÿÿ



ÿÿÿÿ
ûÿ
ÿ
ÿ
ÿ
zLiveWindow.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   r7   ÚID_OKÚresultr   r5   r:   ZEndModalÚUnbindrG   rI   ÚfinishrM   rW   rN   )r+   Úrcr   r   r   r   Úclose#  s    zLiveWindow.closec                 C   s$   | j jjs|  |¡ n
|  |¡ dS )z@Handles the user clicking the window/dialog "close" button/icon.N)r   r6   Zclose_resultr[   rY   ©r+   Úeventr   r   r   rH   1  s    
zLiveWindow._on_close_pagec                 C   s   |  ¡ s|  ¡  dS )zCHandles the user giving focus to another window for a 'popup' view.N)Z	GetActiveÚclose_popupre   r   r   r   Ú_on_close_popup8  s    zLiveWindow._on_close_popupc                 C   s0   | j jd ur,| j jj d ur,|  ¡ r,| j ¡  d S )N)r   ÚinforY   rF   ÚStopr*   r   r   r   rg   =  s    zLiveWindow.close_popupNc                 C   sN   | j du s| jdu rdS | j j | j jd¡rJ| j tj¡ |  tj¡ dS dS )z,Handles the user clicking the **OK** button.NTF)	r   r:   Úhandlerrd   ri   ra   r7   ZEVT_ACTIVATEr_   re   r   r   r   rY   C  s    zLiveWindow._on_okc                 C   s   |  ¡ dkr|  |¡ dS )z)Handles the user pressing the Escape key.é   N)Z
GetKeyCoderH   re   r   r   r   rJ   O  s    zLiveWindow._on_keyc                 C   s.   | j j | j jd¡r*|  |¡ |  tj¡ dS )z(Handles a request to cancel all changes.FN)r   rk   rd   ri   rX   r7   Z	ID_CANCELre   r   r   r   r[   T  s    
zLiveWindow._on_cancelc                 C   s   |j }| j |dk¡ dS )zHandles editing errors.r   N)ÚnewrO   ÚEnable)r+   rf   r3   r   r   r   rZ   Z  s    zLiveWindow._on_errorc                 C   s   |j }| j |¡ dS )z<Handles a change to the "undoable" state of the undo historyN)rm   rM   rn   ©r+   rf   Ústater   r   r   r;   _  s    zLiveWindow._on_undoablec                 C   s   |j }| j |¡ dS )z<Handles a change to the "redoable state of the undo history.N)rm   rW   rn   ro   r   r   r   r<   d  s    zLiveWindow._on_redoablec                 C   s   |j }| j |¡ dS )z'Handles a change to the "revert" state.N)rm   rN   rn   ro   r   r   r   r=   i  s    zLiveWindow._on_revertable)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r^   r7   r_   rd   rH   rh   rg   rY   rJ   r[   rZ   r;   r<   r=   r   r   r   r   r!   T   s    M
r!   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )rE   zfMonitors a specified window and closes it the first time the mouse
    pointer leaves the window.
    c                    sJ   t ƒ  ¡  || _|jj}|dk | _| _d| _|dkr<d| _|  d¡ d S )Nri   r0   Zpopupé
   éd   )	ÚsuperÚ__init__r   r6   rC   Úis_activatedÚis_infoÚborderZStart)r+   r   rC   ©Ú	__class__r   r   rx   t  s    
zMouseMonitor.__init__c                 C   sŒ  | j }|j}|jd u r"|  ¡  d S t ¡ \}}| dd¡\}}| ¡ \}}| j�rBt ¡ }	|	 	¡ sr|	 
¡ sr|	 ¡ rvd S | jrê| ¡ }
t|
tjƒr¢|
 ¡ \}}}}n|j\}}}}||k sØ||| ksØ||k sØ||| krè|j ¡  d| _nV| j}||| k �s0||| | k�s0||| k �s0||| | k�rˆ|j ¡  d| _nF||  k�r^|| k �rˆn n&||  k�r~|| k �rˆn nd| _d S )Nr   FT)r   r:   rj   r7   ZGetMousePositionZClientToScreenrR   ry   ZGetMouseStateZ
LeftIsDownZMiddleIsDownZRightIsDownrz   Z	GetParentr@   ZWindowZGetScreenRectrB   r    rg   r{   )r+   r   r:   ZmxZmyZcxÚcyZcdxZcdyÚmsr   ZpxÚpyZpdxZpdyr{   r   r   r   ÚNotify~  sP    
ÿ
þý
ü

ÿþ
ýü
@zMouseMonitor.Notify)rq   rr   rs   rt   rx   r�   Ú__classcell__r   r   r|   r   rE   o  s   
rE   ) rt   r7   Z
pyface.apir   Úhelperr   r   Zui_baser   Zui_panelr   Ú	constantsr   r	   r
   Ztraitsui.undor   Ztraitsui.menur   r   r   r   r   r   r   r   r   r   r   r!   ÚTimerrE   r   r   r   r   Ú<module>   s$     