a
    §ˆca"  ã                   @   sz   d Z ddlZddlmZmZmZmZmZmZm	Z	m
Z
 ddlmZ ddlmZ e e¡ZG dd„ deƒZG dd	„ d	eƒZdS )
z| Define a base Task application class to create the event loop, and launch
the creation of tasks and corresponding windows.
é    N)ÚCallableÚHasStrictTraitsÚListÚInstanceÚPropertyÚStrÚcached_propertyÚobserve)Útrait)ÚGUIApplicationc                   @   s(   e Zd ZdZeƒ Zeƒ ZeZdd„ Z	dS )ÚTaskFactoryzB A factory for creating a Task with some additional metadata.
    c                 K   s   | j f i |¤ŽS )ze Creates the Task.

        The default implementation simply calls the 'factory' attribute.
        )Úfactory)ÚselfZtraits© r   úa/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/tasks/tasks_application.pyÚcreate4   s    zTaskFactory.createN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚidÚnamer   r   r   r   r   r   r   r   "   s
   r   c                       s¼   e Zd ZdZeedƒƒZeedƒjddd�d�Z	eƒ Z
eedƒƒZeed	ƒƒZeeƒZd
d„ Zd‡ fdd„	Zdd„ Zdd„ Zedƒ‡ fdd„ƒZdd„ Zdd„ Zdd„ Zedd„ ƒZ‡  ZS )ÚTasksApplicationz1 A base class for Pyface tasks applications.
    zpyface.tasks.task.TaskÚactive_windowÚactive_taskT)Úoptional)r	   z0pyface.tasks.task_window_layout.TaskWindowLayoutz3pyface.action.schema.schema_addition.SchemaAdditionc                 C   sT   |   |¡}|du r&t d |¡¡ dS |j|jd�}|j | j¡ |j | j¡ |S )zÿ Creates the Task with the specified ID.

        Parameters
        ----------
        id : str
            The id of the task factory to use.

        Returns
        -------
        The new Task, or None if there is not a suitable TaskFactory.
        NzCould not find task factory {})r   )	Ú_get_task_factoryÚloggerÚwarningÚformatr   r   Úextra_actionsÚextendÚextra_dock_pane_factories)r   r   r   Útaskr   r   r   Úcreate_taska   s    
zTasksApplication.create_taskNc                    sx   ddl m} tƒ jf i |¤Ž}|durd| ¡ D ]2}|  |¡}|durP| |¡ q.d}t ||¡ q.n|ƒ }| 	|¡ |S )a”   Connect task to application and open task in a new window.

        Parameters
        ----------
        layout : TaskLayout instance or None
            The pane layout for the window.
        **kwargs : dict
            Additional keyword arguments to pass to the window factory.


        Returns
        -------
        window : ITaskWindow instance or None
            The new TaskWindow.
        r   ©ÚTaskWindowLayoutNz#Missing factory for task with ID %r)
Úpyface.tasks.task_window_layoutr&   ÚsuperÚcreate_windowZ	get_tasksr$   Zadd_taskr   ÚerrorZset_window_layout)r   ÚlayoutÚkwargsr&   ÚwindowZtask_idr#   Úmsg©Ú	__class__r   r   r)   w   s    

zTasksApplication.create_windowc                 C   s*   | j D ]}|  |¡}|  |¡ || _qdS )zH Create the initial windows to display from the default layout.
        N)Údefault_layoutr)   Z
add_windowr   )r   r+   r-   r   r   r   Ú_create_windows›   s    


z TasksApplication._create_windowsc                 C   s"   | j D ]}|j|kr|  S qdS )zA Returns the TaskFactory with the specified ID, or None.
        N)Útask_factoriesr   )r   r   r   r   r   r   r   §   s    


z"TasksApplication._get_task_factoryzwindows:items:closedc                    s6   |j }t|ddƒ| jv r&| j |j¡ tƒ  |¡ dS )zH Listener that ensures window handles are released when closed.
        r   N)ÚobjectÚgetattrÚtasksÚremover   r(   Ú_on_window_closed)r   Úeventr-   r/   r   r   r8   ±   s    z"TasksApplication._on_window_closedc                 C   s   ddl m} |S )z§ Default to TaskWindow.

        This will be sufficient in many cases as customized behaviour comes
        from the Task and the TaskWindow is just a shell.
        r   )Ú
TaskWindow)Zpyface.tasks.task_windowr:   )r   r:   r   r   r   Ú_window_factory_default¼   s    z(TasksApplication._window_factory_defaultc                 C   s.   ddl m} |ƒ }| jr(| jd jg|_|gS )Nr   r%   )r'   r&   r3   r   Úitems)r   r&   Zwindow_layoutr   r   r   Ú_default_layout_defaultÆ   s
    z(TasksApplication._default_layout_defaultc              
      s¨   ddl m}m}m} ddlm‰ m} ddlm}m	‰ ||j
ˆdd�dd�|d	|j
ˆd
d�dd�|d|j
ˆd�ddd�|‡ ‡‡fdd„dddd�|d|j
ˆd�ddd�gS )aØ   Extra application-wide menu items

        This adds a collection of standard Tasks application menu items and
        groups to a Task's set of menus.  Whether or not they actually appear
        depends on whether the appropriate menus are provided by the Task.

        These default additions assume that the window will hold an editor pane
        so that Ctrl-N and Ctrl-W will be bound to creating/closing new editors
        rather than new task windows.
        r   )ÚAboutActionÚCloseActiveWindowActionÚ
ExitAction)ÚSMenuÚSchemaAddition)ÚCreateTaskWindowActionÚTaskWindowToggleGroupzCtrl+Shift+N)ÚapplicationZacceleratorzMenuBar/File/new_group)r   ÚpathZclose_actionzCtrl+Shift+WzMenuBar/File/close_group)r   r   rF   Zexit_action©rE   Úlast)r   r   rF   Zabsolute_positionc                      s   ˆ ˆˆd�ddd�S )NrG   ZWindowz&Window)r   r   r   r   ©rA   rD   r   r   r   Ú<lambda>ú   s   ýz9TasksApplication._extra_actions_default.<locals>.<lambda>ZMenuBarZViewZHelp)r   rF   ÚafterÚbeforeZabout_actionzMenuBar/HelpÚfirst)Zpyface.action.apir>   r?   r@   Zpyface.action.schema.apirA   rB   Zpyface.tasks.action.apirC   rD   r   )r   r>   r?   r@   rB   rC   r   rI   r   Ú_extra_actions_defaultÎ   sF    ÿüÿû
ü÷
üáz'TasksApplication._extra_actions_defaultc                 C   s    | j d urt| j dd ƒS d S d S )Nr   )r   r5   )r   r   r   r   Ú_get_active_task  s    
z!TasksApplication._get_active_task)N)r   r   r   r   r   r   r6   r   r
   r   r3   r1   r    r   r"   r$   r)   r2   r   r	   r8   r;   r=   rN   r   rO   Ú__classcell__r   r   r/   r   r   <   s0   
ÿÿÿ$


=r   )r   ÚloggingZ
traits.apir   r   r   r   r   r   r   r	   Ztraits.observation.apir
   Zpyface.gui_applicationr   Ú	getLoggerr   r   r   r   r   r   r   r   Ú<module>
   s   (

