3
8Ad]žm  ã               @   sš  d Z ddlmZ ddlmZ edgƒ ddlZddlmZ edƒZ	ddl
mZ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 ddlmZmZmZ ddlm Z  ej!dej"dej#dej$dej%dej&dej'dej(dej)dej*dej+dej,dej-dej.diZ/d d!d"hZ0d#d$„ Z1ee1ƒ G d%d&„ d&eƒZ2G d'd(„ d(eƒZ3G d)d*„ d*eeƒZ4G d+d,„ d,eeƒZ5G d-d.„ d.ej6ƒZ7d/d0„ Z8dS )1zs Defines the concrete implementations of the traits Toolkit interface for
    the wxPython user interface toolkit.
é    )Úabsolute_import)Úassert_toolkit_importÚwxN)Útoolkit_objectz	init:_app)ÚHasPrivateTraitsÚInstanceÚPropertyÚCategoryÚcached_property)Úset_ui_handler)ÚPythonDropTarget)ÚTheme)ÚUI)ÚDockWindowTheme)ÚToolkité   )ÚWindowColorÚ	screen_dxÚ	screen_dy)Úposition_windowZ	left_downZleft_dclickZleft_upZmiddle_downZmiddle_dclickZ	middle_upZ
right_downZright_dclickZright_upZ
mouse_moveZenterZleaveZmouse_wheelZpaintZpopupZpopoverÚinfoc             G   s   t j| f|žŽ  dS )zg Handles UI notification handler requests that occur on a thread other
        than the UI thread.
    N)r   Z	CallAfter)ÚhandlerÚargs© r   úo/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/traitsui-6.1.2-py3.6.egg/traitsui/wx/toolkit.pyÚ
ui_handlerQ   s    r   c               @   s  e Zd Z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d„Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ ZdAd(d)„Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Z d>d?„ Z!dS )BÚ
GUIToolkitz0 Implementation class for wxPython toolkit.
    c             C   s   ddl m} |j||ƒ dS )zs Creates a wxPython panel-based user interface using information
            from the specified UI object.
        r   )Úui_panelN)Ú r   )ÚselfÚuiÚparentr   r   r   r   r   g   s    zGUIToolkit.ui_panelc             C   s   ddl m} |j||ƒ dS )zv Creates a wxPython subpanel-based user interface using information
            from the specified UI object.
        r   )r   N)r   r   Úui_subpanel)r   r    r!   r   r   r   r   r"   n   s    zGUIToolkit.ui_subpanelc             C   s   ddl m} |j||ƒ dS )z‚ Creates a wxPython modal "live update" dialog user interface using
            information from the specified UI object.
        r   )Úui_liveN)r   r#   Úui_livemodal)r   r    r!   r#   r   r   r   r$   u   s    zGUIToolkit.ui_livemodalc             C   s   ddl m} |j||ƒ dS )z† Creates a wxPython non-modal "live update" window user interface
            using information from the specified UI object.
        r   )r#   N)r   r#   )r   r    r!   r#   r   r   r   r#   |   s    zGUIToolkit.ui_livec             C   s   ddl m} |j||ƒ dS )zt Creates a wxPython modal dialog user interface using information
            from the specified UI object.
        r   )Úui_modalN)r   r%   )r   r    r!   r%   r   r   r   r%   ƒ   s    zGUIToolkit.ui_modalc             C   s   ddl m} |j||ƒ dS )zx Creates a wxPython non-modal dialog user interface using
            information from the specified UI object.
        r   )r%   N)r   r%   Úui_nonmodal)r   r    r!   r%   r   r   r   r&   Š   s    zGUIToolkit.ui_nonmodalc             C   s   ddl m} |j||ƒ dS )zŒ Creates a wxPython temporary "live update" popup dialog user
            interface using information from the specified UI object.
        r   )r#   N)r   r#   Úui_popup)r   r    r!   r#   r   r   r   r'   ‘   s    zGUIToolkit.ui_popupc             C   s   ddl m} |j||ƒ dS )zŒ Creates a wxPython temporary "live update" popup dialog user
            interface using information from the specified UI object.
        r   )r#   N)r   r#   Ú
ui_popover)r   r    r!   r#   r   r   r   r(   ˜   s    zGUIToolkit.ui_popoverc             C   s   ddl m} |j||ƒ dS )zŒ Creates a wxPython temporary "live update" popup dialog user
            interface using information from the specified UI object.
        r   )r#   N)r   r#   Úui_info)r   r    r!   r#   r   r   r   r)   Ÿ   s    zGUIToolkit.ui_infoc             C   s   ddl m} |j||ƒ dS )zu Creates a wxPython wizard dialog user interface using information
            from the specified UI object.
        r   )Ú	ui_wizardN)r   r*   )r   r    r!   r*   r   r   r   r*   ¦   s    zGUIToolkit.ui_wizardNr   c       	      C   s"   ddl m} |j|||||||ƒS )a®   Creates a wxPython modal dialog user interface that
            runs as a complete application, using information from the
            specified View object.

        Parameters
        ----------
        context : object or dictionary
            A single object or a dictionary of string/object pairs, whose trait
            attributes are to be edited. If not specified, the current object is
            used.
        view : view or string
            A View object that defines a user interface for editing trait
            attribute values.
        kind : string
            The type of user interface window to create. See the
            **traitsui.view.kind_trait** trait for values and
            their meanings. If *kind* is unspecified or None, the **kind**
            attribute of the View object is used.
        handler : Handler object
            A handler object used for event handling in the dialog box. If
            None, the default handler for Traits UI is used.
        id : string
            A unique ID for persisting preferences about this user interface,
            such as size and position. If not specified, no user preferences
            are saved.
        scrollable : Boolean
            Indicates whether the dialog box should be scrollable. When set to
            True, scroll bars appear on the dialog box if it is not large enough
            to display all of the items in the view at one time.

        r   )Úview_application)r   r+   )	r   ÚcontextÚviewÚkindr   ÚidZ
scrollabler   r+   r   r   r   r+   ­   s    !zGUIToolkit.view_applicationc             C   sV  |j }|j}|jƒ }|dkr0d	\}}tt }}n|jƒ \}}|jƒ \}}|jƒ \}	}
|j}|j}|dk rn|	}n|dkr„t	|t ƒ}nt	|ƒ}|dk rš|
}n|dkr°t	|t ƒ}nt	|ƒ}|j
tkrÒt|||ƒ dS |j}|j}|d
k �r||| d  }|dk �rx|d }nl|dk�r0|| | t	|ƒ d }nH|dk �rT|| | t	|| ƒ }n$|dk�rp|t	|| ƒ }nt	|ƒ}|dk �r¦||| d  }|dk �r|d }nl|dk�rÊ|| | t	|ƒ d }nH|dk �rî|| | t	|| ƒ }n$|dk�r
|t	|| ƒ }nt	|ƒ}t|tjƒ d ƒ}t|tjƒ d ƒ}|jtd|ƒtd|ƒ||ƒ dS )z@ Positions the associated dialog window on the display.
        Nr   g        g      ð?g    ðiø@é   é   r   )r   r   g    ðiøÀg      ð¿g    ðiøÀg      ð¿)r-   ÚcontrolÚ	GetParentr   r   ZGetPositionTupleZGetSizeTupleÚwidthÚheightÚintr.   ÚPopupsr   ÚxÚyÚminr   ZDisplaySizeÚSetDimensionsÚmax)r   r    r-   Úwindowr!   ZpxÚpyZpdxZpdyZ	cur_widthZ
cur_heightr4   r5   r8   r9   r   r   r   ÚpositionÖ   sf    












zGUIToolkit.positionc             C   s   ddl m} |j||ƒ dS )z= Shows a help window for a specified UI and control.
        r   )r   N)r   r   Ú	show_help)r   r    r2   r   r   r   r   r@   ,  s    zGUIToolkit.show_helpc             C   s   ddl m} |j|ƒ dS )zH Saves user preference information associated with a UI window.
        r   )ÚhelperN)r   rA   Úsave_window)r   r    rA   r   r   r   rB   6  s    zGUIToolkit.save_windowc             C   s„   d }}|j dk	r>|j jƒ }|j j}|j}|jƒ  ||_||_|j||ƒ |dk	r€|j j|ƒ |jƒ }|dk	r€|j	|j dt
jƒ dS )z@ Rebuilds a UI after a change to the content of the UI.
        Nr   )r2   ÚGetSizeZ_parentr   Zrecycler    ZrebuildÚSetSizeZGetSizerÚAddr   ZEXPAND)r   r    r!   Úsizer   Zsizerr   r   r   Ú
rebuild_uiA  s    

zGUIToolkit.rebuild_uic             C   s   |j j|jƒ dS )z+ Sets the title for the UI window.
        N)r2   ÚSetTitleÚtitle)r   r    r   r   r   Ú	set_titleZ  s    zGUIToolkit.set_titlec             C   s.   ddl m} t|j|ƒr*|jj|jjƒ ƒ dS )z* Sets the icon for the UI window.
        r   )ÚImageResourceN)Zpyface.image_resourcerK   Ú
isinstanceÚiconr2   ZSetIconZcreate_icon)r   r    rK   r   r   r   Úset_iconc  s    zGUIToolkit.set_iconc             C   s   ddl m} |j|ƒS )zC Converts a keystroke event into a corresponding key name.
        r   )Úkey_event_to_name)r   rO   )r   ÚeventrO   r   r   r   rO   o  s    zGUIToolkit.key_event_to_namec       
      C   sÚ   |dkr\t jt jt jt jt jt jt jt jt j	t j
t jt jt jt jf}|jtt||d�ƒƒ n|dkrlt jf}|dkrz|j}|jƒ }tƒ }|j}x|D ]}|||||ƒ q”W |j|ƒ x |jƒ D ]}	| j||	||ƒ q¾W dS )z‚ Hooks all specified events for all controls in a UI so that they
            can be routed to the correct event handler.
        N)r    r2   Úkeys)r   ÚwxEVT_LEFT_DOWNÚwxEVT_LEFT_DCLICKÚwxEVT_LEFT_UPÚwxEVT_MIDDLE_DOWNÚwxEVT_MIDDLE_DCLICKÚwxEVT_MIDDLE_UPÚwxEVT_RIGHT_DOWNÚwxEVT_RIGHT_DCLICKÚwxEVT_RIGHT_UPÚwxEVT_MOTIONÚwxEVT_ENTER_WINDOWÚwxEVT_LEAVE_WINDOWÚwxEVT_MOUSEWHEELÚwxEVT_PAINTZSetDropTargetr   ÚDragHandlerZ
wxEVT_CHARÚroute_eventÚGetIdÚEventHandlerWrapperZConnectZPushEventHandlerÚGetChildrenÚhook_events)
r   r    r2   Úeventsr   r/   Zevent_handlerÚconnectrP   Úchildr   r   r   re   {  s:    

zGUIToolkit.hook_eventsc             C   s”   t |jƒ  }|jƒ }|j}d}t|ddƒ}|dk	rJt|d|jƒ |f dƒ}|dkrnt|d| dƒplt|ddƒ}|dksˆ||j||ƒdkr�|jƒ  dS )z> Routes a hooked event to the correct handler method.
        NÚ_ownerzon_%s_%szon_%sZon_any_eventF)ÚEventSuffixÚGetEventTypeZGetEventObjectr   ÚgetattrÚget_idr   ÚSkip)r   r    rP   Úsuffixr2   r   ÚmethodÚownerr   r   r   ra   §  s    zGUIToolkit.route_eventc             C   s   |j ƒ  dS )z] Indicates that an event should continue to be processed by the
            toolkit.
        N)rn   )r   rP   r   r   r   Ú
skip_event¿  s    zGUIToolkit.skip_eventc             C   s   t |ƒ |jƒ  dS )z3 Destroys a specified GUI toolkit control.
        N)Ú_popEventHandlersZDestroy)r   r2   r   r   r   Údestroy_controlÉ  s    zGUIToolkit.destroy_controlc             C   s&   x|j ƒ D ]}t|ƒ q
W |jƒ  dS )z\ Destroys all of the child controls of a specified GUI toolkit
            control.
        N)rd   rs   ZDestroyChildren)r   r2   rh   r   r   r   Údestroy_childrenÓ  s    zGUIToolkit.destroy_childrenc             C   s   |j ƒ |jƒ fS )zi Returns a ( width, height ) tuple containing the size of a
            specified toolkit image.
        )ÚGetWidthÚ	GetHeight)r   Úimager   r   r   Ú
image_sizeà  s    zGUIToolkit.image_sizec             C   s   dt iS )zû Returns a dictionary of useful constants.

            Currently, the dictionary should have the following key/value pairs:

            - WindowColor': the standard window background color in the toolkit
              specific color format.
        r   )r   )r   r   r   r   Ú	constantsê  s    	zGUIToolkit.constantsc             O   s   ddl m} |j||ŽS )Nr   )Úcolor_trait)r   r{   ZWxColor)r   r   ÚtraitsÚctr   r   r   r{   ú  s    zGUIToolkit.color_traitc             O   s   ddl m} |j||ŽS )Nr   )Úrgb_color_trait)r   r~   ZRGBColor)r   r   r|   Zrgbctr   r   r   r~   þ  s    zGUIToolkit.rgb_color_traitc             O   s   ddl m} |j||ŽS )Nr   )Ú
font_trait)r   r   ZWxFont)r   r   r|   Úftr   r   r   r     s    zGUIToolkit.font_traitc             C   s   ddl m} |jS )Nr   )Ú	ui_editor)r   r�   ZUIEditor)r   r�   r   r   r   r�     s    zGUIToolkit.ui_editorc             O   s   ddl m} |j||ŽS )Nr   )Úshell_editor)r   r‚   ZToolkitEditorFactory)r   r   r|   Úser   r   r   r‚   H  s    zGUIToolkit.shell_editor)NNr   NN)NN)"Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   r$   r#   r%   r&   r'   r(   r)   r*   r+   r?   r@   rB   rG   rJ   rN   rO   re   ra   rr   rt   ru   ry   rz   r{   r~   r   r�   r‚   r   r   r   r   r   _   s@    
(V
	
,


	=r   c               @   sD   e Zd ZdZeeƒZeejƒZ	dd„ Z
dd„ Zdd„ Zdd	d
„ZdS )r`   z Handler for drag events.
    c             C   s   | j d||||ƒS )z> Handles a Python object being dropped on the window.
        Z
dropped_on)Ú_drag_event)r   r8   r9   ÚdataÚdrag_resultr   r   r   Úwx_dropped_onn  s    zDragHandler.wx_dropped_onc             C   s   | j d||||ƒS )z> Handles a Python object being dragged over the tree.
        Z	drag_over)rˆ   )r   r8   r9   r‰   rŠ   r   r   r   Úwx_drag_overw  s    zDragHandler.wx_drag_overc             C   s
   | j dƒS )z= Handles a dragged Python object leaving the window.
        Z
drag_leave)rˆ   )r   r‰   r   r   r   Úwx_drag_leave€  s    zDragHandler.wx_drag_leaveNc             C   s¢   | j }| jj}d}t|ddƒ}	|	dk	r>t|d|	jƒ |f dƒ}|dkrVt|d| dƒ}|dkrdtjS |dkr||| jj|	ƒ}
n|| jj|	||||ƒ}
|
dkrž|}
|
S )zB Handles routing a drag event to the appropriate handler.
        Nri   zon_%s_%szon_%s)r2   r    r   rl   rm   r   ZDragNoner   )r   ro   r8   r9   r‰   rŠ   r2   r   rp   rq   Úresultr   r   r   rˆ   ‰  s"    zDragHandler._drag_event)NNNN)r„   r…   r†   r‡   r   r   r    r   ZWindowr2   r‹   rŒ   r�   rˆ   r   r   r   r   r`   [  s   
			 r`   c               @   sN   e Zd ZdZeZeZedd�Zdd„ Zdd„ Z	dd	„ Z
d
d„ Zedd„ ƒZdS )ÚWXThemeza Defines the extensions needed to make the generic Theme class specific
        to wxPython.
    rx   )Ú
depends_onc             C   s0   | j d kr*tj}| j}|d k	r$|j}|| _ | j S )N)Ú_content_colorr   ÚBLACKÚimage_sliceÚcontent_color)r   ÚcolorÚislicer   r   r   Ú_get_content_color»  s    
zWXTheme._get_content_colorc             C   s
   || _ d S )N)r‘   )r   r•   r   r   r   Ú_set_content_colorÆ  s    zWXTheme._set_content_colorc             C   s0   | j d kr*tj}| j}|d k	r$|j}|| _ | j S )N)Ú_label_colorr   r’   r“   Úlabel_color)r   r•   r–   r   r   r   Ú_get_label_colorÉ  s    
zWXTheme._get_label_colorc             C   s
   || _ d S )N)r™   )r   r•   r   r   r   Ú_set_label_colorÔ  s    zWXTheme._set_label_colorc             C   s$   ddl m} | jd krd S || jƒS )Nr   )Úimage_slice_for)r“   r�   rx   )r   r�   r   r   r   Ú_get_image_slice×  s    
zWXTheme._get_image_sliceN)r„   r…   r†   r‡   r   r”   rš   r“   r—   r˜   r›   rœ   r
   rž   r   r   r   r   r�   «  s   
r�   c               @   s<   e Zd ZdZedd�Zedd�Zedd„ ƒZedd„ ƒZ	d	S )
ÚWXDockWindowThemezk Defines the extensions needed to make the generic DockWindowTheme class
        specific to wxPython.
    Útab_inactive_edge)r�   Útab_hover_edgec             C   s   | j }|d krd S |jƒ jƒ S )N)r    Úcreate_imageÚConvertToBitmap)r   rx   r   r   r   Ú_get_tab_inactive_edge_bitmapò  s    z/WXDockWindowTheme._get_tab_inactive_edge_bitmapc             C   s    | j }|d kr| jS |jƒ jƒ S )N)r¡   Útab_inactive_edge_bitmapr¢   r£   )r   rx   r   r   r   Ú_get_tab_hover_edge_bitmapú  s    z,WXDockWindowTheme._get_tab_hover_edge_bitmapN)
r„   r…   r†   r‡   r   r¥   Ztab_hover_edge_bitmapr
   r¤   r¦   r   r   r   r   rŸ   å  s
   

rŸ   c               @   s   e Zd ZdZdS )rc   zk Simple wrapper around wx.EvtHandler used to determine which event
    handlers were added by traitui.
    N)r„   r…   r†   r‡   r   r   r   r   rc     s   rc   c             C   sP   x0| | j ƒ k	r0| j ƒ }t|tƒr,| jdƒ qP qW x| jƒ D ]}t|ƒ q<W dS )z[ Pop any event handlers that have been pushed on to a window and its
        children.
    TN)ZGetEventHandlerrL   rc   ZPopEventHandlerrd   rs   )Zctrlr   rh   r   r   r   rs     s    
rs   )9r‡   Ú
__future__r   Ztraitsui.toolkitr   r   Zpyface.toolkitr   Zpyface_toolkitZ_appZ
traits.apir   r   r   r	   r
   Ztraits.trait_notifiersr   Zpyface.wx.drag_and_dropr   Ztraitsui.themer   Ztraitsui.uir   Ztraitsui.dock_window_themer   r   rz   r   r   r   rA   r   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   rj   r7   r   r   r`   r�   rŸ   Z
EvtHandlerrc   rs   r   r   r   r   Ú<module>   sT   


     P: 