3
8Ad]“_  ã               @   sÖ   d Z ddlmZmZ ddlmZ eddgƒ ddlmZ edƒ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 ejjejjƒ ƒZG dd„ dejƒZdd„ Zeeƒ G dd„ dejƒZG dd„ deƒZdS )zk Defines the concrete implementations of the traits Toolkit interface for
the PyQt user interface toolkit.
é    )Úabsolute_importÚdivision)Úassert_toolkit_importZqt4Zqt)Útoolkit_objectz	init:_app)Úset_ui_handler)ÚQtCoreÚQtGuiÚqt_api)ÚToolkité   )Ú	screen_dxÚ	screen_dyc               @   s4   e Zd ZdZg Zejƒ Zdd„ Zdd„ Z	dd„ Z
dS )	Ú
_CallAfterzv This class dispatches a handler so that it executes in the main GUI
        thread (similar to the wx function).
    c             O   sr   t jj| ƒ || _|| _|| _| jjƒ  | jj	| ƒ | jj
ƒ  | jtjjƒ jƒ ƒ t jtƒ}tjjƒ j| |ƒ dS )z Initialise the call.
        N)r   ÚQObjectÚ__init__Ú_handlerÚ_argsÚ_kwdsÚ_calls_mutexÚlockÚ_callsÚappendÚunlockZmoveToThreadr   ÚQApplicationÚinstanceÚthreadÚQEventÚ_QT_TRAITS_EVENTZ	postEvent)ÚselfÚhandlerÚargsÚkwdsÚevent© r#   úp/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/traitsui-6.1.2-py3.6.egg/traitsui/qt4/toolkit.pyr   7   s    


z_CallAfter.__init__c             C   sB   |j ƒ tkr0| j| j| jŽ tjjd| jƒ dS tj	j
| |ƒS dS )z  QObject event handler.
        r   TN)Útyper   r   r   r   r   ZQTimerZ
singleShotÚ	_finishedr   r"   )r   r"   r#   r#   r$   r"   O   s
    z_CallAfter.eventc             C   s(   | j jƒ  | j| jj| ƒ= | j jƒ  dS )zH Remove the call from the list, so it can be garbage collected.
        N)r   r   r   Úindexr   )r   r#   r#   r$   r&   _   s    
z_CallAfter._finishedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ZQMutexr   r   r"   r&   r#   r#   r#   r$   r   ,   s   r   c             O   s   t | f|ž|Ž dS )zg Handles UI notification handler requests that occur on a thread other
        than the UI thread.
    N)r   )r   r    r!   r#   r#   r$   Ú
ui_handlerg   s    r,   c                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )Ú_KeyEventHookz0
    Event hook for handling Qt key events.
    c                s   t t| ƒjƒ  || _d S )N)Úsuperr-   r   r   )r   r   )Ú	__class__r#   r$   r   y   s    z_KeyEventHook.__init__c             C   s.   |j ƒ tjjkr| j|ƒS tjj| ||ƒS d S )N)r%   r   r   ZKeyPressr   r   ÚeventFilter)r   Úobjectr"   r#   r#   r$   r0   }   s    
z_KeyEventHook.eventFilter)r(   r)   r*   r+   r   r0   Ú__classcell__r#   r#   )r/   r$   r-   u   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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d0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ Z d>d?„ Z!d@dA„ Z"dBdC„ Z#dDdE„ Z$dFdG„ Z%dHdI„ Z&dJdK„ Z'dLdM„ Z(dNdO„ Z)dPdQ„ Z*dRdS„ Z+dTdU„ Z,dVdW„ Z-dXdY„ Z.dZd[„ Z/d\d]„ Z0d^d_„ Z1d`da„ Z2dbdc„ Z3ddde„ Z4dfdg„ Z5dhdi„ Z6djdk„ Z7dldm„ Z8dndo„ Z9dpdq„ Z:drds„ Z;dtdu„ Z<dvdw„ Z=dxdy„ Z>dzd{„ Z?d|d}„ Z@d~d„ ZAdS )‚Ú
GUIToolkitz, Implementation class for PyQt toolkit.
    c             C   s   ddl m} |j||ƒ dS )zo Creates a PyQt panel-based user interface using information
            from the specified UI object.
        r   )Úui_panelN)Ú r4   )r   ÚuiÚparentr4   r#   r#   r$   r4   Œ   s    zGUIToolkit.ui_panelc             C   s   ddl m} |j||ƒ dS )zr Creates a PyQt subpanel-based user interface using information
            from the specified UI object.
        r   )r4   N)r5   r4   Úui_subpanel)r   r6   r7   r4   r#   r#   r$   r8   “   s    zGUIToolkit.ui_subpanelc             C   s   ddl m} |j||ƒ dS )z~ Creates a PyQt modal "live update" dialog user interface using
            information from the specified UI object.
        r   )Úui_liveN)r5   r9   Úui_livemodal)r   r6   r7   r9   r#   r#   r$   r:   š   s    zGUIToolkit.ui_livemodalc             C   s   ddl m} |j||ƒ dS )z‚ Creates a PyQt non-modal "live update" window user interface
            using information from the specified UI object.
        r   )r9   N)r5   r9   )r   r6   r7   r9   r#   r#   r$   r9   ¡   s    zGUIToolkit.ui_livec             C   s   ddl m} |j||ƒ dS )zp Creates a PyQt modal dialog user interface using information
            from the specified UI object.
        r   )Úui_modalN)r5   r;   )r   r6   r7   r;   r#   r#   r$   r;   ¨   s    zGUIToolkit.ui_modalc             C   s   ddl m} |j||ƒ dS )zt Creates a PyQt non-modal dialog user interface using
            information from the specified UI object.
        r   )r;   N)r5   r;   Úui_nonmodal)r   r6   r7   r;   r#   r#   r$   r<   ¯   s    zGUIToolkit.ui_nonmodalc             C   s   ddl }|j ||ƒ dS )zq Creates a PyQt wizard dialog user interface using information
            from the specified UI object.
        r   N)Ú	ui_wizard)r   r6   r7   r=   r#   r#   r$   r=   ¶   s    zGUIToolkit.ui_wizardNr5   c       	      C   s"   ddl m} |j|||||||ƒS )aª   Creates a PyQt 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)r5   r>   )	r   ÚcontextÚviewÚkindr   ÚidZ
scrollabler    r>   r#   r#   r$   r>   ½   s    !zGUIToolkit.view_applicationc             C   s„  |j }|j}|jƒ }|dkr.d}d}t}t}nJ|jƒ }	t|jƒ ƒtj	j
@ dkrX|j|	ƒ}	|	jƒ }|	jƒ }|jƒ }|jƒ }|jƒ }
|
jƒ }|
jƒ }|j}|j}|dk rª|}n|dkrÀt|t ƒ}nt|ƒ}|dk rÖ|}n|dkrìt|t ƒ}nt|ƒ}|j}|j}|dk �r||| d  }nl|d	k�r@|| | t|ƒ d }nH|dk �rd|| | t|| ƒ }n$|dk�r€|t|| ƒ }nt|ƒ}|d
k �r¤||| d  }nl|dk�rÈ|| | t|ƒ d }nH|dk �rì|| | t|| ƒ }n$|dk�r|t|| ƒ }nt|ƒ}|jƒ }|jƒ tjjk�rd|jtjjƒ |jtd|ƒtd|ƒƒ |jtj||ƒƒ n|jtd|ƒtd|ƒ||ƒ dS )z@ Positions the associated dialog window on the display.
        Nr   g        g      ð?g    ðiø@é   r   g    ðiøÀg      ð¿g    ðiøÀg      ð¿)r@   Úcontrolr7   r   r   ÚposÚintZwindowFlagsr   ZQtÚWindowZmapToGlobalÚxÚyÚwidthÚheightZsizeHintÚlayoutZsizeConstraintr   ZQLayoutZSetFixedSizeZsetSizeConstraintZSetDefaultConstraintÚmoveÚmaxZsetFixedSizeZQSizeZsetGeometry)r   r6   r@   Úwindowr7   ZpxÚpyZpdxZpdyrE   Z	size_hintZ	cur_widthZ
cur_heightrJ   rK   rH   rI   rL   r#   r#   r$   Úpositionæ   sp    








zGUIToolkit.positionc             C   s   ddl m} |j||ƒ dS )z= Shows a help window for a specified UI and control.
        r   )r4   N)r5   r4   Ú	show_help)r   r6   rD   r4   r#   r#   r$   rR   :  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)r5   rS   Úsave_window)r   r6   rS   r#   r#   r$   rT   D  s    zGUIToolkit.save_windowc             C   s,   |j dk	r|jƒ  ||j_|j||jƒ dS )z@ Rebuilds a UI after a change to the content of the UI.
        N)rD   ZrecycleÚinfor6   Zrebuildr7   )r   r6   r#   r#   r$   Ú
rebuild_uiN  s    
zGUIToolkit.rebuild_uic             C   s   |j j|jƒ dS )z+ Sets the title for the UI window.
        N)rD   ZsetWindowTitleÚtitle)r   r6   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_resourcerY   Ú
isinstanceÚiconrD   ZsetWindowIconZcreate_icon)r   r6   rY   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)r5   r]   )r   r"   r]   r#   r#   r$   r]   o  s    zGUIToolkit.key_event_to_namec             C   s0   |dkrdS |dkr,t |d�|_|j|jƒ 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Úkeys)r   )r-   Z_key_event_hookZinstallEventFilter)r   r6   rD   Úeventsr   r#   r#   r$   Úhook_eventsz  s
    zGUIToolkit.hook_eventsc             C   s   |j ƒ  dS )z] Indicates that an event should continue to be processed by the
            toolkit.
        N)Úignore)r   r"   r#   r#   r$   Ú
skip_event�  s    zGUIToolkit.skip_eventc             C   sD   |j dƒ |jƒ  |jƒ  tdkr@tjdk r@ddl}|j|dƒ dS )z3 Destroys a specified GUI toolkit control.
        TÚpyqti r   N)ZblockSignalsZhideÚdeleteLaterr	   r   ZPYQT_VERSIONÚsipZ
transferto)r   rD   re   r#   r#   r$   Údestroy_control—  s    

zGUIToolkit.destroy_controlc             C   s*   x$|j ƒ D ]}t|tjƒr
|jƒ  q
W dS )z\ Destroys all of the child controls of a specified GUI toolkit
            control.
        N)ÚchildrenrZ   r   ZQWidgetrd   )r   rD   Úwr#   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.
        )rJ   rK   )r   Úimager#   r#   r$   Ú
image_size¾  s    zGUIToolkit.image_sizec             C   s   dt jjƒ jt jjƒ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.
        ZWindowColor)r   r   ZpaletteÚcolorZQPaletterG   )r   r#   r#   r$   Ú	constantsÈ  s    	zGUIToolkit.constantsc             O   s   ddl m} |j||ŽS )Nr   )Úcolor_trait)r5   rn   Z	PyQtColor)r   r    ÚtraitsÚctr#   r#   r$   rn   Ø  s    zGUIToolkit.color_traitc             O   s   ddl m} |j||ŽS )Nr   )Úrgb_color_trait)r5   rq   ZRGBColor)r   r    ro   Zrgbctr#   r#   r$   rq   Ü  s    zGUIToolkit.rgb_color_traitc             O   s   ddl m} |j||ŽS )Nr   )Ú
font_trait)r5   rr   ZPyQtFont)r   r    ro   Úftr#   r#   r$   rr   à  s    zGUIToolkit.font_traitc             C   s   ddl m} |jS )Nr   )Ú	ui_editor)r5   rt   ZUIEditor)r   rt   r#   r#   r$   rt   é  s    zGUIToolkit.ui_editorc             O   s   ddl m} |j||ŽS )Nr   )Úarray_editor)r5   ru   ÚToolkitEditorFactory)r   r    ro   Zaer#   r#   r$   ru   ò  s    zGUIToolkit.array_editorc             O   s   ddl m} |j||ŽS )Nr   )Úboolean_editor)r5   rw   rv   )r   r    ro   Úber#   r#   r$   rw   ÷  s    zGUIToolkit.boolean_editorc             O   s   ddl m} |j||ŽS )Nr   )Úbutton_editor)r5   ry   rv   )r   r    ro   rx   r#   r#   r$   ry   ü  s    zGUIToolkit.button_editorc             O   s   ddl m} |j||ŽS )Nr   )Úcheck_list_editor)r5   rz   rv   )r   r    ro   Zcler#   r#   r$   rz     s    zGUIToolkit.check_list_editorc             O   s   ddl m} |j||ŽS )Nr   )Úcode_editor)r5   r{   rv   )r   r    ro   Úcer#   r#   r$   r{     s    zGUIToolkit.code_editorc             O   s   ddl m} |j||ŽS )Nr   )Úcolor_editor)r5   r}   rv   )r   r    ro   r|   r#   r#   r$   r}     s    zGUIToolkit.color_editorc             O   s   ddl m} |j||ŽS )Nr   )Úcompound_editor)r5   r~   rv   )r   r    ro   r|   r#   r#   r$   r~     s    zGUIToolkit.compound_editorc             O   s   ddl m} |j||ŽS )Nr   )Ústyled_date_editor)r5   r   rv   )r   r    ro   Zsder#   r#   r$   r     s    zGUIToolkit.styled_date_editorc             O   s   ddl m} |j||ŽS )Nr   )Úcustom_editor)r5   r€   rv   )r   r    ro   r|   r#   r#   r$   r€     s    zGUIToolkit.custom_editorc             O   s   ddl m} |j||ŽS )Nr   )Údirectory_editor)r5   r�   rv   )r   r    ro   Úder#   r#   r$   r�     s    zGUIToolkit.directory_editorc             O   s   ddl m} |j||ŽS )Nr   )Údrop_editor)r5   rƒ   rv   )r   r    ro   r‚   r#   r#   r$   rƒ   #  s    zGUIToolkit.drop_editorc             O   s   dd l }|j||ŽS )Nr   )Ú
dnd_editorrv   )r   r    ro   Zdndr#   r#   r$   r„   (  s    zGUIToolkit.dnd_editorc             O   s   ddl m} |j||ŽS )Nr   )Úenum_editor)r5   r…   rv   )r   r    ro   Úeer#   r#   r$   r…   -  s    zGUIToolkit.enum_editorc             O   s   ddl m} |j||ŽS )Nr   )Úfile_editor)r5   r‡   rv   )r   r    ro   Úfer#   r#   r$   r‡   2  s    zGUIToolkit.file_editorc             O   s   ddl m} |j||ŽS )Nr   )Úfont_editor)r5   r‰   rv   )r   r    ro   rˆ   r#   r#   r$   r‰   7  s    zGUIToolkit.font_editorc             O   s   ddl m} |j||ŽS )Nr   )Úkey_binding_editor)r5   rŠ   rv   )r   r    ro   Zkber#   r#   r$   rŠ   <  s    zGUIToolkit.key_binding_editorc             O   s   ddl m} |j||ŽS )Nr   )Úhistory_editor)r5   r‹   ZHistoryEditor)r   r    ro   Úher#   r#   r$   r‹   A  s    zGUIToolkit.history_editorc             O   s   ddl m} |j||ŽS )Nr   )Úhtml_editor)r5   r�   rv   )r   r    ro   rŒ   r#   r#   r$   r�   F  s    zGUIToolkit.html_editorc             O   s   ddl m} |j||ŽS )Nr   )Úimage_editor)r5   rŽ   ZImageEditor)r   r    ro   Úier#   r#   r$   rŽ   K  s    zGUIToolkit.image_editorc             O   s   ddl m} |j||ŽS )Nr   )Úimage_enum_editor)r5   r�   rv   )r   r    ro   Zieer#   r#   r$   r�   P  s    zGUIToolkit.image_enum_editorc             O   s   ddl m} |j||ŽS )Nr   )Úinstance_editor)r5   r‘   rv   )r   r    ro   r�   r#   r#   r$   r‘   U  s    zGUIToolkit.instance_editorc             O   s   ddl m} |j||ŽS )Nr   )Úlist_editor)r5   r’   rv   )r   r    ro   Úler#   r#   r$   r’   Z  s    zGUIToolkit.list_editorc             O   s   ddl m} |j||ŽS )Nr   )Úlist_str_editor)r5   r”   ZListStrEditor)r   r    ro   Zlser#   r#   r$   r”   _  s    zGUIToolkit.list_str_editorc             O   s   ddl m} |j||ŽS )Nr   )Únull_editor)r5   r•   rv   )r   r    ro   Úner#   r#   r$   r•   d  s    zGUIToolkit.null_editorc             O   s   dd l }|j||ŽS )Nr   )Úordered_set_editorrv   )r   r    ro   Zoser#   r#   r$   r—   i  s    zGUIToolkit.ordered_set_editorc             O   s   dd l }|j||ŽS )Nr   )Úplot_editorrv   )r   r    ro   Úper#   r#   r$   r˜   n  s    zGUIToolkit.plot_editorc             O   s   ddl m} |j||ŽS )Nr   )Úrange_editor)r5   rš   rv   )r   r    ro   Úrer#   r#   r$   rš   s  s    zGUIToolkit.range_editorc             O   s   ddl m} |j||ŽS )Nr   )Úrgb_color_editor)r5   rœ   rv   )r   r    ro   Zrgbcer#   r#   r$   rœ   x  s    zGUIToolkit.rgb_color_editorc             O   s   ddl m} |j||ŽS )Nr   )Ú
set_editor)r5   r�   rv   )r   r    ro   Úser#   r#   r$   r�   }  s    zGUIToolkit.set_editorc             O   s   ddl m} |j||ŽS )Nr   )Úshell_editor)r5   rŸ   rv   )r   r    ro   rž   r#   r#   r$   rŸ   ‚  s    zGUIToolkit.shell_editorc             O   s   ddl m} |j||ŽS )Nr   )Útable_editor)r5   r    rv   )r   r    ro   Úter#   r#   r$   r    ‡  s    zGUIToolkit.table_editorc             O   s   ddl m} |j||ŽS )Nr   )Útabular_editor)r5   r¢   ZTabularEditor)r   r    ro   r¡   r#   r#   r$   r¢   Œ  s    zGUIToolkit.tabular_editorc             O   s   ddl m} |j||ŽS )Nr   )Útext_editor)r5   r£   rv   )r   r    ro   r¡   r#   r#   r$   r£   ‘  s    zGUIToolkit.text_editorc             O   s   ddl m} |j||ŽS )Nr   )Útitle_editor)r5   r¤   ZTitleEditor)r   r    ro   r¤   r#   r#   r$   r¤   –  s    zGUIToolkit.title_editorc             O   s   ddl m} |j||ŽS )Nr   )Útree_editor)r5   r¥   rv   )r   r    ro   r¡   r#   r#   r$   r¥   ›  s    zGUIToolkit.tree_editorc             O   s   ddl m} |j||ŽS )Nr   )Útuple_editor)r5   r¦   rv   )r   r    ro   r¡   r#   r#   r$   r¦      s    zGUIToolkit.tuple_editorc             O   s   ddl m} |j||ŽS )Nr   )Úvalue_editor)r5   r§   rv   )r   r    ro   Úver#   r#   r$   r§   ¥  s    zGUIToolkit.value_editor)NNr5   NN)NN)Br(   r)   r*   r+   r4   r8   r:   r9   r;   r<   r=   r>   rQ   rR   rT   rV   rX   r\   r]   r`   rb   rf   ri   rk   rm   rn   rq   rr   rt   ru   rw   ry   rz   r{   r}   r~   r   r€   r�   rƒ   r„   r…   r‡   r‰   rŠ   r‹   r�   rŽ   r�   r‘   r’   r”   r•   r—   r˜   rš   rœ   r�   rŸ   r    r¢   r£   r¤   r¥   r¦   r§   r#   r#   r#   r$   r3   „   s€    
(T

	


		r3   N)r+   Ú
__future__r   r   Ztraitsui.toolkitr   Zpyface.toolkitr   Zpyface_toolkitZ_appZtraits.trait_notifiersr   Z	pyface.qtr   r   r	   r
   rm   r   r   r   ÚTypeZregisterEventTyper   r   r   r,   r-   r3   r#   r#   r#   r$   Ú<module>   s   ;