3
<Ad]ÜÉ  ã               @   sæ  d Z ddlZddlZddlZddlZddlm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mZmZmZmZmZ ddlmZ ddlmZmZmZ dd	lm Z  dd
l!m"Z"m#Z# ddl$m%Z%m&Z& ddl'mZ( ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3 ddl4m5Z5 ej6dkZ7i a8eddd�Z9eddd�Z:edddd�Z;eddd�Z<eddd�Z=edd d�Z>ed!d"d�Z?ed#d$d�Z@G d%d&„ d&eƒZAeAƒ ZBG d'd(„ d(eƒZCG d)d*„ d*eƒZDG d+d,„ d,eEƒZFG d-d.„ d.eƒZGdS )/a~   Pyface 'DockWindow' support.

    This package provides a Pyface 'dockable' window component that allows
    child windows to be reorganized within the DockWindow using drag and drop.
    The component also allows multiple sub-windows to occupy the same
    sub-region of the DockWindow, in which case each sub-window appears as a
    separate notebook-like tab within the region.
é    N)ÚSystemMetrics)ÚHasPrivateTraitsÚInstanceÚTupleÚPropertyÚAnyÚStrÚListÚfalse)Útraits_home)ÚViewÚHGroupÚVGroupÚItemÚHandlerÚerror)Úuser_name_for)ÚMenuÚActionÚ	Separator)ÚDockableViewElement)Údock_window_themeÚDockWindowTheme)ÚPythonDropTargetÚ	clipboard)r   é   )Ú	DockSizerÚDockControlÚ
DockRegionÚ	DockStyleÚDockSplitterÚno_dock_infoÚclear_windowÚfeatures)Ú	IDockable)ÚIDockUIProviderÚdarwinÚMaximizeÚ
on_min_max)ÚnameÚactionZUndockÚ	on_undockzLock LayoutÚon_lock_layoutÚtoggle)r)   r*   ÚstylezSwitch LayoutÚon_switch_layoutzSave Layout...Úon_save_layoutzEdit Properties...Úon_editzShow AllÚon_enable_all_featureszHide AllÚon_disable_all_featuresc               @   s.   e Zd Zdd„ Zdd„ Zddd„Zdd	„ Zd
S )ÚDockWindowHandlerc             C   s   dS )z^ Returns whether or not a specified object can be inserted into the
            view.
        T© )ÚselfÚobjectr5   r5   úq/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/pyface-6.1.2-py3.6.egg/pyface/dock/dock_window.pyÚcan_drop|   s    zDockWindowHandler.can_dropc             C   s  y
|j }W n(   y
|j}W n   d}Y nX Y nX |dkrHt|jjƒ}d}d}t|tƒr¸|}|j}|j}|j	}|j
ƒ }|rˆ|jdd� |j|ƒ}	|rô|j|	|jjd� |j|ƒ |S n<t|tƒrÒ|}|j|ƒ}	n"|j|ƒ}
t|
d�}|
jj}|
j}	t|	|||jj|dd�}|j|ƒ |S )z@ Returns the DockControl object for a specified object.
        Ú NT)Úforce)Úcontrolr.   )Úui)r<   r)   Úexportr.   ÚimageZ	closeable)r)   Úlabelr   Ú	__class__Ú__name__Ú
isinstancer   r?   r>   ÚdockableZdockable_should_closeÚcloseZdockable_get_controlÚ	trait_setÚownerr.   Zdockable_init_dockcontrolr$   Zget_dockable_uir   Úviewr<   )r6   Úparentr7   r)   r?   r>   Údock_controlrD   rE   r<   r=   Zdcr5   r5   r8   Údock_control_for†   sR    








z"DockWindowHandler.dock_control_forTc             C   s   ddl m} |||d� dS )z4 Creates a new view of a specified control.
        r   )ÚDockWindowShell)Ú	use_mouseN)Zdock_window_shellrL   )r6   r<   rM   rL   r5   r5   r8   Úopen_view_forÁ   s    zDockWindowHandler.open_view_forc             C   s   |j r|jjƒ jƒ  dS )z0 Handles the DockWindow becoming empty.
        N)Ú
auto_closer<   Ú	GetParentZDestroy)r6   Údock_windowr5   r5   r8   Údock_window_emptyÌ   s    z#DockWindowHandler.dock_window_emptyN)T)rB   Ú
__module__Ú__qualname__r9   rK   rN   rR   r5   r5   r5   r8   r4   v   s   
;
r4   c               @   s<   e Zd ZeZeeƒZeeddd�ddddgd�Z	d	d
„ Z
dS )Ú
LayoutNamer)   zLayout name)r@   zSave LayoutÚmodalÚOKÚCancel)ÚtitleÚkindÚbuttonsc             C   sR   |rN|j jjƒ }|dkr.t|jjddd� dS || jkrNtd| d|jjd�S d	S )
Nr:   zNo name specifiedzSave Layout Error)rY   Fz%s is already defined. Replace?zSave Layout Warning)ÚmessagerY   rI   T)r7   r)   ÚstripÚwarningr=   r<   Únamesr   )r6   ÚinfoZis_okr)   r5   r5   r8   rE   ò   s    

zLayoutName.closeN)rB   rS   rT   r   r)   r	   r_   r   r   rH   rE   r5   r5   r5   r8   rU   Ù   s   rU   c                   s  e Zd ZeejƒZeeƒZ	e
ZeZeedd�ZeZeZeZdvejejejf‡ fdd„	Zdd„ Zdd	„ Zd
d„ Zdwd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/d0„ Z.dxd1d2„Z/d3d4„ Z0d5d6„ Z1d7d8„ Z2d9d:„ Z3d;d<„ Z4d=d>„ Z5d?d@„ Z6dAdB„ Z7dCdD„ Z8dydEdF„Z9dGdH„ Z:dIdJ„ Z;dKdL„ Z<dMdN„ Z=dOdP„ Z>dQdR„ Z?dSdT„ Z@dUdV„ ZAdzdXdY„ZBdZd[„ ZCd\d]„ ZDd^d_„ ZEd`da„ ZFdbdc„ ZGddde„ ZHdfdg„ ZIdhdi„ ZJdjdk„ ZKdldm„ ZLdndo„ ZMdpdq„ ZNdrds„ ZOdtdu„ ZP‡  ZQS ){Ú
DockWindowF)Ú
allow_noner   c       	         s  t t| ƒjf |Ž tj|||||ƒ | _}| |_tj|| jƒ tj	|| j
ƒ tj|| jƒ tj|| jƒ tj|| jƒ tj|| jƒ tj|| jƒ tj|| jƒ tj|| jƒ |jt| ƒƒ | jjrÒ| jjjj}n.t ƒ j!}tj"|d d |d d |d d ƒ}| jj#|ƒ d S )Nr   éÿ   r   é   )$Úsuperra   Ú__init__ÚwxÚWindowr<   rG   Ú	EVT_PAINTÚ_paintÚEVT_SIZEÚ_sizeÚEVT_LEFT_DOWNÚ
_left_downÚEVT_LEFT_UPÚ_left_upÚEVT_LEFT_DCLICKÚ_left_dclickÚEVT_RIGHT_DOWNÚ_right_downÚEVT_RIGHT_UPÚright_upÚ
EVT_MOTIONÚ_mouse_moveÚEVT_LEAVE_WINDOWÚ_mouse_leaveZSetDropTargetr   ÚthemeÚuse_theme_colorÚtabÚimage_sliceÚbg_colorr   Zdialog_background_colorZColourÚSetBackgroundColour)	r6   rI   ZwidÚposÚsizer.   Útraitsr<   Úcolor)rA   r5   r8   rf   '  s$    &zDockWindow.__init__c             C   s   t ƒ S )N)r   )r6   r5   r5   r8   Ú_theme_defaultJ  s    zDockWindow._theme_defaultc             C   s:   | j d k	r6|jr|jjj}ntj}| j j|ƒ | jƒ  d S )N)	r<   r|   r}   r~   r   rg   Z
NullColourr€   Úupdate_layout)r6   r{   r„   r5   r5   r8   Ú_theme_changedO  s    
zDockWindow._theme_changedc             C   s   | j j| ƒ dS )z> Notifies the DockWindow that its contents are empty.
        N)ÚhandlerrR   )r6   r5   r5   r8   rR   ]  s    zDockWindow.dock_window_emptyNc             C   sD   |dkr| j jtjƒ dS |tkr0tj|ƒt|< | j jt| ƒ dS )z6 Sets the cursor to a specified cursor shape.
        N)r<   Z	SetCursorrg   Z
NullCursorÚ
cursor_mapZStockCursor)r6   Zcursorr5   r5   r8   Ú
set_cursorf  s    zDockWindow.set_cursorc             C   s   | j dk	rd| _ | jjƒ  dS )z2 Releases ownership of the mouse capture.
        N)Ú_ownerr<   ÚReleaseMouse)r6   r5   r5   r8   Úrelease_mousex  s    
zDockWindow.release_mousec             C   s4   y| j jƒ  | j jƒ  W n tjk
r.   Y nX dS )z+ Updates the layout of the window.
        N)r<   ÚLayoutZRefreshrg   ZPyDeadObjectError)r6   r5   r5   r8   r†   ƒ  s
    
zDockWindow.update_layoutc             C   s(   | j }|dk	r$|j| j|ƒ | jƒ  dS )z6 Minimizes/maximizes a specified DockControl.
        N)ÚsizerZMinMaxr<   r†   )r6   rJ   r�   r5   r5   r8   Úmin_max”  s    zDockWindow.min_maxc             C   sL   | j }|dkr:ddlm} || jd� | _ }|j| jdƒ ||_|jƒ  dS )z> Pops up the feature bar for a specified DockControl.
        Nr   )Ú
FeatureBar)rI   Z	completed)Ú_feature_barZfeature_barr‘   r<   Zon_trait_changeÚ_feature_bar_closedrJ   Úshow)r6   rJ   Úfbr‘   r5   r5   r8   Úfeature_bar_popup   s    zDockWindow.feature_bar_popupc             C   s   | j }|jjƒ  |jƒ  d S )N)r’   rJ   Zfeature_bar_closedZhide)r6   r•   r5   r5   r8   r“   ±  s    
zDockWindow._feature_bar_closedc             C   s   | j ƒ  dS )a   Closes the dock window.  In this case, all event handlers are
        unregistered.  Other cleanup operations go here, but at the moment Linux
        (and other non-Windows platforms?) are less forgiving when things like
        event handlers arent unregistered.
        N)Ú_unregister_event_handlers)r6   r5   r5   r8   rE   º  s    zDockWindow.closec             C   s~   | j }|dk	rztj|dƒ tj|dƒ tj|dƒ tj|dƒ tj|dƒ tj|dƒ tj|dƒ tj	|dƒ tj
|dƒ dS )a   Unregister all event handlers setup in the constructor.  This is
        typically done prior to an app shutting down and is needed since Linux
        (and other non-Windows platforms?) trigger mouse, repaint, etc. events
        for controls which have already been deleted.
        N)r<   rg   ri   rk   rm   ro   rq   rs   ru   rw   ry   )r6   r<   r5   r5   r8   r—   Æ  s    z%DockWindow._unregister_event_handlersc             C   s<   t r| jƒ rdS | j}t|tƒr.|j| jƒ n
t| jƒ dS )z( Handles repainting the window.
        N)Úis_macÚ_is_child_paintr�   rC   r   ZDrawr<   r"   )r6   Úeventr�   r5   r5   r8   rj   Ü  s    
zDockWindow._paintc             C   sB   | j jr>| j jj}x*| j jD ]}|jƒ  r|jj|ƒrdS qW dS )zV Returns whether or not the current update region is entirely within a child.
        TF)r<   ZChildrenZUpdateRegionÚBoxZHasTransparentBackgroundZRectZContainsRect)r6   Zupdate_rectÚchildr5   r5   r8   r™   ï  s    

zDockWindow._is_child_paintc             C   sB   | j }|dk	r>y"| jjƒ \}}|jdd||ƒ W n   Y nX dS )z+ Handles the window being resized.
        Nr   )r�   r<   ZGetSizeTupleÚSetDimension)r6   rš   r�   ÚdxÚdyr5   r5   r8   rl   þ  s    zDockWindow._sizec             C   sH   | j }|dk	rD|j|jƒ |jƒ ƒ}|dk	rD|| _| jjƒ  |j|ƒ dS )z6 Handles the left mouse button being pressed.
        N)r�   ÚObjectAtÚGetXÚGetYr‹   r<   ÚCaptureMouseÚ
mouse_down)r6   rš   r�   r7   r5   r5   r8   rn     s    
zDockWindow._left_downc             C   sœ   | j }| jdk	r*|jƒ  | jj|ƒ d| _|jƒ r˜|jƒ r~|jƒ rh| jjƒ }|dk	r||j	ƒ  t
jjƒ  q˜| jj|ƒ | jƒ  n|jƒ r˜| jjƒ  | jƒ  dS )z7 Handles the left mouse button being released.
        N)r<   r‹   rŒ   Zmouse_upÚ	ShiftDownÚControlDownÚAltDownr�   ÚGetContentsÚdumpÚsysÚstdoutÚflushÚResetStructurer†   Ú
ToggleLock)r6   rš   ÚwindowÚcontentsr5   r5   r8   rp     s"    



zDockWindow._left_upc             C   sŠ   | j }|dk	r†|j|jƒ |jƒ dƒ}t|tƒrb|j}|dksL|j||ƒdkr†|jdkr†| j	|ƒ n$t|t
ƒr†|| _| jjƒ  |j|ƒ dS )z= Handles the left mouse button being double clicked.
        NTFÚfixed)r�   r    r¡   r¢   rC   r   rD   Zdockable_dclickr.   r�   r   r‹   r<   r£   r¤   )r6   rš   r�   r7   rD   r5   r5   r8   rr   ;  s    



zDockWindow._left_dclickc             C   s   dS )z7 Handles the right mouse button being pressed.
        Nr5   )r6   rš   r5   r5   r8   rt   P  s    zDockWindow._right_downc             C   s’  | j }|dk	�rŽ|j|jƒ |jƒ dƒ}|dk	�rŽd}| j}t|tƒ}|r€|jdk	r€|jƒ sj|j	ƒ sj|j
ƒ r€|j| _|jj||ƒ}|dk�rb| | _| j jƒ }t|tƒ}|| _|rº|j | _}|}	|rÈ|	j}	|jƒ rØdt_ndt_|t_|t_| t_|jdƒ}
t|
ƒdk�o|
d jt_| jdkt_| jƒ }| jƒ \}}t ttt!ƒ |t!ƒ tt"t!ƒ t||t!ƒ tdd	�}|j#|j$|| ƒ|jƒ d
 |jƒ d
 ƒ d| _dS )z8 Handles the right mouse button being released.
        NTr'   ZRestoreFr   r:   Zpopup)r)   é
   )%r�   r    r¡   r¢   r<   rC   r   rD   r¥   r¦   r§   Ú
_menu_selfZdockable_menur¨   r    Ú_objectrI   ZIsMaximizableÚmin_max_actionr)   ÚenabledÚundock_actionÚedit_actionZget_controlsÚlenÚlockedÚlock_actionÚcheckedÚidÚsave_actionÚ_get_feature_menuÚ_get_layout_menusr   r   Úlayout_actionZPopupMenuXYZcreate_menu)r6   rš   r�   r7   Z
popup_menur¯   Zis_dock_controlÚsectionZis_splitterÚgroupZcontrolsZfeature_menuZrestore_menuZdelete_menur5   r5   r8   rv   Y  sf    






zDockWindow.right_upc             C   s¼   | j dk	r| j jƒ  d| _ | jdk	r2| jj|ƒ n†| j}|dk	r¸| jpX|j|jƒ |jƒ ƒ}| j	||ƒ || j
k	rž| j
dk	r†| j
j|ƒ |dk	r˜|j|ƒ || _
t|tƒr¸|j|ƒr¸|| _ dS )z3 Handles the mouse moving over the window.
        N)Ú_last_dock_controlÚreset_feature_popupr‹   Z
mouse_mover�   r´   r    r¡   r¢   Ú_set_cursorÚ_hoverÚ
hover_exitZhover_enterrC   r   Úfeature_activate)r6   rš   r�   r7   r5   r5   r8   rx   œ  s&    







zDockWindow._mouse_movec             C   s*   | j dk	r| j j|ƒ d| _ | j|ƒ dS )z/ Handles the mouse leaving the window.
        N)rÇ   rÈ   rÆ   )r6   rš   r5   r5   r8   rz   ¿  s    
zDockWindow._mouse_leavec             C   s&   |dkr| j ƒ  n| j |j|ƒƒ dS )z1 Sets the cursor for a specified object.
        N)rŠ   Z
get_cursor)r6   rš   r7   r5   r5   r8   rÆ   Ë  s    
zDockWindow._set_cursorc             C   s   | j | jƒ dS )zM Handles the user asking for a DockControl to be maximized/restored.
        N)r�   r´   )r6   r5   r5   r8   r(   Ù  s    zDockWindow.on_min_maxc             C   s   | j j| jdd� dS )z@ Handles the user requesting an element to be undocked.
        F)rM   N)rˆ   rN   r´   )r6   r5   r5   r8   r+   â  s    zDockWindow.on_undockc             C   s   | j jdƒ dS )z> Handles the user requesting an element to be hidden.
        FN)r´   r”   )r6   r5   r5   r8   Úon_hideë  s    zDockWindow.on_hidec             C   s*   | j }t|tƒr|j}| j|ƒjdƒ dS )z= Handles the user requesting an element to be shown.
        TN)r´   rC   r   rI   Ú_hidden_group_forr”   )r6   r7   r5   r5   r8   Úon_showô  s    
zDockWindow.on_showc             C   s   | j j| jƒ | jƒ  dS )zJ Handles the user requesting that the current layout be switched.
        N)r�   r­   r<   r†   )r6   r5   r5   r8   r/      s    zDockWindow.on_switch_layoutc             C   s   | j jƒ  | jƒ  dS )zI Handles the user requesting that the layout be locked/unlocked.
        N)r�   r®   r†   )r6   r5   r5   r8   r,   
  s    
zDockWindow.on_lock_layoutc             C   s6   t | jƒ d�}|j| jd�jr2| j|j| jjƒ ƒ dS )z? Handles the user requesting that the layout be saved.
        )r_   )rI   N)	rU   Ú_get_layout_namesÚedit_traitsr<   ÚresultÚ_set_layoutr)   r�   ZGetStructure)r6   Zlayout_namer5   r5   r8   r0     s    zDockWindow.on_save_layoutc             C   s"   | j j| j| j|ƒƒ | jƒ  dS )zH Handles the user requesting a specified layout to be restored.
        N)r�   ZSetStructurer<   Ú_get_layoutr†   )r6   r)   r5   r5   r8   Úon_restore_layout  s    zDockWindow.on_restore_layoutc             C   s"   t d| d| jd�r| j|ƒ dS )zF Handles the user reqesting a specified layout to be deleted.
        zDelete the '%s' layout?zDelete Layout Warning)r\   rY   rI   N)r   r<   Ú_delete_layout)r6   r)   r5   r5   r8   Úon_delete_layout)  s    
zDockWindow.on_delete_layoutc             C   sn   |dkr| j }tf |jddddƒŽ}|j| jd�jrj|jjƒ }|dkrL||_|jf |jdddƒŽ | j	ƒ  dS )z6 Handles the user requesting to edit an item.
        Nr)   Ú	user_namer.   Ú
user_style)rI   r:   )
r´   ÚControlInfoÚgetrÎ   r<   rÏ   r)   r]   rF   r†   )r6   r7   Zcontrol_infor)   r5   r5   r8   r1   5  s    

zDockWindow.on_editc             C   s0   x*t D ]"}|jdkr|jdkr|j|ƒ qW dS )z Enables all features.
        r:   r   N)r#   Úfeature_nameÚstateÚtoggle_feature)r6   r*   Úfeaturer5   r5   r8   r2   H  s    
z!DockWindow.on_enable_all_featuresc             C   s0   x*t D ]"}|jdkr|jdkr|j|ƒ qW dS )z  Disables all features.
        r:   r   N)r#   rÙ   rÚ   rÛ   )r6   r*   rÜ   r5   r5   r8   r3   S  s    
z"DockWindow.on_disable_all_featuresc             C   s   |j j|ƒ dS )z\ Toggles the enabled/disabled state of the action's associated
            feature.
        N)Ú_featurerÛ   )r6   r*   r5   r5   r8   Úon_toggle_feature^  s    zDockWindow.on_toggle_featurec             C   s8   | j }|dkr4| jƒ }|dk	r4|j|ƒ}|jƒ  |S dS )z8 Gets the layout dictionary for the DockWindow.
        r:   N)r½   Ú
_get_dw_dbrØ   rE   )r6   r½   ÚdbÚlayoutsr5   r5   r8   Ú_get_layoutsj  s    
zDockWindow._get_layoutsc             C   s    | j ƒ }|dk	rt|jƒ ƒS g S )zK Gets the names of all current layouts defined for the DockWindow.
        N)râ   ÚlistÚkeys)r6   rá   r5   r5   r8   rÍ   {  s    zDockWindow._get_layout_namesc             C   s   | j ƒ }|dk	r|j|ƒS dS )z; Gets the layout data for a specified layout name.
        N)râ   rØ   )r6   r)   rá   r5   r5   r8   rÑ   ˆ  s    
zDockWindow._get_layoutc             C   sN   | j }|dkrJ| jdd�}|dk	rJ|j|ƒ}|dk	rB||= |||< |jƒ  dS )z> Deletes the layout data for a specified layout name.
        r:   Úc)ÚmodeN)r½   rß   rØ   rE   )r6   r)   r½   rà   rá   r5   r5   r8   rÓ   •  s    
zDockWindow._delete_layoutc             C   sT   | j }|dkrP| jdd�}|dk	rP|j|ƒ}|dkr8i }|||< |||< |jƒ  dS )z; Sets the layout data for a specified layout name.
        r:   rå   )ræ   N)r½   rß   rØ   rE   )r6   r)   Zlayoutr½   rà   rá   r5   r5   r8   rÐ   ¦  s    
zDockWindow._set_layoutÚrc             C   s,   yt jtjjtƒ dƒ|dd�S    d S d S )NrQ   r   )ÚflagÚprotocoléÿÿÿÿ)ÚshelveÚopenÚosÚpathÚjoinr   )r6   ræ   r5   r5   r8   rß   ¸  s
    
zDockWindow._get_dw_dbc          	   C   sÈ   d t _t_x>tD ]6}|jdkr|jdkr:dt_t jrHP qdt _tjrP qW g }x6tD ].}|jdkrV|jt|jd|d|jdkd�ƒ qVW t|ƒdkr²|j	d	d
„ ƒ t
ƒ g|dd…< tt tg| ddiŽS )z* Returns the 'Features' sub_menu.
        Fr:   r   TrÞ   r-   )r)   r*   rÝ   r.   r¼   r   c             S   s   t | j|jƒS )N)Úcmpr)   )Úlrç   r5   r5   r8   Ú<lambda>Ü  s    z.DockWindow._get_feature_menu.<locals>.<lambda>r)   ZFeatures)Úenable_features_actionr¶   Údisable_features_actionr#   rÙ   rÚ   Úappendr   r¹   Úsortr   r   )r6   rÜ   Úactionsr5   r5   r8   r¿   Ã  s0    





zDockWindow._get_feature_menuc             C   sr   | j ƒ }t|ƒdkr2tddd�g}tddd�g}n$|jƒ  dd„ |D ƒ}dd„ |D ƒ}t|dd	iŽt|dd
iŽgS )zc Gets the sub-menus for the 'Restore layout' and 'Delete layout' menu
            options.
        r   z<empty>F)r)   r¶   c             S   s    g | ]}t |d t|ƒ d�‘qS )zself.on_restore_layout(%s))r)   r*   )r   Úrepr)Ú.0r)   r5   r5   r8   ú
<listcomp>ò  s   z0DockWindow._get_layout_menus.<locals>.<listcomp>c             S   s    g | ]}t |d t|ƒ d�‘qS )zself.on_delete_layout(%s))r)   r*   )r   rø   )rù   r)   r5   r5   r8   rú   ÷  s   r)   zRestore LayoutzDelete Layout)rÍ   r¹   r   rö   r   )r6   r_   Zrestore_actionsZdelete_actionsr5   r5   r8   rÀ   è  s    zDockWindow._get_layout_menusc       	      C   s¾   t |ttfƒr¸| j}| j}|dkr(| j}|j|ƒ d| _y\| jj| j	||f Ž }t
tddƒ}t|dƒr†|j|kr†t|dƒr†d|j |_|j||ƒ |S    t|d|jj dd� Y nX tjS )	z> Handles a Python object being dropped on the window.
        NÚnodeÚobjÚnamespace_namez@@%szMAn error occurred while attempting to add an item of type '%s' to the window.zCannot add item to window)rY   )rC   r%   r   r<   Ú
_dock_infoÚ_leave_infoÚdrawrˆ   rK   Úhandler_argsÚgetattrr   Úhasattrrü   rý   r½   Zdockr^   rA   rB   rg   ÚDragNone)	r6   ÚxÚyÚdataÚdrag_resultr¯   Ú	dock_infor<   Úbindingr5   r5   r8   Úwx_dropped_on  s,    

zDockWindow.wx_dropped_onc       	      C   sè   t |tƒ}|st |tƒrÌ|r8| jj| j|f Ž  r8tjS | j}|dkrdt	}t |tƒr^|j
| _nd| _| j}| jj||| jdƒ | _}|j|jks´|j|jk	s´|j|jks´|j|jkrÈ|j|ƒ |j|ƒ |S | j|||ƒdk	râ|S tjS )zA Handles a Python object being dragged over the control.
        NéP   F)rC   r%   r   rˆ   r9   r  rg   r  rþ   r!   Z	tab_widthZ
_dock_sizer<   r�   Z
DockInfoAtrZ   ZregionZboundsZ
tab_boundsr   Ú_can_drop_on_feature)	r6   r  r  r  r  Zui_providerZcur_dock_infor¯   r	  r5   r5   r8   Úwx_drag_any(  s0    




zDockWindow.wx_drag_anyc             C   s,   | j dk	r(| j j| jƒ | j d | _| _ dS )z= Handles a dragged Python object leaving the window.
        N)rþ   r   r<   rÿ   )r6   r  r5   r5   r8   Úwx_drag_leaveX  s    
zDockWindow.wx_drag_leavec             C   s   dS )z= Adds a menu item to the menu bar being constructed.
        Nr5   )r6   Z	menu_itemr5   r5   r8   Úadd_to_menuk  s    zDockWindow.add_to_menuc             C   s   dS )zA Adds a tool bar item to the tool bar being constructed.
        Nr5   )r6   Ztoolbar_itemr5   r5   r8   Úadd_to_toolbart  s    zDockWindow.add_to_toolbarc             C   s   dS )zM Returns whether the action should be defined in the user interface.
        Tr5   )r6   r*   r5   r5   r8   Úcan_add_to_menu}  s    zDockWindow.can_add_to_menuc             C   s   dS )za Returns whether the toolbar action should be defined in the user
            interface.
        Tr5   )r6   r*   r5   r5   r8   Úcan_add_to_toolbar‡  s    zDockWindow.can_add_to_toolbarc          	   C   sZ   |j }|dd… dkr,t|tƒ d| jiƒ n*t| |ƒ}y
|ƒ  W n   ||ƒ Y nX dS )zE Performs the action described by a specified Action object.
        Né   zself.r6   )r*   ÚevalÚglobalsr³   r  )r6   Zaction_objectr*   Úmethodr5   r5   r8   Úperform‘  s    

zDockWindow.performc             C   s   | j d k	r| j jƒ S d S )N)r<   ZGetSizer)r6   r5   r5   r8   Ú
_get_sizer¤  s    

zDockWindow._get_sizerc             C   s   | j j|ƒ d S )N)r<   ZSetSizer)r6   r�   r5   r5   r8   Ú
_set_sizer©  s    zDockWindow._set_sizerc             C   s4   x.|dkrdS t |jƒt |jƒkr&|S |j}qW dS )z? Finds the first group with any hidden items (if any).
        N)r¹   r°   Zvisible_contentsrI   )r6   rÃ   r5   r5   r8   rË   ²  s    zDockWindow._hidden_group_forc             C   s‚   | j dk	rd| j j||ƒ}t|tƒrdt||| jƒ}|j||ƒrd| j}|dk	rZ||k	rZ|jƒ  || _dS | jdk	r~| jjƒ  d| _dS )zi Returns a feature that the pointer is over and which can accept the
            specified data.
        N)	r�   r    rC   r   Ú	FakeEventr<   rÉ   rÄ   rÅ   )r6   r  r  r  r7   rš   Zldcr5   r5   r8   r  Á  s    



zDockWindow._can_drop_on_featurerê   )N)N)N)rç   )RrB   rS   rT   r   rg   rh   r<   r   Údock_window_handlerrˆ   r   r  r
   rO   r   r{   r   r.   r   r�   r   r½   ZDefaultPositionZDefaultSizeZFULL_REPAINT_ON_RESIZErf   r…   r‡   rR   rŠ   r�   r†   r�   r–   r“   rE   r—   rj   r™   rl   rn   rp   rr   rt   rv   rx   rz   rÆ   r(   r+   rÊ   rÌ   r/   r,   r0   rÒ   rÔ   r1   r2   r3   rÞ   râ   rÍ   rÑ   rÓ   rÐ   rß   r¿   rÀ   r  r  r  r  r  r  r  r  r  r  rË   r  Ú__classcell__r5   r5   )rA   r8   ra     s‚   
"	
		C#
			




%#0		

	ra   c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
r  c             C   s   |||  | _ | _| _d S )N)r  r  r7   )r6   r  r  r7   r5   r5   r8   rf   Ý  s    zFakeEvent.__init__c             C   s   | j S )N)r  )r6   r5   r5   r8   r¡   à  s    zFakeEvent.GetXc             C   s   | j S )N)r  )r6   r5   r5   r8   r¢   á  s    zFakeEvent.GetYc             C   s   | j S )N)r7   )r6   r5   r5   r8   ÚGetEventObjectâ  s    zFakeEvent.GetEventObjectN)rB   rS   rT   rf   r¡   r¢   r  r5   r5   r5   r8   r  Û  s   r  c            	   @   sb   e Zd ZeZeZeZeZ	eZ
eeeeddƒeddd�ƒeeddƒeddd�ƒƒdd	d
dgd�ZdS )r×   zname<100>{Label}Ú3zuser_name{Remember label}F)Z	show_leftz
style<101>zuser_style{Remember style}zEdit propertiesrV   rW   rX   )rY   rZ   r[   N)rB   rS   rT   r   r)   r
   rÕ   r½   r   r.   rÖ   r   r   r   Ztraits_viewr5   r5   r5   r8   r×   è  s   


r×   )HÚ__doc__rë   rí   rg   rª   Z
pyface.apir   Z
traits.apir   r   r   r   r   r   r	   r
   Ztraits.trait_baser   Ztraitsui.apir   r   r   r   r   r   Ztraitsui.helperr   Ztraitsui.menur   r   r   Ztraitsui.dockable_view_elementr   Ztraitsui.dock_window_themer   r   Zpyface.wx.drag_and_dropr   r   Zpyface.message_dialogr^   Z
dock_sizerr   r   r   r   r    r!   r"   r#   Z	idockabler$   Zidock_ui_providerr%   Úplatformr˜   r‰   rµ   r·   r»   rÁ   r¾   r¸   ró   rô   r4   r  rU   ra   r7   r  r×   r5   r5   r5   r8   Ú<module>   sb   ( (
],       ]