a
    §ˆc‘E  ã                   @   sj  d Z ddl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 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 ddlmZ e e¡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,h d£Z-d d!„ Z.ee.ƒ G d"d#„ d#eƒZ/G d$d%„ d%e
ƒZ0G d&d'„ d'ej1ƒZ2e2fd(d)„Z3dS )*zs Defines the concrete implementations of the traits Toolkit interface for
    the wxPython user interface toolkit.
é    N)Úassert_toolkit_importÚwx)Útoolkit_objectz	init:_app)ÚHasPrivateTraitsÚInstance)Úset_ui_handler)ÚSystemMetrics)ÚPythonDropTarget)ÚTheme)ÚUI)ÚToolkité   ©ÚWindowColor)Ú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paint>   ZpopoverZpopupÚinfoc                 G   s   t j| g|¢R Ž  dS )zbHandles UI notification handler requests that occur on a thread other
    than the UI thread.
    N)r   Ú	CallAfter)ÚhandlerÚargs© r   úV/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/traitsui/wx/toolkit.pyÚ
ui_handlerE   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d=d(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S )>Ú
GUIToolkitz*Implementation class for wxPython toolkit.c                 C   s   ddl m} | ||¡ dS )znCreates a wxPython panel-based user interface using information
        from the specified UI object.
        r   ©Úui_panelN)Ú r   ©ÚselfÚuiÚparentr   r   r   r   r   X   s    zGUIToolkit.ui_panelc                 C   s   ddl m} | ||¡ dS )zqCreates a wxPython subpanel-based user interface using information
        from the specified UI object.
        r   r   N)r   r   Úui_subpanelr   r   r   r   r    `   s    zGUIToolkit.ui_subpanelc                 C   s   ddl m} | ||¡ 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#   h   s    zGUIToolkit.ui_livemodalc                 C   s   ddl m} | ||¡ 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"   p   s    zGUIToolkit.ui_livec                 C   s   ddl m} | ||¡ dS )zoCreates 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&   x   s    zGUIToolkit.ui_modalc                 C   s   ddl m} | ||¡ dS )zsCreates a wxPython non-modal dialog user interface using
        information from the specified UI object.
        r   r%   N)r   r&   Úui_nonmodalr'   r   r   r   r(   €   s    zGUIToolkit.ui_nonmodalc                 C   s   ddl m} | ||¡ 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_popupr$   r   r   r   r*   ˆ   s    zGUIToolkit.ui_popupc                 C   s   ddl m} | ||¡ dS r)   )r   r"   Ú
ui_popoverr$   r   r   r   r+   �   s    zGUIToolkit.ui_popoverc                 C   s   ddl m} | ||¡ dS r)   )r   r"   Úui_infor$   r   r   r   r,   ˜   s    zGUIToolkit.ui_infoc                 C   s   ddl m} | ||¡ dS )zpCreates 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} | |||||||¡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   sd  |j }|j}| ¡ }|du r6d\}}tƒ j}tƒ j}n| ¡ \}}| ¡ \}}| ¡ \}	}
|j}|j	}|dk rt|	}n"|dkrŽt
|tƒ j ƒ}nt
|ƒ}|dk r¤|
}n"|dkr¾t
|tƒ j ƒ}nt
|ƒ}|jtv ràt|||ƒ dS |j}|j}|dk �r||| d  }|dk �r†|d }nl|d	k�r>|| | t
|ƒ d
 }nH|dk �rb|| | t
|| ƒ }n$|dk�r~|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 ¡ d ƒ}t|t ¡ d
 ƒ}| td|ƒtd|ƒ||¡ dS )z6Positions the associated dialog window on the display.N)r   r   g        g      ð?g    ðiøÀé   r   é   g      ð¿r   )r0   ÚcontrolZ	GetParentr   Zscreen_widthZscreen_heightZGetPositionÚGetSizeÚwidthÚheightÚintr1   ÚPopupsr   ÚxÚyÚminr   ZDisplaySizeÚSetSizeÚmax)r   r   r0   Zwindowr   ZpxÚpyZpdxZpdyZ	cur_widthZ
cur_heightr7   r8   r;   r<   r   r   r   Úposition×   sh    













zGUIToolkit.positionc                 C   s   ddl m} | ||¡ dS )z3Shows a help window for a specified UI and control.r   r   N)r   r   Ú	show_help)r   r   r5   r   r   r   r   rB   )  s    zGUIToolkit.show_helpc                 C   s   ddl m} | |¡ dS )z>Saves user preference information associated with a UI window.r   )ÚhelperN)r   rC   Úsave_window)r   r   rC   r   r   r   rD   /  s    zGUIToolkit.save_windowc                 C   s„   d }}|j dur>|j  ¡ }|j j}|j}| ¡  ||_||_| ||¡ |dur€|j  |¡ | ¡ }|dur€| 	|j dt
j¡ dS )z6Rebuilds a UI after a change to the content of the UI.Nr   )r5   r6   Ú_parentr   Zrecycler   Zrebuildr>   ZGetSizerÚAddr   ZEXPAND)r   r   r   Úsizer   Zsizerr   r   r   Ú
rebuild_ui5  s    

zGUIToolkit.rebuild_uic                 C   s   |j  |j¡ dS )z!Sets the title for the UI window.N)r5   ZSetTitleÚtitle)r   r   r   r   r   Ú	set_titleI  s    zGUIToolkit.set_titlec                 C   s.   ddl m} t|j|ƒr*|j |j ¡ ¡ dS )z Sets the icon for the UI window.r   )ÚImageResourceN)Zpyface.image_resourcerK   Ú
isinstanceZiconr5   ZSetIconZcreate_icon)r   r   rK   r   r   r   Úset_iconM  s    zGUIToolkit.set_iconc                 C   s   ddl m} | |¡S )z9Converts a keystroke event into a corresponding key name.r   )Úkey_event_to_name)r   rN   )r   ÚeventrN   r   r   r   rN   T  s    zGUIToolkit.key_event_to_namec           
      C   sÒ   |du 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}| tt||d�ƒ¡ n|dkrlt jf}|du rz|j}| ¡ }tƒ }|j}|D ]}|||||ƒ q’| |¡ | ¡ D ]}	|  ||	||¡ q¸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   r5   Ú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_eventZGetIdÚEventHandlerWrapperZConnectZPushEventHandlerÚGetChildrenÚhook_events)
r   r   r5   Úeventsr   r2   Zevent_handlerÚconnectrO   Úchildr   r   r   rc   Z  s>    òÿ
zGUIToolkit.hook_eventsc                 C   s”   t | ¡  }| ¡ }|j}d}t|ddƒ}|durJt|d| ¡ |f dƒ}|du rnt|d| dƒplt|ddƒ}|du sˆ||j||ƒdu r�| ¡  dS )z4Routes a hooked event to the correct handler method.NÚ_ownerúon_%s_%súon_%sZon_any_eventF)ÚEventSuffixZGetEventTypeZGetEventObjectr   ÚgetattrÚget_idr   ÚSkip)r   r   rO   Úsuffixr5   r   ÚmethodÚownerr   r   r   r`   „  s    ÿÿzGUIToolkit.route_eventc                 C   s   |  ¡  dS )zXIndicates that an event should continue to be processed by the
        toolkit.
        N)rm   )r   rO   r   r   r   Ú
skip_event™  s    zGUIToolkit.skip_eventc                 C   s    t |ƒ dd„ }t ||¡ dS )z)Destroys a specified GUI toolkit control.c                 S   s0   z|   ¡  W n ty*   t d| ¡ Y n0 d S )Nz#Wx control %r not destroyed cleanly)ZDestroyÚ	ExceptionÚloggerÚ	exception)r5   r   r   r   Ú_destroy_control£  s    ÿz4GUIToolkit.destroy_control.<locals>._destroy_controlN)Ú_popEventHandlersr   r   )r   r5   ru   r   r   r   Údestroy_controlŸ  s    zGUIToolkit.destroy_controlc                 C   s&   |  ¡ D ]}t|ƒ qt |j¡ dS )zWDestroys all of the child controls of a specified GUI toolkit
        control.
        N)rb   rv   r   r   ZDestroyChildren)r   r5   rf   r   r   r   Údestroy_children­  s    
zGUIToolkit.destroy_childrenc                 C   s   |  ¡ | ¡ fS )zdReturns a ( width, height ) tuple containing the size of a
        specified toolkit image.
        )ZGetWidthZ	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|i |¤Ž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|i |¤Ž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|i |¤ŽS )Nr   )Ú
font_trait)r   r€   ZWxFont)r   r   r}   Úftr   r   r   r€   Ó  s    zGUIToolkit.font_trait)NNr   NN)NN) Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r#   r"   r&   r(   r*   r+   r,   r-   r.   rA   rB   rD   rH   rJ   rM   rN   rc   r`   rq   rw   rx   rz   r{   r|   r   r€   r   r   r   r   r   U   sD        ø
/R
*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   |   d||||¡S )z4Handles a Python object being dropped on the window.Z
dropped_on©Ú_drag_event©r   r;   r<   ÚdataÚdrag_resultr   r   r   Úwx_dropped_onè  s    zDragHandler.wx_dropped_onc                 C   s   |   d||||¡S )z4Handles a Python object being dragged over the tree.Z	drag_overr†   rˆ   r   r   r   Úwx_drag_overì  s    zDragHandler.wx_drag_overc                 C   s
   |   d¡S )z3Handles a dragged Python object leaving the window.Z
drag_leaver†   )r   r‰   r   r   r   Úwx_drag_leaveð  s    zDragHandler.wx_drag_leaveNc                 C   s¢   | j }| jj}d}t|ddƒ}	|	dur>t|d|	 ¡ |f dƒ}|du rVt|d| dƒ}|du rdtjS |du r||| jj|	ƒ}
n|| jj|	||||ƒ}
|
du rž|}
|
S )z8Handles routing a drag event to the appropriate handler.Nrg   rh   ri   )r5   r   r   rk   rl   r   ZDragNoner   )r   rn   r;   r<   r‰   rŠ   r5   r   ro   rp   Úresultr   r   r   r‡   ô  s$    ÿzDragHandler._drag_event)NNNN)r‚   rƒ   r„   r…   r   r   r   r   ZWindowr5   r‹   rŒ   r�   r‡   r   r   r   r   r_   Ù  s   
r_   c                   @   s   e Zd ZdZdS )ra   zjSimple wrapper around wx.EvtHandler used to determine which event
    handlers were added by traitui.
    N)r‚   rƒ   r„   r…   r   r   r   r   ra     s   ra   c                 C   sZ   ddl m} |  ¡ }| |ur>| ¡ }t||ƒr8|  d¡ |}q|  ¡ D ]}t||ƒ qFdS )zVPop any event handlers that have been pushed on to a window and its
    children.
    r   )ÚURLResolvingHtmlWindowTN)Zhtml_editorr�   ZGetEventHandlerZGetNextHandlerrL   ZPopEventHandlerrb   rv   )ZctrlZhandler_typer�   r   Znext_handlerrf   r   r   r   rv     s    

rv   )4r…   ÚloggingZtraitsui.toolkitr   r   Zpyface.toolkitr   Zpyface_toolkitZ_appZ
traits.apir   r   Ztraits.trait_notifiersr   Z
pyface.apir   Zpyface.wx.drag_and_dropr	   Ztraitsui.themer
   Ztraitsui.uir   r   r{   r   rC   r   Ú	getLoggerr‚   rs   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   rj   r:   r   r   r_   Z
EvtHandlerra   rv   r   r   r   r   Ú<module>   sR   

ò   6