o
    ^i|                     @   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                    sB   t  jttt fi | d|vr|ddsd| _d S d S d S )Ndefault_value
allow_noneF )super__init__r	   r   r   getdefault_args)selfkwargs	__class__r   Y/home/ubuntu/hpml_nyu/venv/lib/python3.10/site-packages/ipywidgets/widgets/widget_link.pyr      s   
zWidgetTraitTuple.__init__c                    sd   t  ||}|\}}| |}d|jj|}|d u r$td| |jds0td| |S )Nz{}.{}zNo such trait: %ssyncz%s cannot be synced)	r   validate_elementstraitsr   formatr   __name__	TypeErrormetadata)r   objvaluewidget
trait_nametrait
trait_reprr   r   r   r      s   z"WidgetTraitTuple.validate_elements)r   
__module____qualname____doc__	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dddieZ	eddjd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
    	LinkModelTr   z&The target (widget, 'trait_name') pair)helpr   z&The source (widget, 'trait_name') pairc                    s&   ||d< ||d< t  jdi | d S )Nsourcetargetr   )r   r   )r   r.   r/   r   r   r   r   r   7   s   zLink.__init__c                 C   s   |    d S )N)close)r   r   r   r   unlink=   s   zLink.unlinkr   )r   r%   r&   r'   r   tag_model_namer   r   r/   r.   r   r1   r)   r   r   r   r   r*   +   s    r*   c                 C   
   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*   )attr1attr2r   r   r   jslinkA      
r7   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.
    DirectionalLinkModelTr,   N)r   r%   r&   r'   r   r2   r3   r   r   r   r   r9   T   s    r9   c                 C   r4   )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'))
    )r9   )r.   r/   r   r   r   jsdlink_   r8   r;   N)r'   r!   r   r   r   widget_corer   	traitletsr   r   r	   r
   r   r*   r7   r9   r;   r   r   r   r   <module>   s   
