3
7ßL]ª  ã               @   sd   d Z ddlmZmZmZmZ ddlmZmZm	Z	m
Z
 ddlmZ G dd„ deƒZG dd„ deƒZd	S )
z The text field interface. é    )Úabsolute_importÚdivisionÚprint_functionÚunicode_literals)ÚAnyÚ	HasTraitsÚInstanceÚUnicode)ÚIWidgetc               @   s0   e Zd ZdZeZeZedƒZ	dd„ Z
dd„ ZdS )ÚIFieldz‚ The field interface.

    A field is a widget that displays a value and (potentially) allows a user
    to interact with it.
    z&pyface.action.menu_manager.MenuManagerc             C   s   dS )z1 Create and show the context menu at a position. N© )ÚselfÚxÚyr   r   ú9/tmp/pip-install-5sebvq2j/pyface/pyface/fields/i_field.pyÚshow_context_menu)   s    zIField.show_context_menuc             C   s   dS )z> Perform any toolkit-specific initialization for the control. Nr   )r   Úcontrolr   r   r   Ú_initialize_control,   s    zIField._initialize_controlN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úvaluer	   Útooltipr   Úcontext_menur   r   r   r   r   r   r      s   r   c                   s°   e Zd ZdZeZeZedƒZ	‡ fdd„Z
‡ f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d„Zdd„ Zdd„ Zd d!„ Zd"d#„ Z‡  ZS )&ÚMFieldz The field mix-in. z&pyface.action.menu_manager.MenuManagerc                sd   t t| ƒjƒ  | j| jddd� | j| jddd� | j| jddd� | jdk	r`| jdk	r`| j	ƒ  dS )z- Set up toolkit-specific bindings for events r   Úui)Údispatchr   r   N)
Úsuperr   Ú_add_event_listenersÚon_trait_changeÚ_value_updatedÚ_tooltip_updatedÚ_context_menu_updatedr   r   Ú_observe_control_context_menu)r   )Ú	__class__r   r   r   @   s    
zMField._add_event_listenersc                sn   | j dk	r | jdk	r | jdd� | j| jdddd� | j| jdddd� | j| jdddd� tt| ƒj	ƒ  dS )	z- Remove toolkit-specific bindings for events NT)Úremover   r   )r   r&   r   r   )
r   r   r$   r    r!   r"   r#   r   r   Ú_remove_event_listeners)r   )r%   r   r   r'   J   s    

zMField._remove_event_listenersc             C   s:   | j | jƒ| _| jƒ  | jƒ  | j| jƒ | j| jƒ dS )z— Creates the toolkit specific control.

        This method should create the control and assign it to the
        :py:attr:``control`` trait.
        N)	Z_create_controlÚparentr   r   r   ÚshowZvisibleÚenableZenabled)r   r   r   r   Ú_createZ   s
    zMField._createc             C   s   | j | jƒ dS )z> Perform any toolkit-specific initialization for the control. N)Ú_set_control_tooltipr   )r   r   r   r   r   g   s    zMField._initialize_controlc             C   s   | j ƒ | _dS )z‰ Handle a change to the value from user interaction

        This is a method suitable for calling from a toolkit event handler.
        N)Ú_get_control_valuer   )r   r   r   r   r   Ú_update_valuek   s    zMField._update_valuec             C   s   | j }|dkrtdƒ‚|S )z; If control is not passed directly, get it from the trait. NzToolkit control does not exist.)r   ÚRuntimeError)r   r   r   r   r   Ú_get_controlr   s    zMField._get_controlc             C   s   t ‚dS )z5 Toolkit specific method to get the control's value. N)ÚNotImplementedError)r   r   r   r   r-   {   s    zMField._get_control_valuec             C   s   t ‚dS )z5 Toolkit specific method to set the control's value. N)r1   )r   r   r   r   r   Ú_set_control_value   s    zMField._set_control_valueFc             C   s   t ‚dS )z? Toolkit specific method to change the control value observer. N)r1   )r   r&   r   r   r   Ú_observe_control_valueƒ   s    zMField._observe_control_valuec             C   s   t ‚dS )z7 Toolkit specific method to get the control's tooltip. N)r1   )r   r   r   r   Ú_get_control_tooltip‡   s    zMField._get_control_tooltipc             C   s   t ‚dS )z7 Toolkit specific method to set the control's tooltip. N)r1   )r   r   r   r   r   r,   ‹   s    zMField._set_control_tooltipc             C   s   t ‚dS )z’ Toolkit specific method to change the control menu observer.

        This should use _handle_control_context_menu as the event handler.
        N)r1   )r   r&   r   r   r   r$   �   s    z$MField._observe_control_context_menuc             C   s   t ‚dS )zÑ Handle a context menu event.

        This should call show_context_menu with appropriate position x and y
        arguments.

        The function signature will likely vary from toolkit to toolkit.
        N)r1   )r   Úeventr   r   r   Ú_handle_control_context_menu–   s    z#MField._handle_control_context_menuc             C   s   | j d k	r| j|ƒ d S )N)r   r2   )r   r   r   r   r   r!   ¢   s    
zMField._value_updatedc             C   s   | j d k	r| j|ƒ d S )N)r   r,   )r   r   r   r   r   r"   ¦   s    
zMField._tooltip_updatedc             C   s2   | j d k	r.|d kr| jdd� |d kr.| jƒ  d S )NT)r&   )r   r$   )r   ÚoldÚnewr   r   r   r#   ª   s
    
zMField._context_menu_updated)F)F)r   r   r   r   r   r   r	   r   r   r   r   r'   r+   r   r.   r0   r-   r2   r3   r4   r,   r$   r6   r!   r"   r#   Ú__classcell__r   r   )r%   r   r   0   s(   
	

r   N)r   Ú
__future__r   r   r   r   Z
traits.apir   r   r   r	   Zpyface.i_widgetr
   r   r   r   r   r   r   Ú<module>   s
   