
    ztft                        d dl mZ d dlmZmZmZmZ d dlmZ ddl	m
Z
mZmZ erd dlmZ  ed      Z ed      Z G d	 d
e      Z G d dee         Z G d dee         Zy)    )annotations)TYPE_CHECKINGAny	ContainerTypeVar)Signal   )BailTypeEventedOrderedSet	SetEvents)Iterable_T_Sc                  0    e Zd ZdZ ee      Z ee      Zy)SelectionEventsa  Events available on [Selection][psygnal.containers.Selection].

    Attributes
    ----------
    items_changed (added: Tuple[_T], removed: Tuple[_T])
        A signal that will emitted whenever an item or items are added or removed.
        Connected callbacks will be called with `callback(added, removed)`, where
        `added` and `removed` are tuples containing the objects that have been
        added or removed from the set.
    active (value: _T)
        Emitted when the active item has changed. An active item is a single selected
        item.
    _current (value: _T)
        Emitted when the current item has changed. (Private event)
    N)__name__
__module____qualname____doc__r   objectactive_current     g/var/www/html/software/conda/envs/higlass/lib/python3.12/site-packages/psygnal/containers/_selection.pyr   r      s      F^Ff~Hr   r   c                       e Zd ZU dZded<   dd fdZedd       Zej                  dd       Zedd       Z	e	j                  dd       Z	dd fd	Z
dd
ZddZddZddZd fdZd fdZddZ xZS )	Selectiona  An model of selected items, with a `active` and `current` item.

    There can only be one `active` and one `current` item, but there can be
    multiple selected items.  An "active" item is defined as a single selected
    item (if multiple items are selected, there is no active item).  The
    "current" item is mostly useful for (e.g.) keyboard actions: even with
    multiple items selected, you may only have one current item, and keyboard
    events (like up and down) can modify that current item.  It's possible to
    have a current item without an active item, but an active item will always
    be the current item.

    An item can be the current item and selected at the same time. Qt views
    will ensure that there is always a current item as keyboard navigation,
    for example, requires a current item.
    This pattern mimics current/selected items from Qt:
    https://doc.qt.io/qt-5/model-view-programming.html#current-item-and-selected-items

    Parameters
    ----------
    data : iterable, optional
        Elements to initialize the set with.
    parent : Container, optional
        The parent container, if any. This is used to provide validation upon
        mutation in common use cases.

    Attributes
    ----------
    events : SelectionEvents
        SignalGroup that with events related to selection changes. (see SelectionEvents)
    active : Any, optional
        The active item, if any. An "active" item is defined as a single selected
        item (if multiple items are selected, there is no active item)
    _current : Any, optional
        The current item, if any. This is used primarily by GUI views when
        handling mouse/key events.
    r   eventsc                p    d | _         d | _        || _        t        |   |       | j                          y )N)iterable)_active	_current__parentsuper__init___update_active)selfdataparent	__class__s      r   r%   zSelection.__init__M   s4    "&$()/$'r   c                    | j                   S )zGet current item.)r"   r'   s    r   r   zSelection._currentT   s     ~~r   c                |    || j                   k(  ry|| _         | j                  j                  j                  |       y)zSet current item.N)r"   r   r   emitr'   values     r   r   zSelection._currentY   s2     DNN"!!%(r   c                    | j                   S )z)Return the currently active item or None.)r!   r,   s    r   r   zSelection.activea   s     ||r   c                    || j                   k(  ry|| _         || j                         n| j                  |       || _        | j                  j
                  j                  |       y)zgSet the active item.

        This makes `value` the only selected item, and makes it current.
        N)r!   clearselect_onlyr   r   r   r.   r/   s     r   r   zSelection.activef   sT     DLL 

4+;+;E+B&r   c                4    |sd| _         t        | 	          y)zClear the selection.

        Parameters
        ----------
        keep_current : bool
            If `False` (the default), the "current" item will also be set to None.
        N)r   r$   r3   )r'   keep_currentr*   s     r   r3   zSelection.clears   s      DMr   c                (    | j                  |h       y)zToggle selection state of obj.N)symmetric_difference_updater'   objs     r   togglezSelection.toggle   s    ((#/r   c                J    | j                  |h       | j                  |       y)zJUnselect everything but `obj`. Add to selection if not currently selected.N)intersection_updateaddr9   s     r   r4   zSelection.select_only   s      #'r   c                    t        |       dk(  rt        t        |             | _        y| j                  -d| _        | j
                  j                  j                  d       yy)z|On a selection event, update the active item based on selection.

        An active item is a single selected item.
        r	   N)lennextiterr   r!   r   r.   r,   s    r   r&   zSelection._update_active   sM    
 t9>tDz*DK\\%DLKK##D) &r   c                    t               S )z(Override SetEvents with SelectionEvents.)r   r,   s    r   _get_events_classzSelection._get_events_class   s      r   c                F    t         |   ||       | j                          y)zEmit a change event.N)r$   _emit_changer&   )r'   addedremovedr*   s      r   rF   zSelection._emit_change   s    UG,r   c                l    | j                   || j                   vrt        d      t        |   |      S )Nz:Cannot select an item that is not in the parent container.)r#   
ValueErrorr$   _pre_add_hook)r'   itemr*   s     r   rK   zSelection._pre_add_hook   s:    <<#DLL(@L  w$T**r   c                    t        |       S )zMake selection hashable.)idr,   s    r   __hash__zSelection.__hash__   s    $xr   )r   N)r(   zIterable[_T]r)   zContainer | None)return	_T | None)r0   rQ   rP   None)F)r6   boolrP   rR   )r:   r   rP   rR   )rP   rR   )rP   r   )rG   tuple[_T, ...]rH   rT   rP   rR   )rL   r   rP   z_T | BailType)rP   int)r   r   r   r   __annotations__r%   propertyr   setterr   r3   r;   r4   r&   rD   rF   rK   rO   __classcell__r*   s   @r   r   r   %   s    #J    __) )   ]]
' 
'
0
	*!
+r   r   c                  \     e Zd ZdZd fdZedd       Zej                  dd       Z xZS )
Selectablez1Mixin that adds a selection model to a container.c                F    t        |       | _        t        |   |i | y )N)r)   )r   
_selectionr$   r%   )r'   argskwargsr*   s      r   r%   zSelectable.__init__   s!    )2$)?$)&)r   c                    | j                   S )zGet current selection.)r^   r,   s    r   	selectionzSelectable.selection   s     r   c                p    | j                   j                  |       | j                   j                  |       y)z7Set selection, without deleting selection model object.N)r^   r=   update)r'   new_selections     r   rb   zSelectable.selection   s(     	++M:}-r   )r_   r   r`   r   rP   rR   )rP   zSelection[_S])re   zIterable[_S]rP   rR   )	r   r   r   r   r%   rW   rb   rX   rY   rZ   s   @r   r\   r\      s9    ;*   . .r   r\   N)
__future__r   typingr   r   r   r   psygnal._signalr   _evented_setr
   r   r   r   r   r   r   r   r\   r   r   r   <module>rj      s`    " 9 9 " @ @T]T]i *@!"% @F.2 .r   