3
7ßL]Ò5  ã               @   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j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ÚUnicodeÚ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apptools.undo.api.IUndoManagerFc             K   s„   | j f d| i|—Ž}|jj| jjƒ | j|ƒ |j| jdƒ |j| jdƒ |j| jdƒ |j| j	dƒ |j| j
dƒ t|d�| _|S )z5 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on_trait_changeÚ_on_window_activatedÚ_on_window_openingÚ_on_window_openedÚ_on_window_closingÚ_on_window_closedr   Úwindow_created)ÚselfÚkwr   © r&   ú>/tmp/pip-install-5sebvq2j/pyface/pyface/workbench/workbench.pyÚcreate_windowl   s    
zWorkbench.create_windowc             C   sb   t jdƒ tƒ  | _}|jsLd| _t| jƒdkr:| jƒ }n
| | _	d}d| _nd}|s^t j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$   Úeventr1   r&   r&   r'   Úexitˆ   s    


zWorkbench.exitNTc             C   s   | j j|||ƒS )z0 Edit an object in the active workbench window. )Úactive_windowÚedit)r$   ÚobjÚkindZuse_existingr&   r&   r'   r5   ·   s    zWorkbench.editc             C   s   | j dkrdS | j j||ƒS )zg Return the editor that is editing an object.

        Returns None if no such editor exists.

        N)r4   Ú
get_editor)r$   r6   r7   r&   r&   r'   r8   ¼   s    
zWorkbench.get_editorc             C   s   | j j|ƒS )zc Return the editor with the specified Id.

        Returns None if no such editor exists.

        )r4   Úget_editor_by_id)r$   Úidr&   r&   r'   r9   È   s    zWorkbench.get_editor_by_idc             C   s   | j j||||ƒS )z3 Convenience method to show a confirmation dialog. )r4   Úconfirm)r$   ÚmessageÚtitleÚcancelÚdefaultr&   r&   r'   r;   Ó   s    zWorkbench.confirmÚInformationc             C   s   | j j||ƒS )z; Convenience method to show an information message dialog. )r4   Úinformation)r$   r<   r=   r&   r&   r'   rA   Ø   s    zWorkbench.informationÚWarningc             C   s   | j j||ƒS )z6 Convenience method to show a warning message dialog. )r4   Úwarning)r$   r<   r=   r&   r&   r'   rC   Ý   s    zWorkbench.warningÚErrorc             C   s   | j j||ƒS )z5 Convenience method to show an error message dialog. )r4   Úerror)r$   r<   r=   r&   r&   r'   rE   â   s    zWorkbench.errorc             C   s<   t jjtjddtjƒ}t jj|ƒs,t j|ƒ tj	d|ƒ |S )z 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,   yddl m} W n tk
r$   dS X |ƒ S )z Trait initializer. r   )ÚUndoManagerN)Zapptools.undo.apirM   ÚImportError)r$   rM   r&   r&   r'   Ú_undo_manager_defaultÿ   s
    zWorkbench._undo_manager_defaultc             C   s   t | jd�S )z Trait initializer. )rK   )r   rK   )r$   r&   r&   r'   Ú!_user_perspective_manager_default
  s    z+Workbench._user_perspective_manager_defaultc             K   s   t ‚dS )z5 Factory method that creates a new workbench window. N)ÚNotImplementedError)r$   r%   r&   r&   r'   Ú_create_window  s    zWorkbench._create_windowc             C   s:   | j dd… }|jƒ  x|D ]}|jƒ sd}P qW d}|S )z† Closes all open windows.

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

        NFT)r/   ÚreverseÚclose)r$   r/   r   Z
all_closedr&   r&   r'   r0     s    

zWorkbench._close_all_windowsc          	   C   sh   t jj| jdƒ}t jj|ƒrdy.t|dƒ}tjjj	|ƒ}|j
ƒ  |j|ƒ W n   tjd|ƒ Y nX dS )z Restore the window layout. Úwindow_mementoÚrbzrestoring window layout from %sN)rF   rG   rH   rK   rI   ÚopenÚsixÚmovesÚcPickleÚloadrT   Zset_mementor)   Ú	exception)r$   r   ÚfilenameÚfZmementor&   r&   r'   r   5  s    
z Workbench._restore_window_layoutc             C   s6   t tjj| jdƒdƒ}tjjj|j	ƒ |ƒ |j
ƒ  dS )z Save the window layout. rU   ÚwbN)rW   rF   rG   rH   rK   rX   rY   rZ   ÚdumpZget_mementorT   )r$   r   r^   r&   r&   r'   Ú_save_window_layoutM  s    zWorkbench._save_window_layoutc             C   s   t jd|ƒ || _dS )z Dynamic trait change handler. zwindow %s activatedN)r)   r*   r4   )r$   r   Ú
trait_namer2   r&   r&   r'   r   Y  s    zWorkbench._on_window_activatedc             C   s    t |d� | _}|jrd|_dS )z Dynamic trait change handler. )r   TN)r   Úwindow_openingr,   )r$   r   rb   r2   Úwindow_eventr&   r&   r'   r   b  s    zWorkbench._on_window_openingc             C   s"   | j j|ƒ || _t|d�| _dS )z Dynamic trait change handler. )r   N)r/   Úappendr4   r   Úwindow_opened)r$   r   rb   r2   r&   r&   r'   r    l  s    zWorkbench._on_window_openedc             C   s^   t |d� | _}|jrd|_n<t| jƒdkrZ| jsJtƒ  | _}|jrJd|_|jsZ| j|ƒ dS )z Dynamic trait change handler. )r   Tr   N)	r   Úwindow_closingr,   r.   r/   r-   r   r+   ra   )r$   r   rb   r2   rd   r&   r&   r'   r!   }  s    
zWorkbench._on_window_closingc             C   s0   | j j|ƒ t|d�| _t| j ƒdkr,| | _dS )z Dynamic trait change handler. )r   r   N)r/   Úremover   Úwindow_closedr.   r1   )r$   r   rb   r2   r&   r&   r'   r"   —  s
    zWorkbench._on_window_closed)NT)N)r@   )rB   )rD   )6Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r4   r   Zeditor_managerZscript_managerr   rK   Zundo_managerr   r   r
   r/   r   r+   r   r1   r   r#   r   rc   rf   rg   ri   r   r   r   r-   r(   r3   r5   r8   r9   r   r;   rA   rC   rE   rL   rO   rP   rR   r0   r   ra   r   r   r    r!   r"   r&   r&   r&   r'   r      sL   /




			
r   )#rm   Zsix.moves.cPicklerX   ÚloggingrF   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   rd   r   r   Ú	getLoggerrj   r)   r   r&   r&   r&   r'   Ú<module>   s    
