a
    §ˆc¯  ã                   @   sD   d dl mZ d dlmZmZ d dlmZ h d£ZG dd„ deƒZdS )é    )ÚActionController)ÚAnyÚInstance)ÚAction>   ZUndoZRevertZHelpZRedoZApplyZCancelÚOKc                   @   sŽ   e Zd ZdZeƒ ZedƒZdd„ Zdd„ Z	dd„ Z
d	d
„ Zddd„Zddd„Zd dd„Zd!dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )"Ú	BasePanela  Base class for Traits UI panels and dialog boxes.

    Concrete subclasses of BasePanel are the Python-side owners of the
    top-level toolkit control for a UI.  They also implement the Pyface
    ActionController API for menu and toolbar action handling.
    ztraitsui.ui.UIc                 C   s   ddl m} |dƒS )z,Return a default icon for a TraitsUI dialog.r   )ÚImageResourcez	frame.png)Zpyface.image_resourcer   )Úselfr   © r
   úV/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/base_panel.pyÚdefault_icon!   s    zBasePanel.default_iconc                 C   s0   |j }|D ]}|  ||¡r
 dS q
| |¡ dS )zlAdds *action* to the system buttons list for this dialog, if it is
        not already in the list.
        N)ÚnameÚ	is_buttonÚappend)r	   ZbuttonsÚactionr   Úbuttonr
   r
   r   Úcheck_button'   s
    zBasePanel.check_buttonc                 C   s   t |tƒr||kS |j|kS )z=Returns whether a specified action button is a system button.)Ú
isinstanceÚstrr   )r	   r   r   r
   r
   r   r   1   s    
zBasePanel.is_buttonc                 C   s&   t |tƒr"t||tv rdndd�S |S )z+Coerces a string to an Action if necessary.Ú ú?)r   r   )r   r   r   ÚSystemButtons©r	   r   r
   r
   r   Úcoerce_button7   s
    
ÿzBasePanel.coerce_buttonNc                 C   s   | j j ¡  dS )z!Handles an "Undo" change request.N)ÚuiÚhistoryZundo©r	   Úeventr
   r
   r   Ú_on_undoA   s    zBasePanel._on_undoc                 C   s   | j j ¡  dS )z Handles a "Redo" change request.N)r   r   Zredor   r
   r
   r   Ú_on_redoE   s    zBasePanel._on_redoc                 C   s,   | j }|jdur|j ¡  |j |j¡ dS )z(Handles a request to revert all changes.N)r   r   ÚrevertÚhandlerÚinfo)r	   r   r   r
   r
   r   Ú
_on_revertI   s    

zBasePanel._on_revertc                 C   s   | j j | j j¡ dS )z*Handles the user clicking the Help button.N)r   r!   Z	show_helpr"   r   r
   r
   r   Ú_on_helpP   s    zBasePanel._on_helpc                 C   s$   | j j}| j  |j| j j||¡ dS )ay  Dispatches the action to be handled by the handler.

        Parameters
        ----------
        action : Action instance
            The action to perform.
        event : ActionEvent instance
            The event that triggered the action.

        Returns
        -------
        result : any
            The result of the action's perform method (usually None).
        N)r   r!   Zdo_undoableÚperformr"   )r	   r   r   r!   r
   r
   r   r%   X   s    zBasePanel.performc                 C   sz   |j }|j}|jdkr(| jj |j|¡ |jdkrB| j |j|¡ |jdkr\| j 	|j|¡ |j
dkrv| j |j
|¡ dS )aØ  Adds a menu item to the menu bar being constructed.

        The bulk of the back-end work is done in Pyface.  This code is simply
        responsible for hooking up radio groups, checkboxes, and enabled
        status.

        This routine is also used to add items to the toolbar, as logic and
        APIs are identical.

        Parameters
        ----------

        menu_item : toolkit MenuItem
            The Pyface toolkit-level item to add to the menu.
        r   N)Úitemr   Úidr   r"   ÚbindZenabled_whenZadd_enabledZvisible_whenZadd_visibleZchecked_whenZadd_checked)r	   Z	menu_itemr&   r   r
   r
   r   Úadd_to_menuj   s    



zBasePanel.add_to_menuc                 C   s   |   |¡ dS )aÀ  Adds a menu item to the menu bar being constructed.

        The bulk of the back-end work is done in Pyface.  This code is simply
        responsible for hooking up radio groups, checkboxes, and enabled
        status.

        This simply calls the analagous menu as logic and APIs are identical.

        Parameters
        ----------

        toolbar_item : toolkit Tool
            The Pyface toolkit-level item to add to the toolbar.
        N)r)   )r	   Ztoolbar_itemr
   r
   r   Úadd_to_toolbar‰   s    zBasePanel.add_to_toolbarc                 C   s   |j dkrdS | j |j ¡S )a|  Should the toolbar action be defined in the user interface.

        This simply calls the analagous menu as logic and APIs are identical.

        Parameters
        ----------

        action : Action
            The Action to add to the toolbar.

        Returns
        -------
        defined : bool
            Whether or not the action should be added to the menu.
        r   T)Zdefined_whenr   Z	eval_whenr   r
   r
   r   Úcan_add_to_menuš   s    
zBasePanel.can_add_to_menuc                 C   s
   |   |¡S )a  Should the toolbar action be defined in the user interface.

        This simply calls the analagous menu as logic and APIs are identical.

        Parameters
        ----------

        action : Action
            The Action to add to the toolbar.

        Returns
        -------
        defined : bool
            Whether or not the action should be added to the toolbar.
        )r+   r   r
   r
   r   Úcan_add_to_toolbar¯   s    zBasePanel.can_add_to_toolbar)N)N)N)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úcontrolr   r   r   r   r   r   r   r   r#   r$   r%   r)   r*   r+   r,   r
   r
   r
   r   r      s    





r   N)	Zpyface.action.apir   Z
traits.apir   r   Ztraitsui.menur   r   r   r
   r
   r
   r   Ú<module>   s   