o
    tf|                     @   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   getZdefault_args)selfkwargs	__class__r   g/var/www/html/software/conda/envs/catlas/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_elementsZtraitsr   formatr   __name__	TypeErrormetadata)r   objvaluewidgetZ
trait_nameZtraitZ
trait_reprr   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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
    Z	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   r*   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$   )Zattr1Zattr2r   r   r   jslinkA      
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DirectionalLinkModelTr%   N)r   r    r!   r"   r   r+   r,   r   r   r   r   r0   T   s    r0   c                 C   r-   )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'))
    )r0   )r'   r(   r   r   r   jsdlink_   r/   r1   N)r"   r   r   r   r   Zwidget_corer   Z	traitletsr   r   r	   r
   r   r$   r.   r0   r1   r   r   r   r   <module>   s   
