
    jj                        d dl 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 ej                  rd dlmZ d dlmZ  G d	 d
e      Zy)    )annotationsN   )BAR_SYMBOLSAlignSizingWrapMode)Text)Widget)Hashable)
TextCanvasc                      e Zd Z eej
                  g      Zej                  dd Z	e
j                  Z	 	 	 d	 	 	 	 	 	 	 	 	 	 	 d fdZddZ ed e      Zed        Zej$                  d        ZdddZdd	Z	 d	 	 	 	 	 dd
Z xZS )ProgressBarN   c                h    t         |           || _        || _        || _        || _        || _        y)u:  
        :param normal: display attribute for incomplete part of progress bar
        :param complete: display attribute for complete part of progress bar
        :param current: current progress
        :param done: progress amount at 100%
        :param satt: display attribute for smoothed part of bar where the
                     foreground of satt corresponds to the normal part and the
                     background corresponds to the complete part.
                     If satt is ``None`` then no smoothing will be done.

        >>> from urwid import LineBox
        >>> pb = ProgressBar("a", "b")
        >>> pb
        <ProgressBar flow widget>
        >>> print(pb.get_text())
        0 %
        >>> pb.set_completion(34.42)
        >>> print(pb.get_text())
        34 %
        >>> class CustomProgressBar(ProgressBar):
        ...     def get_text(self):
        ...         return "Foobar"
        >>> cpb = CustomProgressBar("a", "b")
        >>> print(cpb.get_text())
        Foobar
        >>> for x in range(101):
        ...     cpb.set_completion(x)
        ...     s = cpb.render((10,))
        >>> cpb2 = CustomProgressBar("a", "b", satt="c")
        >>> for x in range(101):
        ...     cpb2.set_completion(x)
        ...     s = cpb2.render((10,))
        >>> pb = ProgressBar("a", "b", satt="c")
        >>> pb.set_completion(34.56)
        >>> print(LineBox(pb).render((20,)))
        ┌──────────────────┐
        │      ▏34 %       │
        └──────────────────┘
        N)super__init__normalcomplete_current_donesatt)selfr   r   currentdoner   	__class__s         b/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/urwid/widget/progress_bar.pyr   zProgressBar.__init__   s4    ^ 	 
	    c                2    || _         | j                          y)z-
        current -- current progress
        N)r   _invalidate)r   r   s     r   set_completionzProgressBar.set_completionL   s      r   c                    | j                   S N)r   r   s    r   <lambda>zProgressBar.<lambda>S   s
    DMM r   c                    | j                   S r"   )r   r#   s    r   r   zProgressBar.doneU   s    zzr   c                2    || _         | j                          y)z1
        done -- progress amount at 100%
        N)r   r   )r   r   s     r   r   zProgressBar.doneY   s    
 
r   c                     y)Nr    )r   sizefocuss      r   rowszProgressBar.rowsa   s    r   c           
     ~    t        dt        dt        | j                  dz  | j                  z                    }|dS )zw
        Return the progress bar percentage text.
        You can override this method to display custom text.
        d   r   z %)minmaxintr   r   )r   percents     r   get_textzProgressBar.get_textd   s;    
 c3q#dllS&8499&D"EFGBr   c                   |\  }t        | j                         | j                  t        j                        j                  |f      }t        | j                        |z  | j                  z  }t        |      }t        |j                  d   d| j                  dd      j                  d            }d}| j                  t        ||z
  dz        }|dk  s||cxk(  rdk(  rn n| j                  |fgg|_        |S ||k\  r| j"                  |fgg|_        |S |r|j                  d   |   dk(  r|j                  d   }	| j$                  |   j                  d      }
|	d| |
z   |	|dz   d z   |j                  d<   g }|dkD  r|j'                  | j"                  |f       |j'                  | j                  t        |
      f       ||z
  dz
  dkD  r#|j'                  | j                  ||z
  dz
  f       |g|_        dt        |j                  d         fgg|_        |S | j"                  |f| j                  ||z
  fgg|_        |S )z*
        Render the progress bar.
        r   Nzutf-8ignorer       r   )r	   r2   
text_alignr   CLIPrenderfloatr   r   r0   len_textdecodeencoder   r   _attrr   eighthsappend_cs)r   r)   r*   maxcolccf
ccol_dirtyccolcstcencas               r   r8   zProgressBar.renderl   s'    	$//8==AHH&S4<< 6)DII5W
1771:kz*11'8DKKGTU99 b4i1_%B!8af-./AG" ! V^/01AG  AGGAJt$*
A<<#**73D5DD1TAXZ=8AGGAJAax$--./HHdiiT+,}q 1$$++v}q'89:cAGS_-./AE  -Vd]/KLMAGr   )r   r-   N)r   Hashable | Noner   rK   r   r0   r   r0   r   rK   returnNone)r   r0   rL   rM   )F)r)   
tuple[int]r*   boolrL   r0   )rL   str)r)   rN   r*   rO   rL   r   )__name__
__module____qualname__	frozensetr   FLOW_sizingr   
HORISONTALr?   r   CENTERr6   r   r    propertyr   r   setterr+   r2   r8   __classcell__)r   s   @r   r   r      s    &G$$Ra(GJ  $44 "4 	4
 4 4 
4l 1>BG  
[[   $$ $ 
	$r   r   )
__future__r   typing	constantsr   r   r   r   textr	   widgetr
   TYPE_CHECKINGcollections.abcr   urwid.canvasr   r   r(   r   r   <module>rd      s4    "  ; ;  	('A& Ar   