
    jjS              
         d dl mZ d dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZ ddlmZmZ dd	lmZ dd
lmZ ddlmZmZ ej.                  rd dlmZ d dlmZ  ej6                  d      Z ej6                  d      Z ej6                  d      Z G d de      ZddZ  G d deeejB                  eeef         Z"y)    )annotationsN)MutableMapping)CanvasCombineCompositeCanvas)remove_defaults)is_mouse_press   )SizingVAlign)WidgetContainerMixin)Filler)WidgetWidgetError)Iterator)Literal
BodyWidgetHeaderWidgetFooterWidgetc                      e Zd Zy)
FrameErrorN)__name__
__module____qualname__     [/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/urwid/widget/frame.pyr   r      s    r   r   c                    | y t        | t              sO| j                  j                   d| j                  j                   }t        j                  | dt        d       y y )N.z is not subclass of Widget   
stacklevel)
isinstancer   	__class__r   r   warningswarnDeprecationWarning)widgetobj_class_paths     r   _check_widget_subclassr)      sa    ~ff%",,778&:J:J:S:S9TU89	
 &r   c                  N    e Zd ZdZdZ eej                  g      Z	 	 	 d*	 	 	 	 	 	 	 d+ fdZ	d, fdZ
d-dZed.d       Zej                  d/d       Zd.dZd/d	Zed0d
       Zej                  d1d       Zd0dZd1dZed2d       Zej                  d3d       Zd2dZd3dZed4d       Zej                  d5d       Zd4dZd5dZed6d       Ze	 	 d7d       Zd8dZej<                  d9d       Zej<                  d:d       Zej<                  d;d       Z	 	 	 	 d<dZej<                  d=d       Z ej<                  d>d       Z ej<                  d?d       Z 	 	 	 	 	 	 d@d Z dAd!Z!dBd"Z"dCd#Z#	 dD	 	 	 	 	 dEd$Z$	 	 	 	 	 	 dFd%Z%	 	 	 	 	 	 	 	 	 	 	 	 	 	 dGd&Z&dHd'Z'dId(Z(dJd)Z) xZ*S )KFrameax  
    Frame widget is a box widget with optional header and footer
    flow widgets placed above and below the box widget.

    .. note:: The main difference between a Frame and a :class:`Pile` widget
        defined as: `Pile([('pack', header), body, ('pack', footer)])` is that
        the Frame will not automatically change focus up and down in response to keystrokes.
    Tc                   t         |           || _        || _        || _        |dv r|| _        n5||k(  rd| _        n(||k(  rd| _        n||k(  rd| _        nt        d|      t        |       t        |       t        |       y)a~  
        :param body: a box widget for the body of the frame
        :type body: Widget
        :param header: a flow widget for above the body (or None)
        :type header: Widget
        :param footer: a flow widget for below the body (or None)
        :type footer: Widget
        :param focus_part:  'header', 'footer' or 'body'
        :type focus_part: str | Widget
        >   bodyfooterheaderr/   r.   r-   zInvalid focus part N)super__init___header_body_footer
focus_part
ValueErrorr)   )selfr-   r/   r.   r5   r#   s        r   r1   zFrame.__init__9   s    " 	
55(DO6!&DO6!&DO4$DO2:.ABBv&t$v&r   c                    i t         |          | j                  | j                  | j                  | j
                  d}t        |t        j                        S )N)r-   r/   r.   r5   )	r0   _repr_attrsr3   r2   r4   r5   r   r+   r1   )r7   attrsr#   s     r   r9   zFrame._repr_attrs^   sN    
g!#
JJllll//
 uenn55r   c              #     K   d| j                   f d| j                  f d| j                  f d| j                  f y w)Nr-   r/   r.   r5   )r3   r2   r4   r5   r7   s    r   __rich_repr__zFrame.__rich_repr__h   sB     djj  $$$$DOO++s   AAc                    | j                   S N)r2   r<   s    r   r/   zFrame.headern       ||r   c                x    t        |       || _        || j                  dk(  rd| _        | j                          y )Nr/   r-   )r)   r2   r5   _invalidater7   r/   s     r   r/   zFrame.headerr   4    v&>doo9$DOr   c                    t        j                  d| j                  j                   d| j                  j                   dt        d       | j
                  S )Nmethod `z/.get_header` is deprecated, standard property `C.header` should be used instead.API will be removed in version 5.0.   r    r$   r%   r#   r   r&   r/   r<   s    r   
get_headerzFrame.get_headerz   S    t~~../ 0""&.."9"9!: ;22 	
 {{r   c                    t        j                  d| j                  j                   d| j                  j                   dt        d       || _        y )NrF   z/.set_header` is deprecated, standard property `rG   rH   r    rI   rC   s     r   
set_headerzFrame.set_header   P    t~~../ 0""&.."9"9!: ;22 	
 r   c                    | j                   S r?   )r3   r<   s    r   r-   z
Frame.body   s    zzr   c                H    t        |       || _        | j                          y r?   )r)   r3   rB   r7   r-   s     r   r-   z
Frame.body   s    t$
r   c                    t        j                  d| j                  j                   d| j                  j                   dt        d       | j
                  S )NrF   z,.get_body` is deprecated, standard property z@.body should be used instead.API will be removed in version 5.0.rH   r    r$   r%   r#   r   r&   r-   r<   s    r   get_bodyzFrame.get_body   sS    t~~../ 0!!%!8!8 9 :22 	
 yyr   c                    t        j                  d| j                  j                   d| j                  j                   dt        d       || _        y )NrF   z-.set_body` is deprecated, standard property `zA.body` should be used instead.API will be removed in version 5.0.rH   r    rS   rQ   s     r   set_bodyzFrame.set_body   sP    t~~../ 0""&.."9"9!: ;22 	
 	r   c                    | j                   S r?   )r4   r<   s    r   r.   zFrame.footer   r@   r   c                x    t        |       || _        || j                  dk(  rd| _        | j                          y )Nr.   r-   )r)   r4   r5   rB   r7   r.   s     r   r.   zFrame.footer   rD   r   c                    t        j                  d| j                  j                   d| j                  j                   dt        d       | j
                  S )NrF   z/.get_footer` is deprecated, standard property `C.footer` should be used instead.API will be removed in version 5.0.rH   r    r$   r%   r#   r   r&   r.   r<   s    r   
get_footerzFrame.get_footer   rK   r   c                    t        j                  d| j                  j                   d| j                  j                   dt        d       || _        y )NrF   z/.set_footer` is deprecated, standard property `r[   rH   r    r\   rY   s     r   
set_footerzFrame.set_footer   rN   r   c                    | j                   S )z
        writeable property containing an indicator which part of the frame
        that is in focus: `'body', 'header'` or `'footer'`.

        :returns: one of 'header', 'footer' or 'body'.
        :rtype: str
        )r5   r<   s    r   focus_positionzFrame.focus_position   s     r   c                    |dvrt        d|       |dk(  r| j                  |dk(  r| j                  t        d|       || _        | j	                          y)z
        Determine which part of the frame is in focus.

        :param part: 'header', 'footer' or 'body'
        :type part: str
        >   r-   r.   r/   zInvalid position for Frame: r/   Nr.   zThis Frame has no )
IndexErrorr2   r4   r5   rB   r7   parts     r   ra   zFrame.focus_position   sj     33;D6BCCH!548;KPTP\P\Pd1$899r   c                R    t        j                  dt        d       | j                  S )ay  
        writeable property containing an indicator which part of the frame
        that is in focus: `'body', 'header'` or `'footer'`.

        .. note:: included for backwards compatibility. You should rather use
            the container property :attr:`.focus_position` to get this value.

        :returns: one of 'header', 'footer' or 'body'.
        :rtype: str
        zincluded for backwards compatibility.You should rather use the container property `.focus_position` to get this value.API will be removed in version 5.0.rH   r    r$   r%   r&   ra   r<   s    r   	get_focuszFrame.get_focus   s+     	2 	
 """r   c                J    t        j                  dt        d       || _        y )Nzincluded for backwards compatibility.You should rather use the container property `.focus_position` to set this value.API will be removed in version 5.0.rH   r    rg   rd   s     r   	set_focuszFrame.set_focus   s%    2 	
 #r   c                d    | j                   | j                  | j                  d| j                     S )zq
        child :class:`Widget` in focus: the body, header or footer widget.
        This is a read-only property.)r/   r.   r-   )r2   r4   r3   r5   r<   s    r   focuszFrame.focus  s)    
 ,,$,,

STXTcTcddr   c                      G  fddt         t        t        t        j                  t
        t        t        f   df   f         } |       S )a&  
        a dict-like object similar to::

            {
                "body": (body_widget, None),
                "header": (header_widget, None),  # if frame has a header
                "footer": (footer_widget, None),  # if frame has a footer
            }

        This object may be used to read or update the contents of the Frame.

        The values are similar to the list-like .contents objects used
        in other containers with (:class:`Widget`, options) tuples, but are
        constrained to keys for each of the three usual parts of a Frame.
        When other keys are used a :exc:`KeyError` will be raised.

        Currently, all options are `None`, but using the :meth:`options` method
        to create the options value is recommended for forwards
        compatibility.
        c                      e Zd ZdZddZW  j
                  ZW  j                  ZW  j                  Z
ddZd	 fdZd
dZy)%Frame.contents.<locals>.FrameContentsr   c                4    t        | j                               S r?   )lenkeys
inner_selfs    r   __len__z-Frame.contents.<locals>.FrameContents.__len__2  s    :??,--r   c              3  @   K   | j                         E d {    y 7 wr?   )rr   rs   s    r   __iter__z.Frame.contents.<locals>.FrameContents.__iter__9  s     %??,,,   c                V    d| j                   j                   dt        |        d dS )N<(z) for >)r#   r   dict)rt   r7   s    r   __repr__z.Frame.contents.<locals>.FrameContents.__repr__<  s4    ://8894
;K:LFSWRXXYZZr   c              3  @   K   | j                         E d {    y 7 wr?   )itemsrs   s    r   r=   z3Frame.contents.<locals>.FrameContents.__rich_repr__?  s     %++---rx   N)returnint)r   zIterator[str])r   strr   z4Iterator[tuple[str | None, typing.Any] | typing.Any])r   r   r   	__slots__ru   _contents__getitem____getitem___contents__setitem____setitem___contents__delitem____delitem__rw   r~   r=   r<   s   r   FrameContentsro   (  sB     I. 33K33K33K-[.r   r   N)r   r   tupletypingUnionr   r   r   )r7   r   s   ` r   contentszFrame.contents  sE    :	.fll:|\#IJDPQS	.4 r   c                    dg}| j                   r|j                  d       | j                  r|j                  d       |S )Nr-   r/   r.   )r2   appendr4   )r7   rr   s     r   _contents_keyszFrame._contents_keysD  s4    x<<KK!<<KK!r   c                     y r?   r   r7   keys     r   r   zFrame._contents__getitem__L  s    UXr   c                     y r?   r   r   s     r   r   zFrame._contents__getitem__O      Y\r   c                     y r?   r   r   s     r   r   zFrame._contents__getitem__R  r   r   c                    |dk(  r| j                   d fS |dk(  r| j                  r| j                  d fS |dk(  r| j                  r| j                  d fS t        d|      )Nr-   r/   r.   Frame.contents has no key: )r3   r2   r4   KeyErrorr   s     r   r   zFrame._contents__getitem__U  se     &=JJ%%(?t||LL$''(?t||LL$''4SG<==r   c                     y r?   r   r7   r   values      r   r   zFrame._contents__setitem__`  s    ber   c                     y r?   r   r   s      r   r   zFrame._contents__setitem__c      fir   c                     y r?   r   r   s      r   r   zFrame._contents__setitem__f  r   r   c                   |dvrt        d|      	 |\  }}|t        d|      	 |dk(  r|| _        y |dk(  r|| _        y || _        y # t        t        f$ r-}t        d|      j	                  |j
                        |d }~ww xY w)N>   r-   r.   r/   r   zadded content invalid: r-   r.   )	r   r   r6   	TypeErrorwith_traceback__traceback__r-   r.   r/   )r7   r   r   value_wvalue_optionsexcs         r   r   zFrame._contents__setitem__i  s    
 228@AA	m%*"G]( #:5)!DEE ) &=DIH_!DK!DK I& 	m6ui@APPQTQbQbcill	ms   A B(BBc                    |dvrt        d|      |dk(  r| j                  |dk(  r| j                  t        d|      |dk(  rd | _        y d | _        y )N>   r.   r/   z!Frame.contents can't remove key: r/   r.   r   )r   r2   r4   r/   r.   r   s     r   r   zFrame._contents__delitem__}  se    **>sgFGG8O 4#/dllNb8@AA(?DKDKr   c                     y)z~
        There are currently no options for Frame contents.

        Return None as a placeholder for future options.
        Nr   r<   s    r   optionszFrame.options  s    r   c                N   |\  }}dx}}| j                   r.| j                   j                  |f| j                  dk(  xr |      }| j                  r.| j                  j                  |f| j                  dk(  xr |      }|}| j                  dk(  r||k\  rd|f||ffS ||z  }||k\  ry||f||ffS | j                  dk(  r||k\  r|df||ffS ||z  }||k\  rK||f||ffS ||z   |k\  r;t	        d|dz
        }||dz
  k\  rd|f||ffS ||z  }t	        d|dz
        }||f||ffS ||f||ffS )a  
        Calculate the number of rows for the header and footer.

        :param size: See :meth:`Widget.render` for details
        :type size: widget size
        :param focus: ``True`` if this widget is in focus
        :type focus: bool
        :returns: `(head rows, foot rows),(orig head, orig foot)`
                  orig head/foot are from rows() calls.
        :rtype: (int, int), (int, int)
        r   r/   r.   r	   )r/   rowsr5   r.   max)	r7   sizerl   maxcolmaxrowfrowshrows	remainingrless1s	            r   frame_top_bottomzFrame.frame_top_bottom  s     ;;KK$$fY80K0UPUVE;;KK$$fY80K0UPUVE	??h&	!9~u~55I	!!5)E5>99__(!1~u~55I	!y)E5>99U]i'IM*F	A%6{UEN22IIM*FE?UEN22u~u~--r   c                   |\  }}| j                  ||f|      \  \  }}\  }}g }	g }
d }|rM||k  rHt        | j                  t        j                        j                  ||f|xr | j                  dk(        }nN|rL| j                  j                  |f|xr | j                  dk(        }|j                         |k7  rt        d      |r<|	j                  |d| j                  dk(  f       |
j                  | j                         ||z   |k  rq| j                  j                  |||z
  |z
  f|xr | j                  dk(        }|	j                  |d| j                  dk(  f       |
j                  | j                         d }|rM||k  rHt        | j                  t        j                        j                  ||f|xr | j                  dk(        }nN|rL| j                  j                  |f|xr | j                  dk(        }|j                         |k7  rt        d      |r<|	j                  |d| j                  dk(  f       |
j                  | j                         t        |	      S )Nr/   zrows, render mismatchr-   r.   )r   r   r/   r   TOPrenderr5   r   RuntimeErrorr   r-   r.   BOTTOMr   )r7   r   rl   r   r   htrimftrimr   r   combinelist
depends_onheadr-   foots                 r   r   zFrame.render  s0   
  )-)>)>?OQV)W&
UU]$++vzz29965/5KpUYUdUdhpUpqD;;%%vi1V4??h;VWDyy{e#"#:;;h80KLMdkk*5=6!99##VVe^e-C$DeFiPTP_P_ciPijDfdoo.GHIdii(UU]$++v}}5<<fe_eNsX\XgXgksXstD;;%%vi1V4??h;VWDyy{e#"#:;;h80KLMdkk*[))r   c                   |\  }}| j                   dk(  rE| j                  9| j                  j                         s|S | j                  j                  |f|      S | j                   dk(  rE| j                  9| j                  j                         s|S | j                  j                  |f|      S | j                   dk7  r|S |}| j                  || j                  j                  |f      z  }| j                  || j                  j                  |f      z  }|dk  r|S | j                  j                         s|S | j                  j                  ||f|      S )z!Pass keypress to widget in focus.r/   r.   r-   r   )r5   r/   
selectablekeypressr.   r   r-   )r7   r   r   r   r   r   s         r   r   zFrame.keypress  s1     ??h&4;;+B;;))+
;;''	377??h&4;;+B;;))+
;;''	377??f$J	;;"))6)44I;;"))6)44I>Jyy##%Jyy!!69"5s;;r   c                h   |\  }}| j                  ||f|      \  \  }	}
\  }}||	k  r||xr | j                  dk(  }t        |      r&|dk(  r!| j                  j	                         rd| _        t        | j                  d      sy| j                  j                  |f|||||      S |||
z
  k\  r|xr | j                  dk(  }t        |      r&|dk(  r!| j                  j	                         rd| _        t        | j                  d      sy| j                  j                  |f|||||z
  |
z   |      S |xr | j                  dk(  }t        |      r&|dk(  r!| j                  j	                         rd| _        t        | j                  d      sy| j                  j                  |||	z
  |
z
  f|||||	z
  |      S )zp
        Pass mouse event to appropriate part of frame.
        Focus may be changed on button 1 press.
        r/   r	   mouse_eventFr.   r-   )
r   r5   r   r/   r   ra   hasattrr   r.   r-   )r7   r   eventbuttoncolrowrl   r   r   r   r   _hrows_frowss                r   r   zFrame.mouse_event  s     +/+@+@&&AQSX+Y((;9doo9Ee$19O9O9Q&.#4;;6;;**F9eVS#uUU&5. 9doo9Ee$19O9O9Q&.#4;;6;;**F9eVS#PV,Y^J^`eff 3$//V3% Vq[TYY5I5I5K"(Dtyy-0yy$$ffunu.D%EufVY[^af[fhmnnr   c                   | j                   j                         syt        | j                   d      sy| j                  }|\  }}| j	                  |d      \  \  }}}|dk(  rd}| j
                  j                  |f      }	nL|dk(  r&|}| j                  j                  |||z
  |z
  f      }	n!||z
  }| j                  j                  |f      }	|	y|	\  }
}|
||z   fS )z2Return the cursor coordinates of the focus widget.Nget_cursor_coordsTr/   r   r-   )	rl   r   r   ra   r   r/   r   r-   r.   )r7   r   fpr   r   r   r   _
row_adjustcoordsxys               r   r   zFrame.get_cursor_coords0  s    zz$$&tzz#67   11$=>J[[22F9=F6\JYY00&&5.5:P1QRF%J[[22F9=F>1!j.  r   c              #  V   K   | j                   rd d | j                  rd yyw)zT
        Return an iterator over the positions in this Frame top to bottom.
        r/   r-   r.   N)r2   r4   r<   s    r   rw   zFrame.__iter__K  *      <<N<<N    ')c              #  V   K   | j                   rd d | j                  rd yyw)zT
        Return an iterator over the positions in this Frame bottom to top.
        r.   r-   r/   N)r4   r2   r<   s    r   __reversed__zFrame.__reversed__U  r   r   )NNr-   )r-   r   r/   r   r.   r   r5   z,Literal['header', 'footer', 'body'] | Widget)r   zdict[str, typing.Any]r   )r   r   )r/   r   r   None)r   r   )r-   r   r   r   )r   r   )r.   r   r   r   )r   #Literal['header', 'footer', 'body'])re   r   r   r   )r   z(BodyWidget | HeaderWidget | FooterWidget)r   zjMutableMapping[Literal['header', 'footer', 'body'], tuple[BodyWidget | HeaderWidget | FooterWidget, None]])r   z)list[Literal['header', 'footer', 'body']])r   Literal['body']r   tuple[BodyWidget, None])r   Literal['header']r   tuple[HeaderWidget, None])r   Literal['footer']r   tuple[FooterWidget, None])r   #Literal['body', 'header', 'footer']r   5tuple[BodyWidget | HeaderWidget | FooterWidget, None])r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   zLiteral['header', 'footer']r   r   )r   r   )r   tuple[int, int]rl   boolr   z'tuple[tuple[int, int], tuple[int, int]])F)r   r   rl   r   r   r   )r   r   r   r   r   z
str | None)r   r   r   r   r   r   r   r   r   r   rl   r   r   zbool | None)r   r   r   ztuple[int, int] | None)r   z-Iterator[Literal['header', 'body', 'footer']])r   z-Iterator[Literal['footer', 'body', 'header']])+r   r   r   __doc___selectable	frozensetr
   BOX_sizingr1   r9   r=   propertyr/   setterrJ   rM   r-   rT   rV   r.   r]   r_   ra   rh   rj   rl   r   r   r   overloadr   r   r   r   r   r   r   r   r   rw   r   __classcell__)r#   s   @r   r+   r+   ,   s    K%G
  $#CI#'#' #' 	#'
 A#'J6,   ]]    
[[ 
   ]]     #(# e e 6
6 6p __X X__\ \__\ \	>6	>	>	> __e e__i i__i i"0" E" 
	"(1.l &*&* &* 
	&*P<< < 
	<<'o'o 'o 	'o
 'o 'o 'o 
'oR!6r   r+   )r'   zWidget | Noner   r   )#
__future__r   r   r$   collections.abcr   urwid.canvasr   r   urwid.split_reprr   
urwid.utilr   	constantsr
   r   	containerr   fillerr   r'   r   r   TYPE_CHECKINGr   typing_extensionsr   TypeVarr   r   r   r   r)   Genericr+   r   r   r   <module>r      s    "   * 7 , % % +  '	() V^^L)
v~~n-v~~n-	 	

qF(&..\S_9_*` qr   