
    jj?                    >   d dl mZ d dlZd dlZd dlmZmZ d dlZd dlm	Z	m
Z
mZm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 dd
lmZmZmZ ddlmZmZ ddlmZm Z m!Z! ejD                  rd dl#m$Z$m%Z%m&Z& d dl'm(Z(  G d de       Z) G d de!      Z* G d deee      Z+y)    )annotationsN)chainrepeat)Canvas
CanvasJoinCompositeCanvasSolidCanvas)Command)remove_defaults)is_mouse_press   )AlignSizing
WHSettings) WidgetContainerListContentsMixinWidgetContainerMixin_ContainerElementSizingFlag)MonitoredFocusListMonitoredList)WidgetWidgetErrorWidgetWarning)IterableIteratorSequence)Literalc                      e Zd ZdZy)ColumnsErrorzColumns related errors.N__name__
__module____qualname____doc__     ]/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/urwid/widget/columns.pyr   r      s    !r%   r   c                      e Zd ZdZy)ColumnsWarningzColumns related warnings.Nr   r$   r%   r&   r(   r(      s    #r%   r(   c                  P    e Zd ZdZd,dZ	 	 	 	 d-	 	 	 	 	 	 	 	 	 d. fdZd/ fdZd0 fdZd1dZd2dZ	d3d	Z
d3d
Zed4d       Zej                  d        Zed4d       Zej                  d        Zed4d       Zej                  d        Zed5d       Zej                  d        Ze	 	 d6d       Zej                  	 	 	 	 d7d       Zeej*                  ddf	 	 	 	 	 	 	 d8d       Zd3 fdZd9dZd2dZd:dZed;d       Zd Zed<d       Zej                  d=d       Zed        Zej                  d3d        Zd>d?d!Z	 d>	 	 	 d@d"Z 	 d>	 	 	 	 	 dAd#Z!	 	 dB	 	 	 	 	 dC fd$Z"	 d>	 	 	 	 	 dDd%Z#dEd&Z$	 	 	 	 	 	 	 	 dFd'Z%	 	 	 	 	 	 	 	 	 	 	 	 	 	 dGd(Z&dHd)Z'd>dId*Z(	 	 	 	 	 	 dJd+Z) xZ*S )KColumnszE
    Widgets arranged horizontally in columns from left to right
    c                   | j                   s)t        t        j                  t        j                  f      S d}d}d}d}t               }t        j                  t        j                  z  t        j                  z  }t        j                  t        j                  z  }t        j                  t        j                  z  }t               }	t        | j                         D ]  \  }
\  }\  }}}|j                         }t        j                  }|t        j                  k(  r|t        j                  z  }t        j                  |v r|t        j                  z  }t        j                  |v r|t        j                  z  }t        j                  |v r|t        j                  t        j                  hz  r|t        j                  z  }n|t        j                   k(  rq|t        j                  z  }t        j                  |v r|t        j                  z  }t        j                  |v r|t        j                  z  }|t        j                  z  }n]|t        j"                  z  }t        j                  |v r|t        j                  z  }t        j                  |v r|t        j                  z  }||z  s]t%        j&                  d| d|
 d|j(                   d| t*        d       t        t        j                  t        j                  f      c S |	j-                  |       |t        j                  z  r	|s||z  sd}|t        j                  z  rd}|t        j                  z  rd}||z  |k7  sd} t/        d	 |	D              r|j-                  t        j                         |sc|r|j-                  t        j                         |r@|s>|j-                  t        j                         |j-                  t        j                         |sht%        j&                  d
dj1                  t3        d |	D                     dt*        d       t        t        j                  t        j                  f      S t        |      S )a	  Sizing supported by widget.

        :return: Calculated widget sizing
        :rtype: frozenset[Sizing]

        Due to the nature of container with mutable contents, this method cannot be cached.

        Rules:
        * WEIGHT BOX -> BOX
        * GIVEN BOX -> Can be included in FIXED and FLOW depends on the other columns
        * PACK BOX -> Unsupported
        * BOX-only widget without `box_columns` disallow FLOW render

        * WEIGHT FLOW -> FLOW
        * GIVEN FLOW -> FIXED (known width and widget knows its height) + FLOW (historic)
        * PACK FLOW -> FLOW (widget fit in provided size)

        * WEIGHT FIXED -> Need also FLOW or/and BOX to properly render due to width calculation
        * GIVEN FIXED -> Unsupported
        * PACK FIXED -> FIXED (widget knows its size)

        Backward compatibility rules:
        * GIVEN BOX -> Allow BOX

        BOX can be only if ALL widgets support BOX.
        FIXED can be only if no BOX without "box_columns" flag and no strict FLOW.

        >>> from urwid import BigText, Edit, SolidFill, Text, Thin3x3Font
        >>> font = Thin3x3Font()

        # BOX-only widget
        >>> Columns((SolidFill("#"),))
        <Columns box widget (1 item)>

        # BOX-only widget with "get height from max"
        >>> Columns((SolidFill("#"),), box_columns=(0,))
        <Columns box widget (1 item)>

        # FLOW-only
        >>> Columns((Edit(),))
        <Columns selectable flow widget (1 item)>

        # FLOW allowed by "box_columns"
        >>> Columns((Edit(), SolidFill("#")), box_columns=(1,))
        <Columns selectable flow widget (2 items) focus_column=0>

        # FLOW/FIXED
        >>> Columns((Text("T"),))
        <Columns fixed/flow widget (1 item)>

        # GIVEN BOX only -> BOX only
        >>> Columns(((5, SolidFill("#")),), box_columns=(0,))
        <Columns box widget (1 item)>

        # No FLOW - BOX only
        >>> Columns(((5, SolidFill("#")), SolidFill("*")), box_columns=(0, 1))
        <Columns box widget (2 items) focus_column=0>

        # FIXED only -> FIXED (and FLOW via drop/expand)
        >>> Columns(((WHSettings.PACK, BigText("1", font)),))
        <Columns fixed/flow widget (1 item)>

        # Invalid sizing combination -> use fallback settings (and produce warning)
        >>> Columns(((WHSettings.PACK, SolidFill("#")),))
        <Columns box/flow widget (1 item)>

        # Special case: empty columns widget sizing is impossible to calculate
        >>> Columns(())
        <Columns box/flow widget ()>
        FzSizing combination of widget z (position=z) not supported:  box=   
stacklevelTc              3  B   K   | ]  }|t         j                  z    y wN)r   BOX.0flags     r&   	<genexpr>z!Columns.sizing.<locals>.<genexpr>   s     H$t1555H   zLColumns widget contents flags not allow to determine supported render kind:
z, c              3  F   K   | ]  }t        j                  |        y wr1   )r   
log_stringr3   s     r&   r6   z!Columns.sizing.<locals>.<genexpr>   s     #cUY$?$J$J4$P#cs   !z/
Using fallback hardcoded BOX|FLOW sizing kind.)contents	frozenseturwidr2   FLOWsetr   FIXEDWH_GIVEN	enumeratesizingNONEr   WEIGHT	WH_WEIGHTr   GIVENWH_PACKwarningswarnnamer(   addalljoinsorted)self
strict_boxhas_flowblock_fixed	has_fixed	supportedbox_flow_fixed
flow_fixed	given_boxflagsidxwidget	size_kind_size_weightis_boxw_sizingr5   s                    r&   rB   zColumns.sizing%   s   N }}eii455
	!$	 (++.I.N.NNQlQrQrr 	 1558S8Y8YY
/336Q6Z6ZZ	 %@I$--@X 0	#<C<&;9lF}}H.33DJ---3===::)7;;;D;;(*7<<<D<<8+FJJ;T0T7===Dj...3<<<::)7;;;D;;(*7===D7<<<D 3;;;<<8+7===D;;(*7<<<D.(3F8;seK\ ~~&eF85" 	 !&**fkk!:;;IIdO1555vPZIZ!
16661777 		!Y."a0	#d H%HH MM&**%fkk*fkk*fll+MM_99V#c]b#ccde fAB  fjj&++677##r%   r   c                8    d _         g  _        t                   t	                _         j
                  j                   j                          j
                  j                   fd        j
                  j                   j                         t        |xs d      }t        |      D ]  \  }}|}t        |t              s2 j                  j!                  |t"        j$                  d||v ff       n"|d   t&        j(                  t"        j*                  hv r6|\  }	} j                  j!                  |t"        j*                  d||v ff       nt-        |      dk(  s%|d   t&        j.                  t"        j0                  hv r9|dd \  }
} j                  j!                  |t"        j0                  |
||v ff       n[|d   t"        j$                  k(  r7|\  }	}
} j                  j!                  |t"        j$                  |
||v ff       nt3        d	|      ||k(  s||j5                         r|}t        |t6              rt9        j:                  |d
t<        d        | _         j                  r	|| _         d _!        | _"        d _#        y)aZ  
        :param widget_list: iterable of flow or box widgets
        :param dividechars: number of blank characters between columns
        :param focus_column: index into widget_list of column in focus or focused widget instance,
            if ``None`` the first selectable widget will be chosen.
        :param min_width: minimum width for each column which is not
            calling widget.pack() in *widget_list*.
        :param box_columns: a list of column indexes containing box widgets
            whose height is set to the maximum of the rows
            required by columns not listed in *box_columns*.

        *widget_list* may also contain tuples such as:

        (*given_width*, *widget*)
            make this column *given_width* screen columns wide, where *given_width* is an int
        (``'pack'``, *widget*)
            call :meth:`pack() <Widget.pack>` to calculate the width of this column
        (``'weight'``, *weight*, *widget*)
            give this column a relative *weight* (number) to calculate its width from th screen columns remaining

        Widgets not in a tuple are the same as (``'weight'``, ``1``, *widget*)

        If the Columns widget is treated as a box widget then all children
        are treated as box widgets, and *box_columns* is ignored.

        If the Columns widget is treated as a flow widget then the rows
        are calculated as the largest rows() returned from all columns
        except the ones listed in *box_columns*.  The box widgets in
        *box_columns* will be displayed with this calculated number of rows,
        filling the full height.
        Fc                $    j                         S r1   )_invalidate)frO   s    r&   <lambda>z"Columns.__init__.<locals>.<lambda>  s    D<L<L<N r%   r$   r   r   N   z"initial widget list item invalid:  is not a Widgetr-   r.   )$_selectable_cache_column_widthssuper__init__r   	_contentsset_modified_callback_contents_modifiedset_focus_changed_callbackset_validate_contents_modified_validate_contents_modifiedr>   rA   
isinstancetupler:   appendr   rD   r   r=   PACKlenr?   rF   r   
selectabler   rH   rI   r(   dividecharsfocus_positionpref_col	min_width_cache_maxcol)rO   widget_listrw   focus_columnrz   box_columnsioriginalw_ignoredwidth	__class__s   `          r&   rj   zColumns.__init__   sG   X !/1!   	 	,,T-D-DE112NO55d6V6VW++,$[1 	VKAxAa'$$a**;*;Q[@P)Q%RS1&++z77!$$a*//4kAQ)R%STQ1!z7G7G(H HRS6q$$a**:*:E1CS)T%UV1***%&"%$$a**;*;UADT)U%VW"%G|#TUUq \%9alln a(%56STU'	V* '==\5".D"!r%   c                    t        | j                        dkD  rdt        | j                         d}n| j                  rd}nd}g t        |          |S )Nr   (z items)z(1 item)z())ru   r:   ri   _repr_words)rO   contents_stringr   s     r&   r   zColumns._repr_words%  sU    t}}! !#dmm"4!5W=O]](O"O8$&888r%   c                    i t         |          | j                  t        | j                        dkD  r| j
                  nd | j                  d}t        |t        j                        S )Nr   )rw   r}   rz   )
ri   _repr_attrsrw   ru   rk   rx   rz   r   r*   rj   )rO   attrsr   s     r&   r   zColumns._repr_attrs.  s`    
g!#
++36t~~3F3JD//PT	
 ug&6&677r%   c              #  B  K   g }g }t        | j                        D ]  \  }\  }\  }}}|t        j                  k(  r|j	                  ||f       nn|t        j
                  k(  r"|j	                  t        j
                  |f       n9|dk(  r|j	                  |       n"|j	                  t        j                  ||f       |s|j	                  |        d|f d| j                  f d| j                  r| j                  nd f d| j                  f d|f y w)Nr   r|   rw   r}   rz   r~   )
rA   rk   r   rF   rs   rt   rD   rw   rx   rz   )rO   r|   r~   rY   
w_instancerB   amountr]   s           r&   __rich_repr__zColumns.__rich_repr__7  s    
 	 	
 "$;DT^^;T 	(7C7*6vvv)))""FJ#78:??*""JOOZ#@A1"":.""J$5$5vz#JK""3'	( [((T----T^^d11MM4>>))[((s   B>DADc                ,    t        | j                        S r1   )ru   rk   rO   s    r&   __len__zColumns.__len__Q  s    4>>""r%   c                f    t        d | j                  D              | _        | j                          y)zv
        Recalculate whether this widget should be selectable whenever the
        contents has been changed.
        c              3  B   K   | ]  \  }}|j                           y wr1   )rv   )r4   r   os      r&   r6   z-Columns._contents_modified.<locals>.<genexpr>Y  s     H$!Qq||~Hr7   N)anyr:   rg   ra   r   s    r&   rm   zColumns._contents_modifiedT  s'    
 H$--HHr%   c           	        g }	 |D ]  }|\  }\  }}}t        |t        j                  t        j                  t        j                  hv|d uxr t        |t        t        f       xs |dk  t        |t               f      s{|j                  |        	 |rt        d|      y # t        t        f$ r-}	t        d|	       j                  |	j                        |	d }	~	ww xY w)Nr   zadded content invalid zadded content invalid: )r   r   rt   rF   rD   rq   intfloatboolrs   	TypeError
ValueErrorr   with_traceback__traceback__)
rO   slc	new_itemsinvalid_itemsitem_wtnbexcs
             r&   rp   z#Columns._validate_contents_modified\  s    XZ	j! 	/ $IQ1*//:3C3CZEVEV!WW$U
1sEl0K,K,TqSTu&q$// "((.	/ !88IJKK  :& 	j!7u=>MMcN_N_`fii	js   A<B& B& &C"5(CC"c                     t        j                  dt        d       t        d  j                  D               fd}j                  |       S )z
        A list of the widgets in this Columns

        .. note:: only for backwards compatibility. You should use the new
            standard container property :attr:`contents`.
        zonly for backwards compatibility. You should use the new standard container `contents`.API will be removed in version 5.0.rd   r.   c              3  &   K   | ]	  \  }}|  y wr1   r$   )r4   r   r   s      r&   r6   z&Columns.widget_list.<locals>.<genexpr>}  s     7A17   c                      _         y r1   )r|   mlrO   s   r&   user_modifiedz*Columns.widget_list.<locals>.user_modified      !Dr%   rH   rI   DeprecationWarningr   r:   rl   rO   r   r   s   ` @r&   r|   zColumns.widget_listo  sL     	2		
 777	" 	  /	r%   c                D   t        j                  dt        d       | j                  }t	        |t        | j                  t        d t        j                  ddff                  D cg c]  \  }\  }}||f c}}}| _        |t        |      k  r|| _        y y c c}}}w )Nr   rd   r.   r   F)rH   rI   r   rx   zipr   r:   r   r   rD   ru   )rO   widgetsrx   newr   optionss         r&   r|   zColumns.widget_list  s    2		
 ,, (+dmmVTJ4E4Eq%3P,Q%RS(
 
 $lq' 'N
 CL("0D )
s   )Bc                     t        j                  dt        d       t        d  j                  D               fd}j                  |       S )z
        A list of the old partial options values for widgets in this Pile,
        for backwards compatibility only.  You should use the new standard
        container property .contents to modify Pile contents.
        for backwards compatibility only.You should use the new standard container property .contents to modify Pile contents.API will be removed in version 5.0.rd   r.   c              3     K   | ][  \  }\  }}}t         j                  t        j                  t         j                  t        j
                  ij                  ||      |f ] y wr1   )r   rF   r   r?   rt   r=   getr4   r   r   r   r   s        r&   r6   z'Columns.column_types.<locals>.<genexpr>  sT      
 9Aq! joov{{KOOPQSTUWXY
s   A!A#c                      _         y r1   )column_typesr   s   r&   r   z+Columns.column_types.<locals>.user_modified  s     "Dr%   r   r   s   ` @r&   r   zColumns.column_types  sW     	2 	
  
 !%
 
	# 	  /	r%   c                   t        j                  dt        d       | j                  }t	        || j
                        D cg c]b  \  \  }}\  }\  }}}|t        j                  t        j                  t        j                  t        j                  ij                  ||      ||ffd c}}}}}}| _        |t        |      k  r|| _        y y c c}}}}}}w )Nr   rd   r.   )rH   rI   r   rx   r   r:   r   r?   r   rF   r=   rt   r   ru   )	rO   r   rx   new_tnew_nr   r   r   r   s	            r&   r   zColumns.column_types  s    2 	
 ,, 58dmm4T
 
0%!YaA &,,
 0 0&++zOSSTY[`achjklm
 C--"0D .	
s   A'Cc                     t        j                  dt        d       t        d t	         j
                        D               fd}j                  |       S )a  
        A list of the indexes of the columns that are to be treated as
        box widgets when the Columns is treated as a flow widget.

        .. note:: only for backwards compatibility. You should use the new
            standard container property :attr:`contents`.
        only for backwards compatibility.You should use the new standard container property `contents`.API will be removed in version 5.0.rd   r.   c              3  :   K   | ]  \  }\  }\  }}}|s|  y wr1   r$   )r4   r   r   r   r   r   s         r&   r6   z&Columns.box_columns.<locals>.<genexpr>  s"     T!2NQ	AqRS1Ts   c                      _         y r1   )r~   r   s   r&   r   z*Columns.box_columns.<locals>.user_modified  r   r%   )rH   rI   r   r   rA   r:   rl   r   s   ` @r&   r~   zColumns.box_columns  sQ     	2		
 Ti6NTT	" 	  /	r%   c                    t        j                  dt        d       t        |      }t	        | j
                        D cg c]  \  }\  }\  }}}|||||v ff c}}}}}| _        y c c}}}}}w )Nr   rd   r.   )rH   rI   r   r>   rA   r:   )rO   r~   r   r   r   r   r   s          r&   r~   zColumns.box_columns  si    2		
 +&R[\`\i\iRjkk;NA~9Aq!!aA$456kks   A*c                r    t        j                  dt        d       t        j                  | j
                  v S )zP
        .. deprecated:: 1.0 Read values from :attr:`contents` instead.
        e.has_flow_type is deprecated, read values from .contents instead. API will be removed in version 4.0.rd   r.   )rH   rI   r   r   rt   r   r   s    r&   has_flow_typezColumns.has_flow_type  s0    
 	s	

 $"3"333r%   c                <    t        j                  dt        d       y )Nr   rd   r.   )rH   rI   r   )rO   values     r&   r   zColumns.has_flow_type  s    s	
r%   c                    | j                   S )a  
        The contents of this Columns as a list of `(widget, options)` tuples.
        This list may be modified like a normal list and the Columns
        widget will update automatically.

        .. seealso:: Create new options tuples with the :meth:`options` method
        rk   r   s    r&   r:   zColumns.contents  s    $ ~~r%   c                "    || j                   d d  y r1   r   )rO   cs     r&   r:   zColumns.contents  s     qr%   Fc                    | t         j                  k(  rt         j                  d|fS | t         j                  t         j                  hv r|t        |       ||fS t	        d| d|      )a  
        Return a new options tuple for use in a Pile's .contents list.

        This sets an entry's width type: one of the following:

        ``'pack'``
            Call the widget's :meth:`Widget.pack` method to determine how wide
            this column should be. *width_amount* is ignored.
        ``'given'``
            Make column exactly width_amount screen-columns wide.
        ``'weight'``
            Allocate the remaining space to this column by using
            *width_amount* as a weight value.

        :param width_type: ``'pack'``, ``'given'`` or ``'weight'``
        :param width_amount: ``None`` for ``'pack'``, a number of screen columns
            for ``'given'`` or a weight value (number) for ``'weight'``
        :param box_widget: set to `True` if this widget is to be treated as a box
            widget when the Columns widget itself is treated as a flow widget.
        :type box_widget: bool
        Nz invalid combination: width_type=z, width_amount=)r   rt   rF   rD   r   )
width_typewidth_amount
box_widgets      r&   r   zColumns.options  sm    B (OOT:66***J,=,=>><C[z*L*EE=j^?[gZjkllr%   c                0    d | _         t        | 	          y r1   )r{   ri   ra   )rO   r   s    r&   ra   zColumns._invalidateA  s    !r%   c                J    t        j                  dt        d       || _        y)a4  
        Set the column in focus by its index in :attr:`widget_list`.

        :param num: index of focus-to-be entry
        :type num: int

        .. note:: only for backwards compatibility. You may also use the new
            standard container property :attr:`focus_position` to set the focus.
        only for backwards compatibility.You may also use the new standard container property `focus_position`.API will be removed in version 5.0.rd   r.   NrH   rI   r   rx   )rO   nums     r&   set_focus_columnzColumns.set_focus_columnE  s%     	2		
 "r%   c                R    t        j                  dt        d       | j                  S )z
        Return the focus column index.

        .. note:: only for backwards compatibility. You may also use the new
            standard container property :attr:`focus_position` to get the focus.
        r   rd   r.   r   r   s    r&   get_focus_columnzColumns.get_focus_columnW  s)     	2		
 """r%   c                    t        j                  dt        d       t        |t              r|| _        yt        | j                        D ]  \  }\  }}||k(  s|| _         y t        d|      )z
        Set the item in focus

        .. note:: only for backwards compatibility. You may also use the new
            standard container property :attr:`focus_position` to get the focus.

        :param item: widget or integer indexonly for backwards compatibility.You may also use the new standard container property `focus_position` to get the focus.API will be removed in version 5.0.rd   r.   Nz&Widget not found in Columns contents: )	rH   rI   r   rq   r   rx   rA   r:   r   )rO   r   r   r   _optionss        r&   	set_focuszColumns.set_focusf  s|     	2 	
 dC "&D )$-- 8 	A}8qy&'#	 A$JKKr%   c                T    | j                   sy| j                   | j                     d   S )z
        the child widget in focus or None when Columns is empty

        Return the widget in focus, for backwards compatibility.  You may
        also use the new standard container property .focus to get the
        child widget in focus.
        Nr   )r:   rx   r   s    r&   focuszColumns.focus~  s(     }}}}T001!44r%   c                    t        j                  dt        d       | j                  sy| j                  | j                     d   S )z
        Return the widget in focus, for backwards compatibility.

        .. note:: only for backwards compatibility. You may also use the new
            standard container property :attr:`focus` to get the focus.
        zonly for backwards compatibility.You may also use the new standard container property `focus` to get the focus.API will be removed in version 5.0.rd   r.   Nr   )rH   rI   r   r:   rx   r   s    r&   	get_focuszColumns.get_focus  sC     	2 	
 }}}}T001!44r%   c                \    | j                   st        d      | j                   j                  S )z
        index of child widget in focus.
        Raises :exc:`IndexError` if read when Columns is empty, or when set to an invalid index.
        z#No focus_position, Columns is empty)r:   
IndexErrorr   r   s    r&   rx   zColumns.focus_position  s'     }}BCC}}"""r%   c                    	 |dk  s|t        | j                        k\  rt        d|       	 || j                  _        y# t        $ r-}t        d|       j	                  |j
                        |d}~ww xY w)zf
        Set the widget in focus.

        position -- index of child widget to be made focus
        r   z$No Columns child widget at position N)ru   r:   r   r   r   r   r   )rO   positionr   s      r&   rx   zColumns.focus_position  s    	!|x3t}}+== #Gz!RSS  > '	  	CH:NO^^!!	s   +A   	A6	(A11A6c                R    t        j                  dt        d       | j                  S )z
        A property for reading and setting the index of the column in
        focus.

        .. note:: only for backwards compatibility. You may also use the new
            standard container property :attr:`focus_position` to get the focus.
        r   rd   r.   r   r   s    r&   	focus_colzColumns.focus_col  s+     	2 	
 """r%   c                J    t        j                  dt        d       || _        y )Nr   rd   r.   r   )rO   new_positions     r&   r   zColumns.focus_col  s%    2 	
 +r%   c                   |d   }|| j                   k(  r(t        d | j                  D              s| j                  S g }g }|| j                  z   }t        | j                        D ]@  \  }\  }\  }	}
}|	t        j                  k(  r|
}n|	t        j                  k(  rt        |t              r|j                         }nHt        j                  |dt        d       t        t         j"                  t         j$                  f      }|t        t&        j(                  t&        j$                  f      z  r}d}t&        j(                  |v r&|j+                  d|xr || j,                  k(        d   }t&        j$                  |v r.|r||kD  r'|j+                  |f|xr || j,                  k(        d   }|}nyt        j                  d| d|	 d	| d
t&        j$                  j/                          d	t        d       |j+                  |f|xr || j,                  k(        d   }n| j0                  }||| j                  z   k  r|| j,                  kD  r n]|j3                  |       ||| j                  z   z  }|	t        j                  t        j                  hvs.|j3                  |
|f       C t        |      D ]5  \  }}|dk\  r n+||| j                  z   z  }d||<   |s'|d   d   |k(  s3|d= 7 |rwt5        d |D              }|t7        |      | j0                  z  z   }t9        |      D ]<  \  }}t;        t=        ||z  |z  dz         | j0                        }
|
||<   ||
z  }||z  }> || _         || _        |S )z~
        Return a list of column widths.

        0 values in the list means hide the corresponding column completely
        r   c              3  P   K   | ]  \  }\  }}}|t         j                  k(     y wr1   )r   rt   r   s        r&   r6   z(Columns.column_widths.<locals>.<genexpr>  s'     3k\QPYQRTUWXA4H3ks   $&rf   r-   r.   r$   zUnusual widget z sizing for z (box=z#). Assuming wrong sizing and using z for width calculationr   c              3  &   K   | ]	  \  }}|  y wr1   r$   )r4   weightr   s      r&   r6   z(Columns.column_widths.<locals>.<genexpr>  s     :IFA:r         ?)r{   r   r:   rh   rw   rA   r   rF   rt   rq   r   rB   rH   rI   r(   r;   r<   r2   r=   r   r?   packrx   upperrz   rs   sumru   rN   maxr   )rO   sizer   maxcolwidthsweightedsharedr   r   r   r   r   static_wr^   candidate_sizewidth_wtotalgrowr   s                      r&   column_widthszColumns.column_widths  sU    aT'''3k]a]j]j3k0k,,,$***%.t}}%= (	,!A!=AuaJ$$$ joo%a( xxzHMMQE)9":NWXY(%))UZZ)@AHiv{{(CDD%&N||x/)*E4Va4CVCV>V)WXY)Z{{h..[aJa)*	5;]Q$J]J]E])^_`)a-H MM)!L6! E;;A;;;L;L;N:OOeg&#$	  !vvvi1S1@S@S;STUVWH  >>4#3#333D<O<O8OMM(#h!1!111F)):??;;
+Q(	,V #6* 	 IAv{ft////FF1IHQKNa/QK	  :::FCMDNN::D#H- !	Cv 6 <=t~~N!q	& ! $$*!r%   c           
     t   i i i g }i }g }i }t        | j                        D ]  \  }\  }\  }}	}
|j                         }|xr || j                  k(  }|t        j
                  k(  r\|	|<   |
r|j                  |       ]t        j                  |v r|j                  |	f|      |<   |	f|<   t        d| d|
d|       |t        j                  k(  r9t        j                  |v r'|
s%|j                  d|      \  }}||<   ||<   d|<   |	dk  r&d|<   d|<   |
r|j                  |       d|<   t        j                  |v s|
rt        j                  |v r|j                  d|      \  }}n| j                  }|j                  |	g       j                  |||
|f       |j                  |	       |j                  |	|       t!        ||	   |      ||	<   t        d| d|
d|        |rt!        d |j#                         D              }|D ]k  }t!        t%        ||z  d	z         | j                        }||   D ]<  \  }}}
}||<   |
s|j                  |f|      |<   |f|<   ,|j                  |       > m st        d
| d      t!        j'                               }|D ]  }||<   |   |f|<    t)        fdt+        t-                    D              t)        fdt+        t-                    D              t)        fdt+        t-                    D              fS )5Get column widths, heights and render size parameterszUnsupported combination of r,   z for r$   r   r   )r   c              3  ,   K   | ]  \  }}||z    y wr1   r$   )r4   r   r   s      r&   r6   z2Columns._get_fixed_column_sizes.<locals>.<genexpr>]  s     *hmfe56>*hs   r   zNo height information for pack z	 as FIXEDc              3  (   K   | ]	  }|     y wr1   r$   )r4   rY   r   s     r&   r6   z2Columns._get_fixed_column_sizes.<locals>.<genexpr>s  s     <#&+<   c              3  (   K   | ]	  }|     y wr1   r$   r4   rY   heightss     r&   r6   z2Columns._get_fixed_column_sizes.<locals>.<genexpr>t       >3'#,>r  c              3  (   K   | ]	  }|     y wr1   r$   r4   rY   w_h_argss     r&   r6   z2Columns._get_fixed_column_sizes.<locals>.<genexpr>u       @C(3-@r  )rA   r:   rB   rx   r   rF   rs   r   r=   rowsr   rt   r?   r   rz   
setdefaultr   itemsr   valuesrr   rangeru   )rO   r   boxr   weightsweight_max_sizesr   rZ   r[   size_weightr]   r^   focusedr   heightmax_weighted_coefficientr   
max_heightrY   r  r  r   s                      @@@r&   _get_fixed_column_sizeszColumns._get_fixed_column_sizes&  se   
 "$"$HJDF+-=Ft}}=U '	j9A98K}}H8T%8%8 8GJ,,,'q	JJqM[[H,!'k^W!EGAJ#..HQK&)DYKuU[T^^cdjck'lmmjoo-&,,(2JSY &B 8v!q	#
 !q	
JJqM"&HQK(F<<8+$*KKG$<ME6 NNE##K4;;VQPW<XY{+ ++K?034D[4QSX0Y -"%@5QWPZZ_`f_g#hiiO'	jR '**hO_OeOeOg*h'h$* 	&C 86 AC GH$..Y2:62B &.FAvw %F1I!%+[[%7%C
',h

1&	& !@	RSS)*
 	6C%GCL#C[*5HSM	6
 <s6{);<<>%G*=>>@5X+?@@
 	
r%   c           
     \   |s| j                  |      S t        | j                  ||            }i i g }g }t        t	        || j
                              D ]k  \  }\  }\  }\  }	}
}t        |t              r|j                         }nHt        j                  |dt        d       t        t        j                  t        j                  f      }t!        |      dk(  r%t        j                  |v r|d   |<   ||d   f|<   |r|j#                  |       t        j                  |v r:|dkD  r(|j%                  |f|xr || j&                  k(        |<   nd|<   |f|<   |	t(        j*                  k(  r;|dkD  r*|j-                  d	|xr || j&                  k(        d   |<   nd|<   d	|<   [|j#                  |       n t!        |      dk(  rer`t/        j1                               }|rMt        j                  d
| d|D cg c]  }| j
                  |   d    c} d|dt        d       nd}n|d   }g ||D ]  }||<   ||   |f|<    |t        fdt3        t!                    D              t        fdt3        t!                    D              fS c c}w )r  r   )r   r   z is not Widget.r-   r.   rd   r   r   r$   zWidgets in columns z (zP) are BOX widgets not marked "box_columns" while FLOW render is requested (size=)c              3  (   K   | ]	  }|     y wr1   r$   r  s     r&   r6   z+Columns.get_column_sizes.<locals>.<genexpr>  r	  r  c              3  (   K   | ]	  }|     y wr1   r$   r  s     r&   r6   z+Columns.get_column_sizes.<locals>.<genexpr>  r  r  )r  rr   r   rA   r   r:   rq   r   rB   rH   rI   r(   r;   r   r=   r2   ru   rs   r  rx   r   rt   r   r   r  r  )rO   r   r   r   r  box_need_heightr   r   rZ   r[   r\   r]   r^   r  rY   r  r  s                  @@r&   get_column_sizeszColumns.get_column_sizesx  s    //e/<<t))t5)AB"$HJ%'GPQTU[]a]j]jQkGl 	*CACB AL&&&)!==?
/:NWXY$fkk6::%>?4yA~&**"8!!W
$d1g.

1(19!'eXu7YdFYFYAY!ZGAJ!"GAJ$hjoo-19!'R1S1@S@S;S!TUV!WGAJ!"GAJ   &&q)=	*@ t9> !12
"MM-o-> ?:IJQT]]1-a0JK Liimhppqs '#$ 
aJ+S+?+ 	6C%GCL#C[*5HSM	6
 >%G*=>>@5X+?@@
 	
 Ks   J)c                    |rt         |   ||      S | j                  ||      \  }}}t        |      | j                  t        t        |      dz
  d      z  z   t        |      fS )zGet packed sized for widget.r   r   )ri   r   r"  r   rw   r   ru   )rO   r   r   r   r  _r   s         r&   r   zColumns.pack  sd     7<e,,!224?Fd..S[1_a1HHH#g,WWr%   c                N   | j                  ||      \  }}}g }t        t        ||| j                              D ]v  \  }\  }}	\  }
}|dk  r|t	        |      dz
  k  r|| j
                  z  }|j                  |
j                  |	|xr | j                  |k(        || j                  |k(  |f       x |s(|rt        d|d   g |dd dd         S t        d      t        |      }|r<|j                         |d   k  r&|j                  d|d   |j                         z
         |S )z
        Render columns and return canvas.

        :param size: see :meth:`Widget.render` for details
        :param focus: ``True`` if this widget is in focus
        :type focus: bool
        r   r   r   NzNo data to render)r"  rA   r   r:   ru   rw   rs   renderrx   r	   r   r   colspad_trim_left_right)rO   r   r   r   r$  	size_argsdatar   r   w_sizer   canvass               r&   r'  zColumns.render  s>     $44T5A946*3C	4==4Y*Z 	&A&vv1z3v;?")))KKHHV5+MT5H5HA5MHN''1,		  "3Q48Q1BCC233D!FKKMDG+&&q$q'FKKM*ABr%   c                t     j                    j                     \  }}|j                         syt        |d      sy j	                  |d      \  }}}t        |       j                  k  ry|j                  | j                           x}-|\  }}|t         fd|d j                   D              z  }||fS y)z4Return the cursor coordinates from the focus widget.Nget_cursor_coordsTr  c              3  H   K   | ]  }|d kD  s	j                   |z     yw)r   N)rw   )r4   wcrO   s     r&   r6   z,Columns.get_cursor_coords.<locals>.<genexpr>  s%     ]rVX[\V\T%%*]s   
"")r:   rx   rv   hasattrr"  ru   r/  r   )	rO   r   r   r$  r   r*  coordsxys	   `        r&   r/  zColumns.get_cursor_coords  s    }}T0011||~q-.#44T4F9v;$---)))D4G4G*HIIFVDAq]V<Qd>Q>Q5R]]]Aa4Kr%   c                
   	 | j                  |d      \  }}}d}d}	t	        t        || j                              D ]  \  }
\  }\  }}|	|z   }|j                         r}|t        j                  k7  r"|t        j                  k(  s|	|kD  r
||
|	||f} nY|t        j                  k7  r|	|kD  r||d   z
  |	|z
  k  r n1|
|	||f}|t        j                  k7  r||k  r n|| j                  z   }	 |y|\  }
}	}}t        |d      rKt        |t              r t        t        d||	z
        ||	z
  dz
        }n|}|j!                  ||
   ||      du ry|
| _        || _        y# t        $ r}t        | j                  |||      |d}~ww xY w)	z
        Choose a selectable column to focus based on the coords.

        see :meth:`Widget.move_cursor_coords` for details
        Tr  Nr   rd   Fmove_cursor_to_coordsr   )r"  	Exceptionr   r:   rA   r   rv   r   RIGHTLEFTrw   r2  rq   r   minr   r7  rx   ry   )rO   r   colrowr   r$  r*  r   bestr4  r   r   r   r   endmove_xs                   r&   r7  zColumns.move_cursor_to_coords	  s   	E#'#8#8T#8#J FAy )23vt}}3M)N 	'%A%}8e)C||~%++%3%**+<CT\aa<D%++%!c'cDGma#g6M!S!|%++%#)d&&&A	'  <1c11-.#s#SC!G_cAgk:&&y|VSAUJG  	ET]]D#s;D	Es   E 	F$E==Fc           	     R   | j                  ||      \  }}}	d}
t        t        ||	| j                              D ]  \  }\  }}\  }}||
k  r y| j                  |   d   }|
|z   }||k\  r|| j                  z   }
@|xr | j
                  |k(  }t        |      r|dk(  r|j                         r|| _        t        |d      sLt        j                  |j                  j                   d|j                  j                   dt        d	        y|j                  |||||
z
  ||      c S  y)
z_
        Send event to appropriate column.
        May change focus on button 1 press.
        r  r   Fr   mouse_event.z is not subclass of Widgetrd   r.   )r"  rA   r   r:   rw   rx   r   rv   r2  rH   rI   r   r!   r    r   rB  )rO   r   eventbuttonr<  r=  r   r   r$  r*  r4  r   r   r,  r   r?  s                   r&   rB  zColumns.mouse_event;  s5     $44T4G9*3C	4==4Y*Z 	M&A&vv1Qwa #Ae)Ccz$***6d11Q6Ee$1&'#1m,{{--.a0D0D/EE_`& 
 ==aeLL-	M. r%   c                Z   | j                  |d      \  }}}| j                  | j                     \  }}t        |      | j                  k  ryd}|| j                     }t	        |d      re|j                  || j                           }t        |t              r7|| j                  | j                  z  z  }|t        |d| j                         z  }|| j                  }|L|j                         r<|dz  }|| j                  | j                  z  z  }|t        |d| j                         z  }|S )z-Return the pref col from the column in focus.Tr  r   Nget_pref_colrd   )r"  r:   rx   ru   r2  rG  rq   r   rw   r   ry   rv   )rO   r   r   r$  r*  r   r<  cwidths           r&   rG  zColumns.get_pref_cold  s&   #44T4F9}}T0011v;$---++,1n%..4+>+>!?@C#s#t**T-=-===s6"7D$7$7899;--C;1<<>A+C4&&)9)999C3v3 3 3455C
r%   c                L    | j                  ||      \  }}}|rt        dg| S y)z
        Return the number of rows required by the columns.
        This only makes sense if :attr:`widget_list` contains flow widgets.

        see :meth:`Widget.rows` for details
        r   )r"  r   )rO   r   r   r$  r  s        r&   r  zColumns.rows|  s2     --dE:7Aq#7##r%   c                >   | j                   |S | j                  |d      \  }}}| j                   t        |      k\  r|S | j                   }| j                  |   \  }}| j                  |   t
        j                  t
        j                  t
        j                  t
        j                  hvrd| _
        |j                         r|j                  ||   |      }| j                  |   t
        j                  t
        j                  hvr|S | j                  |   t
        j                  k(  rt        t!        |dz
  dd            }n+t        t!        |dz   t        | j                                    }|D ]+  }	| j                  |	   d   j                         s$|	| _          y |S )z
        Pass keypress to the focus column.

        :param size: Widget size correct for the supported sizing
        :type size: tuple[()] | tuple[int] | tuple[int, int]
        :param key: a single keystroke value
        :type key: str
        NTr  r   r   )rx   r"  ru   r:   _command_mapr
   UPDOWNPAGE_UP	PAGE_DOWNry   rv   keypressr:  r9  listr  )
rO   r   keyr   r$  r*  r   r   
candidatesjs
             r&   rQ  zColumns.keypress  sg    &J#44T4F9#f+-J}}Q1S!'**gllGOOU\UfUf)gg DM<<>**Yq\3/CS!',,)FFJS!W\\1eAE2r23JeAE3t}}+=>?J 	A==#A&113"#D	 
r%   )returnzfrozenset[Sizing])r   Nr   N)
r|   zIterable[Widget | tuple[Literal['pack', WHSettings.PACK] | int, Widget] | tuple[Literal['given', WHSettings.GIVEN], int, Widget] | tuple[Literal['weight', WHSettings.WEIGHT], int | float, Widget]]rw   r   r}   zint | Widget | Nonerz   r   r~   zIterable[int] | None)rV  z	list[str])rV  zdict[str, typing.Any])rV  z4Iterator[tuple[str | None, typing.Any] | typing.Any])rV  r   )rV  None)rV  r   )rV  r   )rV  zMonitoredFocusList[tuple[Widget, tuple[Literal[WHSettings.PACK], None, bool] | tuple[Literal[WHSettings.GIVEN], int, bool] | tuple[Literal[WHSettings.WEIGHT], int | float, bool]],])r   zSequence[Widget, tuple[Literal[WHSettings.PACK], None, bool] | tuple[Literal[WHSettings.GIVEN], int, bool] | tuple[Literal[WHSettings.WEIGHT], int | float, bool]]rV  rW  )r   zXLiteral['pack', 'given', 'weight', WHSettings.PACK, WHSettings.GIVEN, WHSettings.WEIGHT]r   zint | float | Noner   r   rV  ztuple[Literal[WHSettings.PACK], None, bool] | tuple[Literal[WHSettings.GIVEN], int, bool] | tuple[Literal[WHSettings.WEIGHT], int | float, bool])r   r   rV  rW  )r   zWidget | intrV  rW  )rV  zWidget | None)rV  z
int | None)r   r   rV  rW  )F)r   ztuple[int] | tuple[int, int]r   r   rV  z	list[int])r   r   rV  zEtuple[Sequence[int], Sequence[int], Sequence[tuple[int] | tuple[()]]])r   z(tuple[int, int] | tuple[int] | tuple[()]r   r   rV  zWtuple[Sequence[int], Sequence[int], Sequence[tuple[int, int] | tuple[int] | tuple[()]]])r$   F)r   (tuple[()] | tuple[int] | tuple[int, int]r   r   rV  ztuple[int, int])r   rX  r   r   rV  zSolidCanvas | CompositeCanvas)r   rX  rV  ztuple[int, int] | None)r   rX  r<  zint | Literal['left', 'right']r=  r   rV  r   )r   rX  rD  strrE  r   r<  r   r=  r   r   r   rV  zbool | None)r   rX  rV  r   )r   z
tuple[int]r   r   rV  r   )r   rX  rS  rY  rV  z
str | None)+r    r!   r"   r#   rB   rj   r   r   r   r   rm   rp   propertyr|   setterr   r~   r   r:   staticmethodr   rD   r   ra   r   r   r   r   r   rx   r   r   r  r"  r   r'  r/  r7  rB  rG  r  rQ  __classcell__)r   s   @r&   r*   r*       s   d$\ ,0,0X"
X" X" *X" X" *X"t98)4#L&  * 1 1&  2 1 1   , l l 	4 	4 
 
 
 & __	
	 
	 	  +, $m
$m )	$m
 $m	?$m $mL"$#L0 
5 
55$ # # ' ' # #" + +Ph P
P
 
OP
j G
6G
 G
 
a	G
V :<	X6	X 	X 
		X '6' ' 
'	'R(060 ,0 	0
 
0d'6' ' 	'
 ' ' ' 
'R0
)6) ) 
	)r%   r*   ),
__future__r   typingrH   	itertoolsr   r   r<   urwid.canvasr   r   r   r	   urwid.command_mapr
   urwid.split_reprr   
urwid.utilr   	constantsr   r   r   	containerr   r   r   monitored_listr   r   rZ   r   r   r   TYPE_CHECKINGcollections.abcr   r   r   typing_extensionsr   r   r(   r*   r$   r%   r&   <module>rk     sv    "   #  I I % , % 0 0 j j = 6 6	<<)"; "$] $Qf*,L Qr%   