a
    ¦ˆc—Š  ã                   @   s˜   d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
 ddlmZmZ ddlmZ ddlmZ ddlmZ dd	lmZmZ dd
lmZ G dd„ deƒZdS )a   Implements the DockWindowFeature base class.

    A DockWindowFeature is an optional feature of a DockControl that can be
    dynamically contributed to the package. Whenever a DockControl is added to
    a DockWindow, each feature will be given the opportunity to add itself to
    the DockControl.

    Each feature is manifested as an image that appears on the DockControl tab
    (or drag bar). The user interacts wth the feature using mouse clicks and
    drag and drop operations (depending upon how the feature is implemented).
é    ©Úref)ÚHasPrivateTraitsÚInstanceÚIntÚStrÚBoolÚPropertyÚobserve)ÚMenuÚAction)Údo_later)ÚImageé   )Ú
DockWindow)ÚDockControlÚadd_feature)ÚIFeatureToolc                   @   s„  e Zd ZdZdZdZg ZeeƒZ	e
ƒ Zeƒ Zeƒ Zeƒ ZedƒZedƒZedƒZeZdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Z dd„ Z!dd„ Z"dd„ Z#dd „ Z$d!d"„ Z%d#d$„ Z&d%d&„ Z'd'd(„ Z(d)d*„ Z)e*d+d,„ ƒZ+e*d-d.„ ƒZ,e*d/d0„ ƒZ-d1d2„ Z.d3d4„ Z/d5d6„ Z0e*d7d8„ ƒZ1e*d9d:„ ƒZ2e3d;ƒd<d=„ ƒZ4d>d?„ Z5d@dA„ Z6dBdC„ Z7dDdE„ Z8dFdG„ Z9dHdI„ Z:dJS )KÚDockWindowFeaturea�   Implements "features" on DockWindows.

    See "The DockWindowFeature Feature of DockWindows" document (.doc or .pdf)
    in pyface.doc for details on using this class.

    Traits are defined on each feature instance. One or more feature instances
    are created for each application component that a feature class applies to.
    A given feature class might or might not apply to a specific application
    component. The feature class determines whether it applies to an application
    component when the feature is activated, or when a new application
    component is added to the DockWindow (and the feature is already active).
    Ú r   Fc                 C   s   |   ¡  dS )a   Handles the user left-clicking on a feature image.

        This method is designed to be overridden by subclasses. The default
        implementation attempts to perform a 'quick drag' operation (see the
        'quick_drag' method). Returns nothing.
        N)Ú
quick_drag©Úself© r   úb/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/pyface/dock/dock_window_feature.pyÚclickŽ   s    zDockWindowFeature.clickc                 C   s   |   ¡  dS )a`   Handles the user right-clicking on a feature image.

        This method is designed to be overridden by subclasses. The default
        implementation attempts to perform a 'quick drag' operation (see the
        'quick_right_drag' method). Returns nothing. Typically, you override
        this method to display the feature's shortcut menu.
        N)Úquick_right_dragr   r   r   r   Úright_click›   s    zDockWindowFeature.right_clickc                 C   s   dS )aL   Returns the object to be dragged when the user drags a feature
        image.

        This method can be overridden by subclasses. If dragging is supported
        by the feature, then the method returns the object to be dragged;
        otherwise it returns **None**. The default implementation returns
        **None**.
        Nr   r   r   r   r   Údrag©   s    	zDockWindowFeature.dragc                 C   s   dS )a}   Returns the object to be dragged when the user drags a feature
        image while pressing the 'Ctrl' key.

        This method is designed to be overridden by subclasses. If
        control-dragging is supported by the feature, then the method returns
        the object to be dragged; otherwise it returns **None**. The default
        implementation returns **None**.
        Nr   r   r   r   r   Úcontrol_drag¹   s    	zDockWindowFeature.control_dragc                 C   s   dS )a}   Returns the object to be dragged when the user drags a feature
        image while pressing the 'Shift' key.

        This method is designed to be overridden by subclasses. If
        shift-dragging is supported by the feature, then the method returns
        the object to be dragged; otherwise it returns **None**. The default
        implementation returns **None**.

        Nr   r   r   r   r   Ú
shift_dragÉ   s    
zDockWindowFeature.shift_dragc                 C   s   dS )ay   Returns the object to be dragged when the user drags a feature
        image while pressing the 'Alt' key.

        This method is designed to be overridden by subclasses. If
        Alt-dragging is supported by the feature, then the method returns
        the object to be dragged; otherwise it returns **None**. The default
        implementation returns **None**.

        Nr   r   r   r   r   Úalt_dragÚ   s    
zDockWindowFeature.alt_dragc                 C   s   dS )ae   Returns the object to be dragged when the user right mouse button
        drags a feature image.

        This method can be overridden by subclasses. If right dragging is
        supported by the feature, then the method returns the object to be
        dragged; otherwise it returns **None**. The default implementation
        returns **None**.
        Nr   r   r   r   r   Ú
right_dragë   s    	zDockWindowFeature.right_dragc                 C   s   dS )a–   Returns the object to be dragged when the user right mouse button
        drags a feature image while pressing the 'Ctrl' key.

        This method is designed to be overridden by subclasses. If
        right control-dragging is supported by the feature, then the method
        returns the object to be dragged; otherwise it returns **None**. The
        default implementation returns **None**.
        Nr   r   r   r   r   Úcontrol_right_dragû   s    	z$DockWindowFeature.control_right_dragc                 C   s   dS )a–   Returns the object to be dragged when the user right mouse button
        drags a feature image while pressing the 'Shift' key.

        This method is designed to be overridden by subclasses. If right
        shift-dragging is supported by the feature, then the method returns
        the object to be dragged; otherwise it returns **None**. The default
        implementation returns **None**.

        Nr   r   r   r   r   Úshift_control_drag  s    
z$DockWindowFeature.shift_control_dragc                 C   s   dS )a’   Returns the object to be dragged when the user right mouse button
        drags a feature image while pressing the 'Alt' key.

        This method is designed to be overridden by subclasses. If right
        Alt-dragging is supported by the feature, then the method returns
        the object to be dragged; otherwise it returns **None**. The default
        implementation returns **None**.

        Nr   r   r   r   r   Úalt_right_drag  s    
z DockWindowFeature.alt_right_dragc                 C   s   dS )ao   Handles the user dropping a specified object on a feature image.

        Parameters
        ----------
        object : any object
            The object being dropped onto the feature image

        Returns
        -------
        Nothing.

        Description
        -----------
        This method is designed to be overridden by subclasses. It is called
        whenever the user drops an object on the feature's tab or drag bar
        image. This method can be called only if a previous call to
        **can_drop()** for the same object returned **True**. The default
        implementation does nothing.
        Nr   ©r   Úobjectr   r   r   Údrop,  s    zDockWindowFeature.dropc                 C   s   dS )a*   Returns whether a specified object can be dropped on a feature
        image.

        Parameters
        ----------
        object : any object
            The object being dragged onto the feature image

        Returns
        -------
        **True** if *object* is a valid object for the feature to process;
        **False** otherwise.

        Description
        -----------
        This method is designed to be overridden by subclasses. It is called
        whenever the user drags an icon over the feature's tab or drag bar
        image. The method does not perform any processing on *object*; it only
        examines it. Processing of the object occurs in the **drop()** method,
        which is called when the user release the object over the feature's
        image, which typically occurs after the **can_drop()** method has
        indicated that the feature can process the object, by returning
        **True**. The default implementation returns **False**, indicating that
        the feature does not accept any objects for dropping.
        Fr   r&   r   r   r   Úcan_dropF  s    zDockWindowFeature.can_dropc                 C   s   dS )aÒ   Performs any clean-up needed when the feature is removed from its
        associated application component (for example, when the user disables
        the feature).

        This method is designed to be overridden by subclasses. The method
        performs any clean-up actions needed by the feature, such as closing
        files, removing trait listeners, and so on. The method does not return
        a result. The default implementation does nothing.
        Nr   r   r   r   r   Údisposef  s    
zDockWindowFeature.disposec                 C   sF   | j j ¡ }| ¡ \}}| | || ¡| j| d | j| d ¡ dS )a·   Displays a shortcut menu.

        Parameters
        ----------
        menu : traitsui.menu.Menu object
            The menu to be displayed

        Returns
        -------
        Nothing.

        Description
        -----------
        This helper method displays the shortcut menu specified by *menu* at a
        point near the feature object's current (x,y) value, as specified by
        the **x** and **y** traits. Normally, the (x,y) value contains the
        screen location where the user clicked on the feature's tab or drag
        bar image. The effect is that the menu is displayed near the feature's
        icon, with the pointer directly over the top menu option.
        é
   N)Údock_controlÚcontrolZ	GetParentÚGetScreenPositionZ	PopupMenuZcreate_menuÚxÚy)r   ÚmenuÚwindowZwxZwyr   r   r   Ú
popup_menux  s
    "ÿzDockWindowFeature.popup_menuc                 C   s   d| j _dS )zò Refreshes the display of the feature image.

        Returns
        -------
        Nothing.

        Description
        -----------
        This helper method requests the containing DockWindow to refresh the
        feature bar.
        TN)r,   Úfeature_changedr   r   r   r   Úrefresh—  s    zDockWindowFeature.refreshc                 C   s$   | j | _d| _ | jdur d| j_dS )aß   Disables the feature.

        Returns
        -------
        Nothing.

        Description
        -----------
        This helper method temporarily disables the feature for the associated
        application component. The feature can be re-enabled by calling the
        **enable()** method. Disabling the feature removes the feature's icon
        from the feature bar, without actually deleting the feature (i.e., the
        **dispose()** method is not called).
        NT)ÚimageÚ_imager,   r4   r   r   r   r   Údisable©  s    
zDockWindowFeature.disablec                 C   s$   | j | _d| _ | jdur d| j_dS )a`   Enables the feature.

        Returns
        -------
        Nothing.

        Description
        -----------
        This helper method re-enables a previously disabled feature for its
        associated application component. Enabling a feature restores the
        feature bar icon that the feature displayed at the time it was disabled.
        NT)r7   r6   r,   r4   r   r   r   r   ÚenableÁ  s    
zDockWindowFeature.enablec                 C   sN   | j r|  ¡ }n(| jr |  ¡ }n| jr0|  ¡ }n|  ¡ }|durJ|  |¡ dS )zî Performs a quick drag and drop operation by displaying a pop-up menu
            containing all targets that the feature's xxx_drag() method can be
            dropped on. Selecting an item drops the item on the selected target.
        N)Úcontrol_downr   Úalt_downr!   Ú
shift_downr    r   Ú_quick_drag_menur&   r   r   r   r   Ù  s    


zDockWindowFeature.quick_dragc                 C   sN   | j r|  ¡ }n(| jr |  ¡ }n| jr0|  ¡ }n|  ¡ }|durJ|  |¡ dS )a   Performs a quick drag and drop operation with the right mouse button
            by displaying a pop-up menu containing all targets that the
            feature's xxx_right_drag() method can be dropped on. Selecting an
            item drops the item on the selected target.
        N)r:   r#   r;   r%   r<   Zshift_right_dragr"   r=   r&   r   r   r   r   ó  s    


z"DockWindowFeature.quick_right_dragc                 C   s   |   |¡r|  |¡S dS )aÓ   Returns a single new feature object or list of new feature objects
        for a specified DockControl.

        Parameters
        ----------
        dock_control : pyface.dock.api.DockControl
            The DockControl object that corresponds to the application
            component being added, or for which the feature is being enabled.

        Returns
        -------
        An instance or list of instances of this class that will be associated
        with the application component; **None** if the feature does not apply
        to the application component.

        Description
        -----------
        This class method is designed to be overridden by subclasses. Normally,
        a feature class determines whether it applies to an application
        component by examining the component to see if it is an instance of a
        certain class, supports a specified interface, or has trait attributes
        with certain types of metadata. The application component is available
        through the *dock_control.object* trait attribute. Note that it is
        possible for *dock_control.object* to be **None**.

        The default implementation for this method calls the
        **is_feature_for()** class method to determine whether the feature
        applies to the specified DockControl. If it does, it calls the
        **new_feature()** class method to create the feature instances to be
        returned. If it does not, it simply returns **None**.
        N)Úis_feature_forÚnew_feature©Úclsr,   r   r   r   Úfeature_for  s    !

zDockWindowFeature.feature_forc                 C   s
   | |d�S )aÅ   Returns a new feature instance for a specified DockControl.

        Parameters
        ----------
        dock_control : pyface.dock.api.DockControl
            The DockControl object that corresponds to the application
            component being added, or for which the feature is being enabled.

        Returns
        -------
        An instance or list of instances of this class to be associated
        with the application component; it can also return **None**.

        Description
        -----------
        This method is designed to be overridden by subclasses. This method is
        called by the default implementation of the **feature_for()** class
        method to create the feature instances to be associated with the
        application component specified by *dock_control*. The default
        implementation returns the result of calling the class constructor as
        follows::

            cls( dock_control=dock_control )

        ©r,   r   r@   r   r   r   r?   8  s    zDockWindowFeature.new_featurec                 C   s   dS )a‹   Returns whether this class is a valid feature for the application
        object corresponding to a specified DockControl.

        Parameters
        ----------
        dock_control : pyface.dock.api.DockControl
            The DockControl object that corresponds to the application
            component being added, or for which the feature is being enabled.

        Returns
        -------
        **True** if the feature applies to the application object associated
        with the *dock_control*; **False** otherwise.

        Description
        -----------
        This class method is designed to be overridden by subclasses. It is
        called by the default implementation of the **feature_for()** class
        method to determine whether the feature applies to the application
        object specified by *dock_control*. The default implementation always
        returns **True**.
        Tr   )r   r,   r   r   r   r>   Z  s    z DockWindowFeature.is_feature_forc                 C   sD   |  ¡  ¡ \}}| j| ¡ | | ¡ | | ¡ | ¡ | ¡ d� dS )zJ Sets the feature's 'event' traits for a specified mouse 'event'.
        )r/   r0   r<   r:   r;   N)ZGetEventObjectr.   Z	trait_setZGetXZGetYZ	ShiftDownZControlDownZAltDown)r   Úeventr/   r0   r   r   r   Ú
_set_eventz  s    

ûzDockWindowFeature._set_eventc              	      sŽ  g }t ˆ tƒr\d}| jjD ]>}|jrˆ  |j¡s:ˆ  |¡rddlm	} | 
||d�g¡ qnBd}| jjD ]4}|jrh‡ fdd„|jD ƒ}t|ƒdkrh| 
|¡ qht|ƒdk�rŠg }g }|D ]¤}	t|	ƒdk�r$g }
|	D ].}|
 
td	|j d
t|ƒ d�¡ | 
|¡ qÒ| 
t|
dd||jjf iŽ¡ q¸| 
td||	d jjf d
t|ƒ d�¡ | 
|	d ¡ q¸ˆ | _|| _|  t|ddiŽ¡ d | _| _dS )zC Displays the quick drag menu for a specified drag object.
        zApply tor   )ÚFeatureToolrC   zSend toc                    s$   g | ]}|j d kr| ˆ ¡r|‘qS )r   )Úfeature_namer)   )Ú.0Úf©r'   r   r   Ú
<listcomp>ž  s   þz6DockWindowFeature._quick_drag_menu.<locals>.<listcomp>r   z
%s Featurezself._drop_on(%d))ÚnameÚactionrL   z	%s the %sz%s %sZpopupN)Ú
isinstancer   r,   Zdock_controlsZvisibleZfeature_can_drop_onr'   Z feature_can_drop_on_dock_controlZfeature_toolrF   ÚappendÚfeaturesÚlenr   rG   r   rL   Ú_objectÚ	_featuresr3   )r   r'   Zfeature_listsÚmsgÚdcrF   ÚallowedrP   ÚactionsÚlistZsub_actionsÚfeaturer   rJ   r   r=   Š  sj    

ÿþ
þ
þÿý
ÿÿÿ
þÿz"DockWindowFeature._quick_drag_menuc                 C   sH   | j }t|tƒr4| j| j}| |j¡ | |¡ n| j|  |¡ dS )zG Drops the current object on the feature selected by the user.
        N)	rR   rN   r   rS   r,   Zfeature_dropped_onr'   Zfeature_dropped_on_dock_controlr(   )r   Úindexr'   rU   r   r   r   Ú_drop_onÑ  s    
zDockWindowFeature._drop_onc                 C   sN   |   |¡}|durJdd„ | jD ƒ| _t|tƒr4|g}| j dd„ |D ƒ¡ |S )z™ Returns a feature object for use with the specified DockControl (or
        **None** if the feature does not apply to the DockControl object).

        Nc                 S   s   g | ]}|ƒ d ur|‘qS ©Nr   ©rH   Úarefr   r   r   rK   ë  s   z5DockWindowFeature.new_feature_for.<locals>.<listcomp>c                 S   s   g | ]}t |ƒ‘qS r   r   )rH   rY   r   r   r   rK   ð  ó    )rB   Ú	instancesrN   r   Úextend)rA   r,   Úresultr   r   r   Únew_feature_forã  s    
ÿ
z!DockWindowFeature.new_feature_forc                 C   s¦   | j dkrLd| _ t| ƒ |jj ¡ D ]$}t|ddƒ}t|tƒr$t|j	ƒ q$nVd}d| j  | _ | j dkrjd}dd	„ | j
D ƒ| _
| j
D ]}|ƒ }|dur‚t||ƒƒ  q‚dS )
z( Toggles the feature on or off.
        r   r   ÚownerNr8   é   r9   c                 S   s   g | ]}|ƒ d ur|‘qS r\   r   r]   r   r   r   rK     s   z4DockWindowFeature.toggle_feature.<locals>.<listcomp>)Ústater   r2   r-   ZGetChildrenÚgetattrrN   r   r   Zupdate_layoutr`   )rA   rD   r-   r2   Úmethodr^   rY   r   r   r   Útoggle_featureø  s$    


ÿ
z DockWindowFeature.toggle_featurer6   c                 C   s
   d | _ d S r\   )Ú_bitmap)r   rD   r   r   r   Ú_reset_bitmap  s    zDockWindowFeature._reset_bitmapc                 C   s*   | j d u r$| jd ur$| j ¡  ¡ | _ | j S r\   )rj   r6   Zcreate_imageZConvertToBitmapr   r   r   r   Ú_get_bitmap  s    zDockWindowFeature._get_bitmapc                 C   s   dS )z= Adds a menu item to the menu bar being constructed.
        Nr   )r   Z	menu_itemr   r   r   Úadd_to_menu(  s    zDockWindowFeature.add_to_menuc                 C   s   dS )zA Adds a tool bar item to the tool bar being constructed.
        Nr   )r   Ztoolbar_itemr   r   r   Úadd_to_toolbar1  s    z DockWindowFeature.add_to_toolbarc                 C   s   dS )zM Returns whether the action should be defined in the user interface.
        Tr   ©r   rM   r   r   r   Úcan_add_to_menu:  s    z!DockWindowFeature.can_add_to_menuc                 C   s   dS )za Returns whether the toolbar action should be defined in the user
            interface.
        Tr   ro   r   r   r   Úcan_add_to_toolbarD  s    z$DockWindowFeature.can_add_to_toolbarc                 C   s:   |j }|dd… dkr*t|tƒ d| iƒ nt| |ƒƒ  dS )zE Performs the action described by a specified Action object.
        Né   zself.r   )rM   ÚevalÚglobalsrg   ro   r   r   r   ÚperformN  s    zDockWindowFeature.performN);Ú__name__Ú
__module__Ú__qualname__Ú__doc__rG   rf   r`   r   r   r,   r   r6   r   Ztooltipr   r/   r0   r   r<   r:   r;   r	   Zbitmapr   r   r   r   r    r!   r"   r#   r$   r%   r(   r)   r*   r3   r5   r8   r9   r   r   ÚclassmethodrB   r?   r>   rE   r=   r[   rc   ri   r
   rk   rl   rm   rn   rp   rq   ru   r   r   r   r   r   +   sj    
)
!
G


		

r   N)ry   Úweakrefr   Z
traits.apir   r   r   r   r   r	   r
   Ztraitsui.menur   r   Zpyface.timer.apir   Zpyface.ui_traitsr   Zdock_windowr   Z
dock_sizerr   r   Zifeature_toolr   r   r   r   r   r   Ú<module>   s   $