3
8Ad]Ž2  ã               @   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
mZmZmZ ddlmZmZmZmZmZmZ ddlmZ edeƒ d�ZG d	d
„ d
eƒZG dd„ deƒZdS )z° Defines KeyBinding and KeyBindings classes, which manage the mapping of
    keystroke events into method calls on controller objects that are supplied
    by the application.
é    )Úabsolute_import)
ÚAnyÚEventÚHasPrivateTraitsÚHasStrictTraitsÚInstanceÚListÚPropertyÚStrÚcached_propertyÚon_trait_changeé   )ÚHGroupÚItemÚKeyBindingEditorÚ
ListEditorÚViewÚtoolkit)ÚSequenceTypesÚbinding)ÚeventÚeditorc               @   sT   e Zd ZdZeZeZeZeZ	e
dƒZeeedƒedƒeddd�dd	�ƒZd
d„ ZdS )Ú
KeyBindingz. Binds one or two keystrokes to a method.
    ÚKeyBindingsÚbinding1Úbinding2ÚdescriptionÚreadonly)ÚstyleF)Zshow_labelsc             C   s   | j d k	r| | j _d S )N)ÚownerÚbinding_modified)Úself© r"   úq/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/traitsui-6.1.2-py3.6.egg/traitsui/key_bindings.pyÚ_binding_changeda   s    
zKeyBinding._binding_changedN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚBindingr   r   r
   r   Úmethod_namer   r   r   r   r   Útraits_viewr$   r"   r"   r"   r#   r   9   s   

r   c                   s  e Zd ZdZeeƒZeZeZ	edd�Z
ed dd�Zedd�Zedd�ZeeƒZedd�Zeedddedd	�d
�dgdddddd�Z‡ fdd„Zg fdd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZ d d!„ Z!d"d#„ Z"e#d$ƒd%d&„ ƒZ$d'd(„ Z%d)d*„ Z&d+d,„ Z'‡  Z(S )-r   z A set of key bindings.
    T)Z	transientÚparent)Z
depends_onÚbindingsZcustomF)r   )r   Z
show_labelr   z]|{Click on an entry field, then press the key to assign. Double-click a field to clear it.}<>zUpdate Key BindingsZ	livemodalgš™™™™™Ù?)ÚtitleÚkindZ	resizableÚwidthÚheightc                sl   t tˆ ƒjf |Ž t|ƒdkr4t|d tƒr4|d }t|ƒ}ˆ jdtt||dd�ƒ ‡ fdd„|D ƒˆ _	d S )Nr   r   r-   Úlist)ÚminlenÚmaxlenÚmodec                s   g | ]}|j ˆ d �‘qS ))r   )Ú	trait_set)Ú.0r   )r!   r"   r#   ú
<listcomp>®   s    z(KeyBindings.__init__.<locals>.<listcomp>)
Úsuperr   Ú__init__ÚlenÚ
isinstancer   Ú	add_traitr   r   r-   )r!   r-   ÚtraitsÚn)Ú	__class__)r!   r#   r:   ¤   s    
zKeyBindings.__init__c             O   sR   t |tƒrt|jƒ ƒ}nt |tƒs*|g}nt|ƒ}| jtƒ j|ƒ|||jddƒƒS )z% Processes a keyboard event.
        Ú	recursiveF)	r<   Údictr2   Úvaluesr   Ú_dor   Zkey_event_to_nameÚget)r!   r   ÚcontrollersÚargsÚkwr"   r"   r#   Údo´   s    

zKeyBindings.doc             C   sV   i }x| j D ]}|||j< qW x2|j D ](}|j|jƒ}|dk	r&|j|_|j|_q&W dS )z; Merges another set of key bindings into this set.
        N)r-   r*   rE   r   r   )r!   Zkey_bindingsZbinding_dicr   r   r"   r"   r#   ÚmergeÅ   s    zKeyBindings.mergec             K   s   | j | j|Žjf | jddƒŽS )z4 Returns a clone of the KeyBindings object.
        ÚprefixÚsuffix)r@   r-   r6   rE   )r!   r>   r"   r"   r#   ÚcloneÖ   s    zKeyBindings.clonec             C   s:   | j dk	r| j jj| ƒ | `| `| `d | _  | _| _dS )z  Dispose of the object.
        N)r,   ÚchildrenÚremoverF   r-   Ú_rootÚfocus_owner)r!   r"   r"   r#   Údisposeà   s    
zKeyBindings.disposec             C   s4   t t| jjg ƒƒƒ}|jdd„ d� t|ƒjƒ  dS )z; Edits a possibly hierarchical set of KeyBindings.
        c             S   s   d| j dd … | j f S )Nz%s%02dr   éÿÿÿÿ)r   )Úxr"   r"   r#   Ú<lambda>ô   s    z"KeyBindings.edit.<locals>.<lambda>)ÚkeyN)r2   ÚsetÚrootÚ_get_bindingsÚsortr   Zedit_traits)r!   r-   r"   r"   r#   Úeditð   s    zKeyBindings.editc             C   s<   |dkr8x.| j D ]$}||k	r||jks0||jkr|S qW dS )zC Returns the current binding for a specified key (if any).
        Ú N)r-   r   r   )r!   r   Úkey_nameÚ	a_bindingr"   r"   r#   Úkey_binding_forû   s    

zKeyBindings.key_binding_forc             C   s   | }x|j d k	r|j }qW |S )N)r,   )r!   rX   r"   r"   r#   Ú	_get_root	  s    
zKeyBindings._get_rootc             C   sh   |j }|j}xV| jD ]L}||k	r||j kr0d|_ ||jkr@d|_||j krPd|_ ||jkrd|_qW dS )z* Handles a binding being changed.
        r\   N)r   r   r-   )r!   r   r   r   r^   r"   r"   r#   Ú_binding_modified_changed  s    



z%KeyBindings._binding_modified_changedc             C   s   |dk	rd|_ dS )z0 Handles the focus owner being changed.
        Nr   )Zborder_size)r!   ÚoldÚnewr"   r"   r#   Ú_focus_owner_changed#  s    z KeyBindings._focus_owner_changedz
children[]c             C   s   x|D ]
}| |_ qW dS )z> Handles child KeyBindings being added to the object.
        N)r,   )r!   ÚremovedÚaddedÚitemr"   r"   r#   Ú_children_modified)  s    
zKeyBindings._children_modifiedc             C   sB   t |d ƒ}| jdtt||d�ƒ | jj|ƒ | jdd… | _dS )z< Restores the state of a previously pickled object.
        r-   )r3   r4   N)r;   r=   r   r   Ú__dict__Úupdater-   )r!   Ústater?   r"   r"   r#   Ú__setstate__6  s    zKeyBindings.__setstate__c             C   s*   |j | jƒ x| jD ]}|j|ƒ qW |S )zM Returns all of the bindings of this object and all of its children.
        )Úextendr-   rN   rY   )r!   r-   Úchildr"   r"   r#   rY   @  s    zKeyBindings._get_bindingsc             C   s¶   xˆ| j D ]~}||jks ||jkrd| j|j| jf }x:|| j D ],}t||dƒ}|dk	r@||Ž }	|	dk	r@dS q@W |jdkr| jƒ  dS qW |r²x"| j	D ]}
|
j
||||ƒr–dS q–W dS )z‰ Process the specified key for the specified set of controllers for
            this KeyBindings object and all of its children.
        z%s%s%sNFTZedit_bindings)r-   r   r   rK   r*   rL   rF   Úgetattrr[   rN   rD   )r!   r]   rF   rG   rA   r   r*   Z
controllerÚmethodÚresultrn   r"   r"   r#   rD   I  s&    


zKeyBindings._do))r%   r&   r'   r(   r   r   r-   r
   rK   rL   rF   r   r,   r	   rX   rN   r   r    r   rQ   r   r   r   r+   r:   rI   rJ   rM   rR   r[   r_   r   r`   ra   rd   r   rh   rl   rY   rD   Ú__classcell__r"   r"   )r@   r#   r   j   sD   






	r   N)r(   Ú
__future__r   Z
traits.apir   r   r   r   r   r   r	   r
   r   r   Zapir   r   r   r   r   r   Ztraits.trait_baser   r)   r   r   r"   r"   r"   r#   Ú<module>   s   0 1