a
    §ˆcO6  ã                   @   sÚ   d Z ddlZddlZddlZddl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mZmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZ e e¡Z eeƒG dd„ deƒƒZ!dS )z A workbench. é    N)Ú	ETSConfig)ÚNO)ÚBoolÚCallableÚEventÚ	HasTraitsÚprovides)ÚInstanceÚListÚStrÚVetoable)ÚVetoableEventé   )ÚIEditorManager)Ú
IWorkbench)ÚUserPerspectiveManager)ÚWorkbenchWindow)ÚWindowEventÚVetoableWindowEventc                   @   s@  e Zd ZdZeeƒZeeƒZedƒZ	e
ƒ ZedƒZeeƒZeeƒZeƒ Zeƒ ZeeƒZeeƒZeeƒZeeƒZeeƒZeZedƒZdd„ Z dd„ Z!d4dd„Z"d5dd„Z#dd„ Z$d	de%fdd„Z&d6dd„Z'd7dd„Z(d8dd„Z)dd„ Z*dd„ Z+d d!„ Z,d"d#„ Z-d$d%„ Z.d&d'„ Z/d(d)„ Z0d*d+„ Z1d,d-„ Z2d.d/„ Z3d0d1„ Z4d2d3„ Z5d	S )9Ú	Workbenchzˆ A workbench.

    There is exactly *one* workbench per application. The workbench can create
    any number of workbench windows.

    z(apptools.appscripting.api.IScriptManagerzpyface.undo.api.IUndoManagerFc                 K   s„   | j f d| i|¤Ž}|j | jj¡ |  |¡ | | jd¡ | | jd¡ | | jd¡ | | j	d¡ | | j
d¡ t|d�| _|S )ú5 Factory method that creates a new workbench window. Ú	workbenchZ	activatedZopeningZopenedÚclosingÚclosed©Úwindow)Úwindow_factoryZperspectivesÚextendÚuser_perspective_managerÚ_restore_window_layoutZobserveÚ_on_window_activatedÚ_on_window_openingÚ_on_window_openedÚ_on_window_closingÚ_on_window_closedr   Úwindow_created)ÚselfÚkwr   © r(   ú]/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/workbench/workbench.pyÚcreate_windowu   s    
zWorkbench.create_windowc                 C   sb   t  d¡ tƒ  | _}|jsLd| _t| jƒdkr:|  ¡ }n
| | _	d}d| _nd}|s^t  d¡ |S )a]   Exits the workbench.

        This closes all open workbench windows.

        This method is not called when the user clicks the close icon. Nor when
        they do an Alt+F4 in Windows. It is only called when the application
        menu File->Exit item is selected.

        Returns True if the exit succeeded, False if it was vetoed.

        z**** exiting the workbench ****Tr   Fz&**** exit of the workbench vetoed ****)
ÚloggerÚdebugr   ÚexitingÚvetoÚ_explicit_exitÚlenÚwindowsÚ_close_all_windowsÚexited)r&   Úeventr3   r(   r(   r)   Úexit‘   s    


zWorkbench.exitNTc                 C   s   | j  |||¡S )z0 Edit an object in the active workbench window. )Úactive_windowÚedit)r&   ÚobjÚkindZuse_existingr(   r(   r)   r7   À   s    zWorkbench.editc                 C   s   | j du rdS | j  ||¡S )zg Return the editor that is editing an object.

        Returns None if no such editor exists.

        N)r6   Ú
get_editor)r&   r8   r9   r(   r(   r)   r:   Å   s    
zWorkbench.get_editorc                 C   s   | j  |¡S )zc Return the editor with the specified Id.

        Returns None if no such editor exists.

        )r6   Úget_editor_by_id)r&   Úidr(   r(   r)   r;   Ñ   s    zWorkbench.get_editor_by_idc                 C   s   | j  ||||¡S )z3 Convenience method to show a confirmation dialog. )r6   Úconfirm)r&   ÚmessageÚtitleÚcancelÚdefaultr(   r(   r)   r=   Ü   s    zWorkbench.confirmÚInformationc                 C   s   | j  ||¡S )z; Convenience method to show an information message dialog. )r6   Úinformation©r&   r>   r?   r(   r(   r)   rC   á   s    zWorkbench.informationÚWarningc                 C   s   | j  ||¡S )z6 Convenience method to show a warning message dialog. )r6   ÚwarningrD   r(   r(   r)   rF   æ   s    zWorkbench.warningÚErrorc                 C   s   | j  ||¡S )z5 Convenience method to show an error message dialog. )r6   ÚerrorrD   r(   r(   r)   rH   ë   s    zWorkbench.errorc                 C   s<   t j tjddtj¡}t j |¡s,t  |¡ t 	d|¡ |S )ú Trait initializer. Zpyfacer   zworkbench state location is %s)
ÚosÚpathÚjoinr   Zapplication_homeZtoolkitÚexistsÚmakedirsr+   r,   )r&   Ústate_locationr(   r(   r)   Ú_state_location_defaultö   s    ü
z!Workbench._state_location_defaultc                 C   s,   zddl m} W n ty$   Y dS 0 |ƒ S )rI   r   )ÚUndoManagerN)Zpyface.undo.apirQ   ÚImportError)r&   rQ   r(   r(   r)   Ú_undo_manager_default  s
    zWorkbench._undo_manager_defaultc                 C   s   t | jd�S )rI   )rO   )r   rO   )r&   r(   r(   r)   Ú!_user_perspective_manager_default  s    z+Workbench._user_perspective_manager_defaultc                 K   s
   t ƒ ‚dS )r   N)ÚNotImplementedError)r&   r'   r(   r(   r)   Ú_create_window  s    zWorkbench._create_windowc                 C   s8   | j dd… }| ¡  |D ]}| ¡ sd} q4qd}|S )z† Closes all open windows.

        Returns True if all windows were closed, False if the user changed
        their mind ;^)

        NFT)r1   ÚreverseÚclose)r&   r1   r   Z
all_closedr(   r(   r)   r2   %  s    
zWorkbench._close_all_windowsc                 C   sd   t j | jd¡}t j |¡r`z*t|dƒ}t |¡}| ¡  | 	|¡ W n   t
 d|¡ Y n0 dS )z Restore the window layout. Úwindow_mementoÚrbzrestoring window layout from %sN)rJ   rK   rL   rO   rM   ÚopenÚpickleÚloadrX   Zset_mementor+   Ú	exception)r&   r   ÚfilenameÚfZmementor(   r(   r)   r   >  s    

z Workbench._restore_window_layoutc                 C   s2   t tj | jd¡dƒ}t | ¡ |¡ | ¡  dS )z Save the window layout. rY   ÚwbN)	r[   rJ   rK   rL   rO   r\   ÚdumpZget_mementorX   )r&   r   r`   r(   r(   r)   Ú_save_window_layoutT  s    zWorkbench._save_window_layoutc                 C   s   |j }t d|¡ || _dS )ú Dynamic trait change handler. zwindow %s activatedN)Úobjectr+   r,   r6   ©r&   r4   r   r(   r(   r)   r    `  s    zWorkbench._on_window_activatedc                 C   s(   |j }t|d� | _}|jr$d|j_dS )rd   r   TN)re   r   Úwindow_openingr.   Únew©r&   r4   r   Úwindow_eventr(   r(   r)   r!   g  s    zWorkbench._on_window_openingc                 C   s(   |j }| j |¡ || _t|d�| _dS )rd   r   N)re   r1   Úappendr6   r   Úwindow_openedrf   r(   r(   r)   r"   o  s    zWorkbench._on_window_openedc                 C   sj   |j }t|d� | _}|jr&d|j_n@t| jƒdkrf| jsTtƒ  | _	}|jrTd|j_|jjsf|  
|¡ dS )rd   r   Tr   N)re   r   Úwindow_closingr.   rh   r0   r1   r/   r   r-   rc   ri   r(   r(   r)   r#   ~  s    
zWorkbench._on_window_closingc                 C   s6   |j }| j |¡ t|d�| _t| jƒdkr2| | _dS )rd   r   r   N)re   r1   Úremover   Úwindow_closedr0   r3   rf   r(   r(   r)   r$   –  s    zWorkbench._on_window_closed)NT)N)rB   )rE   )rG   )6Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r6   r   Zeditor_managerZscript_managerr   rO   Zundo_managerr   r   r
   r1   r   r-   r   r3   r   r%   r   rg   rl   rm   ro   r   r   r   r/   r*   r5   r7   r:   r;   r   r=   rC   rF   rH   rP   rS   rT   rV   r2   r   rc   r    r!   r"   r#   r$   r(   r(   r(   r)   r   $   sL   
/




		r   )"rs   r\   ÚloggingrJ   Ztraits.etsconfig.apir   Z
pyface.apir   Z
traits.apir   r   r   r   r   r	   r
   r   r   r   Zi_editor_managerr   Zi_workbenchr   r   r   Zworkbench_windowr   rj   r   r   Ú	getLoggerrp   r+   r   r(   r(   r(   r)   Ú<module>
   s    
