
    jj=                        d dl mZ d dlZd dlmZmZ d dlmZ ddlm	Z	m
Z
 ddlmZ  ej                  d      Z G d	 d
e	      Z G d d e
d      ee         Zy)    )annotationsN)HashableMapping)CompositeCanvas   )WidgetErrordelegate_to_widget_mixin)WidgetDecorationWrappedWidgetc                      e Zd Zy)AttrMapErrorN)__name__
__module____qualname__     ^/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/urwid/widget/attr_map.pyr   r      s    r   r   c                       e Zd ZdZ	 d		 	 	 	 	 	 	 d
 fdZd fdZddZddZ eee      Z	ddZ
ddZ ee
e      ZdddZ xZS )AttrMapz
    AttrMap is a decoration that maps one set of attributes to another.
    This object will pass all function calls and variable references to the
    wrapped widget.
    c                    t         |   |       t        |t              rt	        |      | _        n	d|i| _        t        |t              rt	        |      | _        y||| _        yd|i| _        y)a  
        :param w: widget to wrap (stored as self.original_widget)
        :type w: widget

        :param attr_map: attribute to apply to *w*, or dict of old display
            attribute: new display attribute mappings
        :type attr_map: display attribute or dict

        :param focus_map: attribute to apply when in focus or dict of
            old display attribute: new display attribute mappings;
            if ``None`` use *attr*
        :type focus_map: display attribute or dict

        >>> from urwid import Divider, Edit, Text
        >>> AttrMap(Divider("!"), "bright")
        <AttrMap flow widget <Divider flow widget '!'> attr_map={None: 'bright'}>
        >>> AttrMap(Edit(), "notfocus", "focus").attr_map
        {None: 'notfocus'}
        >>> AttrMap(Edit(), "notfocus", "focus").focus_map
        {None: 'focus'}
        >>> size = (5,)
        >>> am = AttrMap(Text("hi"), "greeting", "fgreet")
        >>> next(am.render(size, focus=False).content())  # ... = b in Python 3
        [('greeting', None, ...'hi   ')]
        >>> next(am.render(size, focus=True).content())
        [('fgreet', None, ...'hi   ')]
        >>> am2 = AttrMap(Text(("word", "hi")), {"word": "greeting", None: "bg"})
        >>> am2
        <AttrMap fixed/flow widget <Text fixed/flow widget 'hi'> attr_map={'word': 'greeting', None: 'bg'}>
        >>> next(am2.render(size).content())
        [('greeting', None, ...'hi'), ('bg', None, ...'   ')]
        N)super__init__
isinstancer   dictattr_map	focus_map)selfwr   r   	__class__s       r   r   zAttrMap.__init__   sb    L 	h( NDM!8,DMi)!)_DN&DN"I.DNr   c                z    i t         |          d| j                  i}| j                  | j                  |d<   |S )Nr   r   )r   _repr_attrs	_attr_map
_focus_map)r   dr   s     r   r!   zAttrMap._repr_attrsM   s<    Auw"$Aj$..A??&!__AkNr   c                ,    t        | j                        S N)r   r"   r   s    r   get_attr_mapzAttrMap.get_attr_mapT   s     DNN##r   c                    |j                         D ]6  \  }}t        |t              rt        |t              r't        |d|d       || _        | j                          y)a  
        Set the attribute mapping dictionary {from_attr: to_attr, ...}

        Note this function does not accept a single attribute the way the
        constructor does.  You must specify {None: attribute} instead.

        >>> from urwid import Text
        >>> w = AttrMap(Text("hi"), None)
        >>> w.set_attr_map({"a": "b"})
        >>> w
        <AttrMap fixed/flow widget <Text fixed/flow widget 'hi'> attr_map={'a': 'b'}>
        :: attribute mapping is invalid. Attributes must be hashableN)itemsr   r   r   r"   _invalidate)r   r   	from_attrto_attrs       r   set_attr_mapzAttrMap.set_attr_mapY   se     #+.."2 	Iwi2*Wh:W" m1WK/ij 	 "r   c                F    | j                   rt        | j                         S y r&   )r#   r   r'   s    r   get_focus_mapzAttrMap.get_focus_mapq   s     ??((r   c                    |I|j                         D ]6  \  }}t        |t              rt        |t              r't        |d|d       || _        | j                          y)a  
        Set the focus attribute mapping dictionary
        {from_attr: to_attr, ...}

        If None this widget will use the attr mapping instead (no change
        when in focus).

        Note this function does not accept a single attribute the way the
        constructor does.  You must specify {None: attribute} instead.

        >>> from urwid import Text
        >>> w = AttrMap(Text("hi"), {})
        >>> w.set_focus_map({"a": "b"})
        >>> w
        <AttrMap fixed/flow widget <Text fixed/flow widget 'hi'> attr_map={} focus_map={'a': 'b'}>
        >>> w.set_focus_map(None)
        >>> w
        <AttrMap fixed/flow widget <Text fixed/flow widget 'hi'> attr_map={}>
        Nr*   r+   )r,   r   r   r   r#   r-   )r   r   r.   r/   s       r   set_focus_mapzAttrMap.set_focus_mapx   sl    (  &/oo&7 "	7!)X6jRZ>[&$-q3mn 
 $r   c                    | j                   }|r| j                  | j                  }| j                  j                  ||      }t	        |      }|j                  |       |S )zK
        Render wrapped widget and apply attribute. Return canvas.
        )focus)r"   r#   _original_widgetrenderr   fill_attr_apply)r   sizer6   r   canvs        r   r8   zAttrMap.render   sZ     >>T__0H$$++D+>t$X&r   r&   )r   r   r   4Hashable | Mapping[Hashable | None, Hashable] | Noner   r<   returnNone)r=   zdict[str, typing.Any])r=   zdict[Hashable | None, Hashable])r   &dict[Hashable | None, Hashable] | Noner=   r>   )r=   r?   )r   r?   r=   r>   )F)r6   boolr=   r   )r   r   r   __doc__r   r!   r(   r0   propertyr   r2   r4   r   r8   __classcell__)r   s   @r   r   r      s|     KO	2/2/ G2/ H	2/
 
2/h$
, l3H: 6I
 
r   r   r7   )
__future__r   typingcollections.abcr   r   urwid.canvasr   widgetr   r	   widget_decorationr
   TypeVarr   r   r   r   r   r   <module>rK      sP    "  - ( 9 //	; 	O&'9:<L]<[ Or   