
    jj9                    "   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 ddl
mZmZmZmZmZmZmZmZ ddlmZmZ ej,                  rd d	lmZ  ej2                  d
      Z G d de      Z G d dee         Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)    )annotationsN)CompositeCanvas)remove_defaults)	int_scale   )RELATIVE_100SizingVAlign
WHSettingsnormalize_heightnormalize_valignsimplify_heightsimplify_valign)WidgetDecorationWidgetError)LiteralWrappedWidgetc                      e Zd Zy)FillerErrorN)__name__
__module____qualname__     \/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/urwid/widget/filler.pyr   r      s    r   r   c                  F    e Zd Zej                  ej                  dddf	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZdddZ	d fdZ
edd       Zej                  dd       Zdd	Zdd
ZddZddZ	 d	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZddZd dZ	 	 	 	 	 	 	 	 	 	 	 	 d!dZ xZS )"FillerNr   c                j   t         |   |       t        |t              rm|d   dk(  r/t        |t              r|d   dk7  rt	        d      |d   }t
        }n6|d   dk(  r.t        |t              r|d   dk7  rt	        d      |d   }t
        }t        |t              r?|d   dk(  r|d   }t        j                  }nP|d   dk(  r|d   }t        j                  }n2|}n/t        |t        t        f      st	        d|      t        |      }||t        j                  k(  rt        j                  }|| _        || _        t!        |t              \  | _        | _        t'        |t              \  | _        | _        | j(                  t        j,                  t        j                  hvr|| _        yd| _        y)	a  
        :param body: a flow widget or box widget to be filled around (stored as self.original_widget)
        :type body: Widget

        :param valign: one of:
            ``'top'``, ``'middle'``, ``'bottom'``,
            (``'relative'``, *percentage* 0=top 100=bottom)

        :param height: one of:

            ``'pack'``
              if body is a flow widget

            *given height*
              integer number of rows for self.original_widget

            (``'relative'``, *percentage of total height*)
              make height depend on container's height

        :param min_height: one of:

            ``None``
              if no minimum or if body is a flow widget

            *minimum height*
              integer number of rows for the widget when height not fixed

        :param top: a fixed number of rows to fill at the top
        :type top: int
        :param bottom: a fixed number of rows to fill at the bottom
        :type bottom: int

        If body is a flow widget, then height must be ``'pack'`` and *min_height* will be ignored.
        Sizing of the filler will be BOX/FLOW in this case.

        If height is integer, *min_height* will be ignored and sizing of filler will be BOX/FLOW.

        Filler widgets will try to satisfy height argument first by reducing the valign amount when necessary.
        If height still cannot be satisfied it will also be reduced.
        r   z	fixed topzfixed bottomz:fixed top height may only be used with fixed bottom valignr   z:fixed bottom height may only be used with fixed top valignzinvalid valign: N)super__init__
isinstancetupler   r   r
   TOPBOTTOMstrr	   FLOWr   PACKtopbottomr   valign_typevalign_amountr   height_typeheight_amountGIVEN
min_height)	selfbodyvalignheightr/   r(   r)   normalized_valign	__class__s	           r   r    zFiller.__init__!   s   j 	 fe$ayK'!&%0F1I4O%&bccQi%n,!&%0F1I4L%&bcc%fe$ayK'Qi$*JJ!n,$*MM!$*!FVSM2 0
;<< !'v >Vv{{2__F/?@QS^/_,$,/?/T,$,J$4$4joo#FF(DO"DOr   c                    t         j                  h}| j                  t        j                  t        j
                  hv r|j                  t         j                         t        |      S )zWidget sizing.

        Sizing BOX is always supported.
        Sizing FLOW is supported if: FLOW widget (a height type is PACK) or BOX widget with height GIVEN
        )	r	   BOXr,   r   r'   r.   addr&   	frozenset)r0   sizings     r   r:   zFiller.sizing   sG      &zzl
1A1ABBJJv{{#  r   c                D   | j                   t        j                  k(  r6| j                  j	                  ||      | j
                  z   | j                  z   S | j                   t        j                  k(  r&| j                  | j
                  z   | j                  z   S t        d      )z+Flow pack support if FLOW sizing supported.z+Method 'rows' not supported for BOX widgets)
r,   r   r'   original_widgetrowsr(   r)   r.   r-   r   )r0   sizefocuss      r   r=   zFiller.rows   s}    z.'',,T59DHHDt{{RRz///%%04;;>>GHHr   c                   i t         |          t        | j                  | j                        t        | j                  | j                        | j                  | j                  | j                  d}t        |t        j                        S )N)r2   r3   r(   r)   r/   )r   _repr_attrsr   r*   r+   r   r,   r-   r(   r)   r/   r   r   r    )r0   attrsr5   s     r   rA   zFiller._repr_attrs   ss    
g!#
%d&6&68J8JK%d&6&68J8JK88kk//
 ufoo66r   c                R    t        j                  dt        d       | j                  S )9backwards compatibility, widget used to be stored as body^backwards compatibility, widget used to be stored as body. API will be removed in version 5.0.   
stacklevelwarningswarnDeprecationWarningr<   r0   s    r   r1   zFiller.body   s'     	l	

 ###r   c                J    t        j                  dt        d       || _        y )NrE   rF   rG   rI   r0   new_bodys     r   r1   zFiller.body   s!    l	

  (r   c                R    t        j                  dt        d       | j                  S )rD   ^backwards compatibility, widget used to be stored as body. API will be removed in version 4.0.rF   rG   rI   rM   s    r   get_bodyzFiller.get_body   s%    l	

 ###r   c                J    t        j                  dt        d       || _        y )NrR   rF   rG   rI   rO   s     r   set_bodyzFiller.set_body   s!    l	

  (r   c                6    | j                   j                         S )zReturn selectable from body.)_original_widget
selectablerM   s    r   rX   zFiller.selectable   s    $$//11r   c           
        | j                  ||      \  }}| j                  t        j                  k(  rf| j                  j                  |f|      }t        || j                  | j                  t        j                  |d| j                  | j                        S t        || j                  | j                  | j                  | j                  | j                  | j                  | j                        S )z
        Return the number of rows to pad on the top and bottom.

        Override this method to define custom padding behaviour.
        )r?   N)packr,   r   r'   rW   r=   calculate_top_bottom_fillerr*   r+   r.   r(   r)   r-   r/   )r0   r>   r?   maxcolmaxrowr3   s         r   filler_valueszFiller.filler_values   s     4/z.**//	/GF.  ""  	 	 +OOHHKK	
 		
r   c                F   | j                  ||      \  }}| j                  ||      \  }}| j                  t        j                  k(  r| j
                  j                  |f|      }n$| j
                  j                  |||z
  |z
  f|      }t        |      }|rQ|j                         |kD  r>|j                  2|j                  \  }}	|	|k\  r|j                  |	|z
  dz   ||z
  |z
         |j                         |kD  r|j                  d|       |S |j                  ||       |S )z:Render self.original_widget with space above and/or below.r   r   )rZ   r^   r,   r   r'   rW   renderr   r=   cursortrimpad_trim_top_bottom)
r0   r>   r?   r\   r]   r(   r)   canv_cxcys
             r   r`   zFiller.render   s    4/((u5Vz.((//	5AD((//#9N0OQVWDt$diikF*t{{/FkkGCV|		"v+/6C<&+@A99;IIa K  f-r   c                   | j                  |d      \  }}| j                  t        j                  k(  r| j                  j                  |f|      S | j                  ||fd      \  }}| j                  j                  |||z
  |z
  f|      S )z&Pass keypress to self.original_widget.T)rZ   r,   r   r'   rW   keypressr^   )r0   r>   keyr\   r]   r(   r)   s          r   rh   zFiller.keypress  s     4.z.((116)SAA((&&)94@V$$--vv|f7L.MsSSr   c                p   | j                  |d      \  }}t        | j                  d      sy| j                  |d      \  }}| j                  t
        j                  k(  r| j                  j                  |f      }n#| j                  j                  |||z
  |z
  f      }|sy|\  }}||k\  r|dz
  }|||z   fS )z6Return cursor coords from self.original_widget if any.Tget_cursor_coordsNr   )rZ   hasattrrW   r^   r,   r   r'   rk   )	r0   r>   r\   r]   r(   r)   coordsxys	            r   rk   zFiller.get_cursor_coords  s    4.t,,.AB((t4Vz.**<<fYGF**<<ffslU[F[=\]F1;
A!c'zr   c                D   | j                  |d      \  }}t        | j                  d      sy| j                  t        j
                  k(  r| j                  j                  |f      }|S | j                  |d      \  }}| j                  j                  |||z
  |z
  f      }|S )z1Return pref_col from self.original_widget if any.Tget_pref_colN)rZ   rl   rW   r,   r   r'   rq   r^   )r0   r>   r\   r]   rn   r(   r)   s          r   rq   zFiller.get_pref_col!  s    4.t,,n=z.%%22F9=A
  ,,T48KC%%22FFSL6<Q3RSAr   c                l   | j                  |d      \  }}t        | j                  d      sy| j                  |d      \  }}||k  s|||z
  k\  ry| j                  t
        j                  k(  r!| j                  j                  |f|||z
        S | j                  j                  |||z
  |z
  f|||z
        S )Pass to self.original_widget.Tmove_cursor_to_coordsF)rZ   rl   rW   r^   r,   r   r'   rt   )r0   r>   colrowr\   r]   r(   r)   s           r   rt   zFiller.move_cursor_to_coords/  s    4.t,,.EF((t4V9v.z.((>>y#sUXyYY$$::FFSLSYDY;Z\_adgjajkkr   c                x   | j                  ||      \  }}t        | j                  d      sy| j                  |d      \  }	}
||	k  s|||
z
  k\  ry| j                  t
        j                  k(  r$| j                  j                  |f|||||	z
  |      S | j                  j                  |||	z
  |
z
  f|||||	z
  |      S )rs   mouse_eventFT)rZ   rl   rW   r^   r,   r   r'   rx   )r0   r>   eventbuttonru   rv   r?   r\   r]   r(   r)   s              r   rx   zFiller.mouse_event=  s     4/t,,m<((t4V9v.z.((44fYvsTWZ]T]_dee$$00&&3,:O1PRWY_adfilofoqvwwr   )r1   r   r2   zbLiteral['top', 'middle', 'bottom'] | VAlign | tuple[Literal['relative', WHSettings.RELATIVE], int]r3   zdint | Literal['pack', WHSettings.PACK] | tuple[Literal['relative', WHSettings.RELATIVE], int] | Noner/   
int | Noner(   intr)   r|   returnNone)r}   zfrozenset[Sizing])F)r>   z
tuple[int]r?   boolr}   r|   )r}   zdict[str, typing.Any])r}   r   )rP   r   r}   r~   )r}   r   )r>   tuple[int, int] | tuple[int]r?   r   r}   tuple[int, int])r>   r   r?   r   r}   r   )r>   ztuple[int, int] | tuple[()]ri   r%   r}   z
str | None)r>   r   r}   ztuple[int, int] | None)r>   r   r}   r{   )r>   r   ru   r|   rv   r|   r}   r   )r>   r   rz   r|   ru   r|   rv   r|   r?   r   r}   zbool | None)r   r   r   r
   MIDDLEr   r'   r    r:   r=   rA   propertyr1   setterrS   rU   rX   r^   r`   rh   rk   rq   rt   rx   __classcell__)r5   s   @r   r   r       sd    MM OO!%`#`# o	`# q`# `# `# `# 
`#D	!I	7 $ $ 
[[( ($(2
F *  
	2T)T T 
	T$lx*x 	x
 x x x 
xr   r   c                2   |t         j                  k(  r1t        | |z
  |z
  d      }t        |d|dz         }	|t        |	|      }	n|}	t        j
                  dt        j                  dt        j                  dij                  ||      }
| |	z
  |z
  |z
  }|t        d|
z
  d|dz         z  }| |	z
  |z
  }|dcxk  r|k  rn nt        ||       }||z  }||z  }n%|dcxk  r|k  rn nt        ||       }||z  }||z  }t        |d      }t        |d      }||fS )a  
    Return the amount of filler (or clipping) on the top and
    bottom part of maxrow rows to satisfy the following:

    valign_type -- 'top', 'middle', 'bottom', 'relative'
    valign_amount -- a percentage when align_type=='relative'
    height_type -- 'given', 'relative', 'clip'
    height_amount -- a percentage when width_type=='relative'
        otherwise equal to the height of the widget
    min_height -- a desired minimum width for the widget or None
    top -- a fixed number of rows to fill on the top
    bottom -- a fixed number of rows to fill on the bottom

    >>> ctbf = calculate_top_bottom_filler
    >>> ctbf(15, "top", 0, "given", 10, None, 2, 0)
    (2, 3)
    >>> ctbf(15, "relative", 0, "given", 10, None, 2, 0)
    (2, 3)
    >>> ctbf(15, "relative", 100, "given", 10, None, 2, 0)
    (5, 0)
    >>> ctbf(15, "middle", 0, "given", 4, None, 2, 0)
    (6, 5)
    >>> ctbf(15, "middle", 0, "given", 18, None, 2, 0)
    (0, 0)
    >>> ctbf(20, "top", 0, "relative", 60, None, 0, 0)
    (0, 8)
    >>> ctbf(20, "relative", 30, "relative", 60, None, 0, 0)
    (2, 6)
    >>> ctbf(20, "relative", 30, "relative", 60, 14, 0, 0)
    (2, 4)
    r   e   r   2   d   )
r   RELATIVEmaxr   r
   r#   r   r$   getmin)r]   r*   r+   r,   r-   r/   r(   r)   	maxheightr3   r2   fillershifts                r   r[   r[   T  s9   R j)))v-q1	=#y1}=!,Fjj!V]]BsCGGUbcF f_s"V+F
ifc6A:66F
6/F
"C CC&!u%	q	6	FSD!%u c1+C^F;r   )r]   r|   r*   zLLiteral['top', 'middle', 'bottom', 'relative', WHSettings.RELATIVE] | VAlignr+   r|   r,   z\Literal['given', 'relative', 'clip', WHSettings.GIVEN, WHSettings.RELATIVE, WHSettings.CLIP]r-   r|   r/   r{   r(   r|   r)   r|   r}   r   )
__future__r   typingrJ   urwid.canvasr   urwid.split_reprr   
urwid.utilr   	constantsr   r	   r
   r   r   r   r   r   widget_decorationr   r   TYPE_CHECKINGtyping_extensionsr   TypeVarr   r   r   r[   r   r   r   <module>r      s    "   ( ,  	 	 	 =	)/	+ 	qxm, qxh	FF]F F n	F
 F F 
F F Fr   