
    jj                        d dl mZ d dlZddlmZ ddl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 dd
lmZmZ ej(                  rd dlmZ ddlmZ  ej2                  d      Z G d dee    ed            Zy)    )annotationsN   )Columns)BOX_SYMBOLSAlign
WHSettings)Divider)Pile)	SolidFill)Text)WidgetDecorationdelegate_to_widget_mixin)Literal)WidgetWrappedWidgetc                  .    e Zd ZeZdej                  dej                  j                  ej                  j                  ej                  j                  ej                  j                  ej                  j                  ej                  j                  ej                  j                  ej                  j                  f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
 fdZed fd       Zej"                  dd       Zedd       ZddZddZedd	       Z xZS )LineBox Nc           
     t   t        |      }t        |
      }t        |      t        |      t        |      }}}t        |	      t        |      t        |      }}}|s|rt        d      |r"t        || j	                  |      f      | _        nt        | j	                  |            | _        |r	|t        j                  t        j                  t        j                  hvrt        d      |t        j                  k(  rt        j                  | j
                  f|g}nB|t        j                  | j
                  fg}|t        j                  k(  r|j                  |       t        |      | _        t        t        t!        |xr |            |f| j                  t        t!        |xr |
            |ff      }n	d| _        d}t        t        t!        |            |f|t        t!        |
            |ffddg|      }|r?t        t        t!        |	xr |            |f|t        t!        |xr |
            |ff      }nd}g }|r!|j                  t        j                  |f       |j                  |       |r!|j                  t        j                  |f       t#        ||      | _        t&        | Q  |       y)u	  
        Draw a line around original_widget.

        Use 'title' to set an initial title text with will be centered
        on top of the box.

        Use `title_attr` to apply a specific attribute to the title text.

        Use `title_align` to align the title to the 'left', 'right', or 'center'.
        The default is 'center'.

        You can also override the widgets used for the lines/corners:
            tline: top line
            bline: bottom line
            lline: left line
            rline: right line
            tlcorner: top left corner
            trcorner: top right corner
            blcorner: bottom left corner
            brcorner: bottom right corner

        If empty string is specified for one of the lines/corners, then no character will be output there.
        If no top/bottom/left/right lines - whole lines will be omitted.
        This allows for seamless use of adjoining LineBoxes.

        Class attribute `Symbols` can be used as source for standard lines:

        >>> print(LineBox(Text("Some text")).render(()))
        ┌─────────┐
        │Some text│
        └─────────┘
        >>> print(
        ...     LineBox(
        ...         Text("Some text"),
        ...         tlcorner=LineBox.Symbols.LIGHT.TOP_LEFT_ROUNDED,
        ...         trcorner=LineBox.Symbols.LIGHT.TOP_RIGHT_ROUNDED,
        ...         blcorner=LineBox.Symbols.LIGHT.BOTTOM_LEFT_ROUNDED,
        ...         brcorner=LineBox.Symbols.LIGHT.BOTTOM_RIGHT_ROUNDED,
        ...     ).render(())
        ... )
        ╭─────────╮
        │Some text│
        ╰─────────╯
        >>> print(
        ...     LineBox(
        ...         Text("Some text"),
        ...         tline=LineBox.Symbols.HEAVY.HORIZONTAL,
        ...         bline=LineBox.Symbols.HEAVY.HORIZONTAL,
        ...         lline=LineBox.Symbols.HEAVY.VERTICAL,
        ...         rline=LineBox.Symbols.HEAVY.VERTICAL,
        ...         tlcorner=LineBox.Symbols.HEAVY.TOP_LEFT,
        ...         trcorner=LineBox.Symbols.HEAVY.TOP_RIGHT,
        ...         blcorner=LineBox.Symbols.HEAVY.BOTTOM_LEFT,
        ...         brcorner=LineBox.Symbols.HEAVY.BOTTOM_RIGHT,
        ...     ).render(())
        ... )
        ┏━━━━━━━━━┓
        ┃Some text┃
        ┗━━━━━━━━━┛

        To make Table constructions, some lineboxes need to be drawn without sides
        and T or CROSS symbols used for corners of cells.
        z.Cannot have a title when tline is empty stringz7title_align must be one of "left", "right", or "center"Nr      )box_columnsfocus_column)
focus_item)r   r   r	   
ValueErrorformat_titletitle_widgetr   LEFTCENTERRIGHTr   PACKappendr   tline_widgetintboolr
   _wrapped_widgetsuper__init__)selforiginal_widgettitletitle_align
title_attrtlcornertlinellinetrcornerblcornerrlineblinebrcornerw_llinew_rline
w_tlcornerw_tline
w_trcorner
w_blcornerw_bline
w_brcornertline_widgetstopmiddlebottompile_widgets	__class__s                             ^/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/urwid/widget/line_box.pyr'   zLineBox.__init__   sd   ^ E"E"*.x.'%.$x.ZG
*.x.'%.$x.ZG
MNN $j$2C2CE2J%K LD $T%6%6u%= >D5::u||U[["II !Z[[ejj(",//43D3D!Ew O!(:??D<M<M*N O%,,.!((1 ' 6Dh0512J?%%h0512J?C !%DC $u+(/CU<Lg;VWA(
 h0512J?h0512J?F F# 67F#& 9:#LVD)    c                    t         |   S N)r&   r)   )r(   rB   s    rC   r)   zLineBox.original_widget   s    w&&rD   c                   t        t        | j                              }d}t        j                  d| j
                  |         }|j                  |   \  }}||f|j                  |<   t        j                  j                  | |       y )Nr   r   )
r#   r$   r"   typingcastr%   contentsr   r)   fset)r(   r)   v_indexh_indexr?   _old_widgetoptionss          rC   r)   zLineBox.original_widget   ss    d4,,-. ++i1E1Eg1NO%w7W$3W#= ((--dODrD   c                    | j                   S rF   )r%   r(   s    rC   _wz
LineBox._w   s    ###rD   c                    |rd| dS y)N r    r(   texts     rC   r   zLineBox.format_title   s    tfA;rD   c                    | j                   st        d      | j                  j                  | j	                  |             | j                   j                          y )Nz$Cannot set title when tline is unset)r"   r   r   set_textr   _invalidaterV   s     rC   	set_titlezLineBox.set_title   sH      CDD""4#4#4T#:;%%'rD   c                .    | j                   j                  S )zLineBox is partially container.

        While focus position is a bit hacky
        (formally it's not container and only position 0 available),
        focus widget is always provided by original widget.
        )_original_widgetfocusrQ   s    rC   r^   zLineBox.focus   s     $$***rD   )r)   r   r*   strr+   z*Literal['left', 'center', 'right'] | Alignr-   r_   r.   r_   r/   r_   r0   r_   r1   r_   r2   r_   r3   r_   r4   r_   returnNone)r`   r   )r)   r   r`   ra   )r`   r
   )rW   r_   r`   r_   )rW   r_   r`   ra   )r`   zWidget | None)__name__
__module____qualname__r   Symbolsr   r   LIGHTTOP_LEFT
HORIZONTALVERTICAL	TOP_RIGHTBOTTOM_LEFTBOTTOM_RIGHTr'   propertyr)   setterrR   r   r[   r^   __classcell__)rB   s   @rC   r   r      s{   G
 BG,,#))22 &&11 &&//#))33#))55 &&// &&11#))66P*&P* P* @	P* P* P* P* P* P* P* P* P* 
P*d ' ' E E $ $( + +rD   r   r%   )
__future__r   rH   columnsr   	constantsr   r   r   dividerr	   piler
   
solid_fillr   rW   r   widget_decorationr   r   TYPE_CHECKINGtyping_extensionsr   widgetr   TypeVarr   r   rU   rD   rC   <module>r{      s_    "   5 5   !  I	)/z+}-/GHY/Z z+rD   