o
    Mf6                     @   sx  d dl 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mZmZmZmZmZmZ ddlmZ ddlm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$ ddl%m&Z& ddl'm(Z( ddl)m*Z* e
r|d dl+m,Z, G dd deZ-ede&f Z.ede-f Z/G dd de0Z1G dd de1Z2G dd dZ3G dd deZ4G dd de4Z5G dd  d e4Z6e#G d!d dZ7e8d"kr:d d#l9mZ e Ze7 Z:e:;e7d$d%d&e7dd'd(e7d)d*d+ e:d' <e7d,d-e7d.d/d0 e:d. <e7d1d/d0e7d2d- e:d2 ;e7d3d-e7d4d-e7d5d- e:d, ;e7e:j=d6d-e7d7d- e:d1 >d8 e?e: d9S d9S ):    )ABCabstractmethod)islice)
itemgetter)RLock)	TYPE_CHECKINGDictIterableList
NamedTupleOptionalSequenceTupleUnion   )ratio_resolve)Align)ConsoleConsoleOptionsRenderableTypeRenderResult)ReprHighlighter)Panel)Pretty)	rich_reprResult)Region)Segment)	StyleTypeTreec                   @   s*   e Zd ZU dZeed< eee  ed< dS )LayoutRenderzAn individual layout render.regionrenderN)__name__
__module____qualname____doc__r   __annotations__r
   r    r)   r)   Y/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/pip/_vendor/rich/layout.pyr!       s   
 r!   Layoutc                   @      e Zd ZdZdS )LayoutErrorzLayout related error.Nr$   r%   r&   r'   r)   r)   r)   r*   r-   +       r-   c                   @   r,   )
NoSplitterz"Requested splitter does not exist.Nr.   r)   r)   r)   r*   r0   /   r/   r0   c                   @   sD   e Zd ZdZe Zddddeddfdd	Zd
ede	de
fddZdS )_Placeholderz4An internal renderable used as a Layout placeholder. layoutr+   stylereturnNc                 C   s   || _ || _d S N)r3   r4   )selfr3   r4   r)   r)   r*   __init__8   s   
z_Placeholder.__init__consoleoptionsc                 c   sx    |j }|jp
|jj}| j}|jr|jd| d| dnd| d| d}ttjt|dd| j	| 
|ddV  d S )	Nz (z x )(middle)verticalblue)r4   titleborder_style)	max_widthheightsizer3   namer   r   centerr   r4   highlighter)r7   r9   r:   widthrC   r3   r@   r)   r)   r*   __rich_console__<   s   z_Placeholder.__rich_console__)r2   )r$   r%   r&   r'   r   rG   r   r8   r   r   r   rI   r)   r)   r)   r*   r1   3   s    r1   c                
   @   sZ   e Zd ZU dZdZeed< edefddZede	d d	e
deede
f  fd
dZdS )SplitterzBase class for a splitter.r2   rE   r5   c                 C      dS )z(Get the icon (emoji) used in layout.treeNr)   r7   r)   r)   r*   get_tree_iconT       zSplitter.get_tree_iconchildrenr+   r"   c                 C   rK   )zDivide a region amongst several child layouts.

        Args:
            children (Sequence(Layout)): A number of child layouts.
            region (Region): A rectangular region to divide.
        Nr)   )r7   rO   r"   r)   r)   r*   divideX   rN   zSplitter.divideN)r$   r%   r&   r'   rE   strr(   r   rM   r   r   r	   r   rP   r)   r)   r)   r*   rJ   O   s   
 rJ   c                	   @   H   e Zd ZdZdZdefddZded dede	e
def  fd	d
ZdS )RowSplitterz!Split a layout region in to rows.rowr5   c                 C   rK   )Nu   [layout.tree.row]⬌r)   rL   r)   r)   r*   rM   i      zRowSplitter.get_tree_iconrO   r+   r"   c                 c   sX    |\}}}}t ||}d}t}	t||D ]\}
}|
|	|| |||fV  ||7 }qd S Nr   r   r   zip)r7   rO   r"   xyrH   rC   render_widthsoffset_Regionchildchild_widthr)   r)   r*   rP   l      

zRowSplitter.divideNr$   r%   r&   r'   rE   rQ   rM   r   r   r	   r   rP   r)   r)   r)   r*   rS   d       rS   c                	   @   rR   )ColumnSplitterz$Split a layout region in to columns.columnr5   c                 C   rK   )Nu   [layout.tree.column]⬍r)   rL   r)   r)   r*   rM   }   rU   zColumnSplitter.get_tree_iconrO   r+   r"   c                 c   sX    |\}}}}t ||}d}t}	t||D ]\}
}|
|	||| ||fV  ||7 }qd S rV   rW   )r7   rO   r"   rY   rZ   rH   rC   render_heightsr\   r]   r^   child_heightr)   r)   r*   rP      r`   zColumnSplitter.divideNra   r)   r)   r)   r*   rc   x   rb   rc   c                   @   s  e Zd ZdZeedZ	d=ddddddddee dee	 d	ee
 d
e
de
dedee
 ddfddZdefddZedefddZeded  fddZedefddZde	ded  fddZde	dd fddZed>ddZd d!d"ed ef d#eee	f ddfd$d%Zd"ed ef ddfd&d'Zd"ed ef ddfd(d)Zd"ed ef ddfd*d+Zd?d,d-Zdeddfd.d/Zd0d1d2e	ddfd3d4Z d5e
de
de!fd6d7Z"d0e#d8e$defd9d:Z%d0e#d8e$de&fd;d<Z'dS )@r+   aB  A renderable to divide a fixed height in to rows or columns.

    Args:
        renderable (RenderableType, optional): Renderable content, or None for placeholder. Defaults to None.
        name (str, optional): Optional identifier for Layout. Defaults to None.
        size (int, optional): Optional fixed size of layout. Defaults to None.
        minimum_size (int, optional): Minimum size of layout. Defaults to 1.
        ratio (int, optional): Optional ratio for flexible layout. Defaults to 1.
        visible (bool, optional): Visibility of layout. Defaults to True.
    )rT   rd   Nr   T)rE   rD   minimum_sizeratiovisiblerC   
renderablerE   rD   rg   rh   ri   rC   r5   c                C   sX   |pt | | _|| _|| _|| _|| _|| _|| _| jd  | _	g | _
i | _t | _d S )Nrd   )r1   _renderablerD   rg   rh   rE   ri   rC   	splitterssplitter	_children_render_mapr   _lock)r7   rj   rE   rD   rg   rh   ri   rC   r)   r)   r*   r8      s   zLayout.__init__c                 c   s>    d| j d fV  d| jd fV  d| jdfV  d| jdfV  d S )NrE   rD   rg   r   rh   )rE   rD   rg   rh   rL   r)   r)   r*   __rich_repr__   s
   zLayout.__rich_repr__c                 C   s   | j r| S | jS )zLayout renderable.)rn   rk   rL   r)   r)   r*   rj         zLayout.renderablec                 C   s   dd | j D S )zGets (visible) layout children.c                 S   s   g | ]}|j r|qS r)   )ri   ).0r^   r)   r)   r*   
<listcomp>   s    z#Layout.children.<locals>.<listcomp>rn   rL   r)   r)   r*   rO      rr   zLayout.childrenc                 C   s   | j S )zGet a map of the last render.)ro   rL   r)   r)   r*   map   s   z
Layout.mapc                 C   s8   | j |kr| S | jD ]}||}|dur|  S q
dS )zGet a named layout, or None if it doesn't exist.

        Args:
            name (str): Name of layout.

        Returns:
            Optional[Layout]: Layout instance or None if no layout was found.
        N)rE   rn   get)r7   rE   r^   named_layoutr)   r)   r*   rw      s   
	

z
Layout.getc                 C   s$   |  |}|d u rtd||S )NzNo layout with name )rw   KeyError)r7   rE   r3   r)   r)   r*   __getitem__   s   
zLayout.__getitem__r    c                    sz   ddl m  ddlm ddlm} dddf fdd	| }||d
|jj dd}dfdd||  |S )z/Get a tree renderable to show layout structure.r   )Styled)Tabler   r3   r+   r5   c                    sF   | j  }jdd}| jrt| n t| d}||| |}|S )N)r   r   r   r   )paddingdim)rm   rM   gridri   r   add_row)r3   icontabletext_summary)r{   r|   r)   r*   summary   s   
zLayout.tree.<locals>.summarylayout.tree.T)guide_style	highlighttreer    Nc                    s2   |j D ]} | j|d|jj d| qd S )Nr   )r   )rn   addrm   rE   )r   r3   r^   )recurser   r)   r*   r      s   
zLayout.tree.<locals>.recurse)r   r    r3   r+   r5   N)pip._vendor.rich.styledr{   pip._vendor.rich.tabler|   pip._vendor.rich.treer    rm   rE   )r7   r    r3   r   r)   )r{   r|   r   r   r*   r      s   

zLayout.treerd   )rm   layoutsrm   c                G   s^   dd |D }zt |tr|n| j|  | _W n ty%   td|w || jdd< dS )zSplit the layout in to multiple sub-layouts.

        Args:
            *layouts (Layout): Positional arguments should be (sub) Layout instances.
            splitter (Union[Splitter, str]): Splitter instance or name of splitter.
        c                 S   s"   g | ]}t |tr|nt|qS r)   
isinstancer+   rs   r3   r)   r)   r*   rt     s    z Layout.split.<locals>.<listcomp>zNo splitter called N)r   rJ   rl   rm   ry   r0   rn   )r7   rm   r   _layoutsr)   r)   r*   split  s   
zLayout.splitc                 G   s   dd |D }| j | dS )zAdd a new layout(s) to existing split.

        Args:
            *layouts (Union[Layout, RenderableType]): Positional arguments should be renderables or (sub) Layout instances.

        c                 s   s&    | ]}t |tr|nt|V  qd S r6   r   r   r)   r)   r*   	<genexpr>'  s
    
z#Layout.add_split.<locals>.<genexpr>N)rn   extend)r7   r   r   r)   r)   r*   	add_split   s   zLayout.add_splitc                 G      | j |ddi dS )zSplit the layout in tow a row (Layouts side by side).

        Args:
            *layouts (Layout): Positional arguments should be (sub) Layout instances.
        rm   rT   Nr   r7   r   r)   r)   r*   	split_row-     zLayout.split_rowc                 G   r   )zSplit the layout in to a column (layouts stacked on top of each other).

        Args:
            *layouts (Layout): Positional arguments should be (sub) Layout instances.
        rm   rd   Nr   r   r)   r)   r*   split_column5  r   zLayout.split_columnc                 C   s   | j dd= dS )zReset splits to initial state.Nru   rL   r)   r)   r*   unsplit=  s   zLayout.unsplitc                 C   s2   | j  || _W d   dS 1 sw   Y  dS )zjUpdate renderable.

        Args:
            renderable (RenderableType): New renderable object.
        N)rp   rk   )r7   rj   r)   r)   r*   updateA  s   "zLayout.updater9   r   layout_namec                 C   s   | j 4 | | }| j| \}}|\}}}}	|||j||	}
t||
| j|< ||
|| W d   dS 1 s:w   Y  dS )zRefresh a sub-layout.

        Args:
            console (Console): Console instance where Layout is to be rendered.
            layout_name (str): Name of layout.
        N)rp   ro   render_linesr:   update_dimensionsr!   update_screen_lines)r7   r9   r   r3   r"   _linesrY   rZ   rH   rC   linesr)   r)   r*   refresh_screenJ  s   "zLayout.refresh_screenrH   c                 C   s   | t dd||fg}|j}|j}g }|j}|r7||  |d \}}	|j}
|
r5|j|
|	D ]}|| q.|sdd t|tddD }|S )z,Create a dict that maps layout on to Region.r   c                 S   s   i | ]\}}||qS r)   r)   rs   r3   r"   r)   r)   r*   
<dictcomp>j  s    z+Layout._make_region_map.<locals>.<dictcomp>r   )key)r   appendpoprO   rm   rP   sortedr   )r7   rH   rC   stackpushr   layout_regionsappend_layout_regionr3   r"   rO   child_and_region
region_mapr)   r)   r*   _make_region_map[  s"   

zLayout._make_region_mapr:   c                 C   sv   |j }|jp|j}| ||}dd | D }i }|j}|j}	|D ]\}
}||
j|	|j|j}t||||
< q"|S )zRender the sub_layouts.

        Args:
            console (Console): Console instance.
            options (ConsoleOptions): Console options.

        Returns:
            RenderMap: A dict that maps Layout on to a tuple of Region, lines
        c                 S   s   g | ]\}}|j s||fqS r)   )rO   r   r)   r)   r*   rt   }  s    z!Layout.render.<locals>.<listcomp>)	rB   rC   r   itemsr   r   rj   rH   r!   )r7   r9   r:   render_widthrender_heightr   r   
render_mapr   r   r3   r"   r   r)   r)   r*   r#   p  s   
zLayout.renderc                 c   s    | j b |jp
|j}|jp|j}| ||||}|| _dd t|D }t}|	 D ]\}}	|\}
}}}t
||||| |	D ]	\}}|| qBq-t }|D ]
}|E d H  |V  qSW d    d S 1 siw   Y  d S )Nc                 S   s   g | ]}g qS r)   r)   )rs   _r)   r)   r*   rt     s    z+Layout.__rich_console__.<locals>.<listcomp>)rp   rB   rH   rC   r#   r   ro   ranger   valuesrX   r   r   line)r7   r9   r:   rH   rC   r   layout_lines_islicer"   r   _xrZ   _layout_widthlayout_heightrT   r   new_line
layout_rowr)   r)   r*   rI     s*   
"zLayout.__rich_console__r6   )r5   r    )r5   N)(r$   r%   r&   r'   rS   rc   rl   r   r   rQ   intboolr8   r   rq   propertyrj   r
   rO   	RenderMaprv   rw   rz   r   r   rJ   r   r   r   r   r   r   r   	RegionMapr   r   r   r#   r   rI   r)   r)   r)   r*   r+      s|    
	

*



	__main__)r   header   )rE   rD   main)rh   rE   
   footer)rD   rE   side)rE   body   )rE   rh   contents2topr=   bottomleft1left2fooN)@abcr   r   	itertoolsr   operatorr   	threadingr   typingr   r   r	   r
   r   r   r   r   r   _ratior   alignr   r9   r   r   r   r   rG   r   panelr   prettyr   reprr   r   r"   r   segmentr   r4   r   r   r    r!   r   r   	Exceptionr-   r0   r1   rJ   rS   rc   r+   r$   pip._vendor.rich.consoler3   r   r   r   r   printr)   r)   r)   r*   <module>   s`    ,  



 