B
    p[                 @   s   d Z ddlmZmZmZ ddlmZ ddlmZm	Z	m
Z
mZ G dd de	ZeG dd	 d	eZd
d ZeG dd deZdd ZdS )z]Link and DirectionalLink classes.

Propagate changes between widgets on the javascript side.
   )Widgetregisterwidget_serialization)
CoreWidget    )UnicodeTupleInstance
TraitErrorc                   s0   e Zd ZdZdZ fddZ fddZ  ZS )WidgetTraitTuplez<Traitlet for validating a single (Widget, 'trait_name') pairzA (Widget, 'trait_name') pairc                s    t t| jttt f| d S )N)superr   __init__r	   r   r   )selfkwargs)	__class__ =lib/python3.7/site-packages/ipywidgets/widgets/widget_link.pyr      s    zWidgetTraitTuple.__init__c                sh   t t| ||}|\}}| |}d|jj|f }|d krNtd| n|dsdtd| |S )Nz%s.%szNo such trait: %ssyncz%s cannot be synced)	r   r   validate_elementsZtraitsgetr   __name__	TypeErrorZget_metadata)r   objvaluewidgetZ
trait_nameZtraitZ
trait_repr)r   r   r   r      s    
z"WidgetTraitTuple.validate_elements)r   
__module____qualname____doc__Z	info_textr   r   __classcell__r   r   )r   r   r      s   r   c                   sl   e Zd ZdZedjddZeddjf ddieZ	eddjf ddieZ
 fd	d
Zdd Z  ZS )LinkzLink Widget

    source: a (Widget, 'trait_name') tuple for the source trait
    target: a (Widget, 'trait_name') tuple that should be updated
    Z	LinkModelT)r   z&The target (widget, 'trait_name') pair)helpr   z&The source (widget, 'trait_name') pairc                s&   ||d< ||d< t t| jf | d S )Nsourcetarget)r   r   r   )r   r!   r"   r   )r   r   r   r   1   s    zLink.__init__c             C   s   |    d S )N)close)r   r   r   r   unlink7   s    zLink.unlink)r   r   r   r   r   tag_model_namer   r   r"   r!   r   r$   r   r   r   )r   r   r   %   s   r   c             C   s
   t | |S )a  Link two widget attributes on the frontend so they remain in sync.

    The link is created in the front-end and does not rely on a roundtrip
    to the backend.

    Parameters
    ----------
    source : a (Widget, 'trait_name') tuple for the first trait
    target : a (Widget, 'trait_name') tuple for the second trait

    Examples
    --------

    >>> c = link((widget1, 'value'), (widget2, 'value'))
    )r   )Zattr1Zattr2r   r   r   jslink;   s    r'   c               @   s    e Zd ZdZedjddZdS )DirectionalLinkzA directional link

    source: a (Widget, 'trait_name') tuple for the source trait
    target: a (Widget, 'trait_name') tuple that should be updated
    when the source trait changes.
    ZDirectionalLinkModelT)r   N)r   r   r   r   r   r%   r&   r   r   r   r   r(   N   s   r(   c             C   s
   t | |S )a  Link a source widget attribute with a target widget attribute.

    The link is created in the front-end and does not rely on a roundtrip
    to the backend.

    Parameters
    ----------
    source : a (Widget, 'trait_name') tuple for the source trait
    target : a (Widget, 'trait_name') tuple for the target trait

    Examples
    --------

    >>> c = dlink((src_widget, 'value'), (tgt_widget, 'value'))
    )r(   )r!   r"   r   r   r   jsdlinkY   s    r)   N)r   r   r   r   r   Zwidget_corer   Z	traitletsr   r   r	   r
   r   r   r'   r(   r)   r   r   r   r   <module>   s   
