
    ;OOf                        d dl mZmZ d dlmZmZ d dlmZmZ d dl	m
Z
mZmZmZmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZm Z  d dl!m"Z" d dl#m$Z$  G d	 d
e      Z% G d de$e      Z& G d de      Z'd Z( G d de)      Z* G d d ee'e            Z+d Z, G d de      Z-d Z. G d de      Z/ G d de      Z0d Z1e2dk(  r e1        yy)    )divisionprint_function)ord2with_metaclass)decompose_tagmarkupget_encoding_mode)CompositeCanvas
CanvasJoin
TextCanvasCanvasCombineSolidCanvas)
WidgetMetaWidgetBOXFIXEDFLOWnocache_widget_rendernocache_widget_render_instance
fixed_size
WidgetWrapDivider	SolidFillTextCENTERCLIP)PileColumns)AttrSpec)WidgetDecorationc                   F    e Zd Z eeg      Zd Zd Zd Zd Z	ddZ
d	dZy)
BigTextc                 H    | j                  |       | j                  |       y)z_
        markup -- same as Text widget markup
        font -- instance of a Font class
        N)set_fontset_text)selfmarkupfonts      O/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/urwid/graphics.py__init__zBigText.__init__(   s    
 	df    c                 T    t        |      \  | _        | _        | j                          y N)r   textattrib_invalidate)r%   r&   s     r(   r$   zBigText.set_text0   s!    !4V!<	4;r*   c                 2    | j                   | j                  fS )z-
        Returns (text, attributes).
        )r-   r.   r%   s    r(   get_textzBigText.get_text4   s     yy$++%%r*   c                 2    || _         | j                          y r,   )r'   r/   )r%   r'   s     r(   r#   zBigText.set_font:   s    	r*   Nc                     | j                   j                  }d}| j                  D ]   }|| j                   j                  |      z  }" ||fS Nr   )r'   heightr-   
char_width)r%   sizefocusrowscolscs         r(   packzBigText.pack>   sL    yy 	,ADII((++D	,Tzr*   c                 <   t        |       d }dx}}g }| j                  j                  }| j                  d t	        | j
                        fgz   }| j
                  D ]  }	|s||   \  }}|dz  }|dz  }| j                  j                  |	      }
|
s5| j                  j                  |	      }|t        |      }|j                  |       |j                  |d d|
f        |rt        |      }nt        dg|z  dd      }t        |      }|j                  g        |S )Nr      F )maxcolcheck_width)r   r'   r6   r.   lenr-   r7   renderr	   	fill_attrappendr
   r   set_depends)r%   r8   r9   aaiakor:   r.   chwidthr<   canvs                r(   rD   zBigText.renderE   s   4Ryys499~ 677)) 	.Br
2a!GBII((,E		  $A}#A&AHHaue,-	. a=DrdTk!*/1D"4(Dr*   NFF)__name__
__module____qualname__	frozensetr   _sizingr)   r$   r2   r#   r=   rD    r*   r(   r!   r!   %   s,     G&r*   r!   c                   2    e Zd Z	 	 	 	 	 ddZd Zd ZddZy)LineBoxNc                    |rt        |      }|rt        |      }|rt        |      }|
rt        |
      }
t        |      t        |      }}t        |	      t        |      }}	|s|rt        d      |r"t        || j	                  |      f      | _        nt        | j	                  |            | _        |rz|dvrt        d      |dk(  rd| j
                  f|g}n&|d| j
                  fg}|dk(  r|j                  |       t        |      | _        t        dd|f| j                  dd|fg      }n	d	| _        d	}g }|r|j                  dd|f       n|j                  dd
t        d      f       |j                  |       t        |      dz
  }|
r|j                  dd|
f       t        |d
dg|      }|rt        dd|	f|dd|fg      }nd	}g }|r|j                  d|f       |j                  |       t        |      dz
  }|r|j                  d|f       t        ||      }t        j                  | |       t        j                  | |       y	)af  
        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.  This allows for seamless use of
        adjoining LineBoxes.
        z.Cannot have a title when tline is empty string)leftcenterrightz7title_align must be one of "left", "right", or "center"rZ   flowr[   fixedr?   Nr   r@      )box_columnsfocus_column)
focus_item)r   r   r   
ValueErrorformat_titletitle_widgetrF   r   tline_widgetrC   r   r   r)   r   )r%   original_widgettitletitle_align
title_attrtlcornertlinellinetrcornerblcornerrlineblinebrcornertline_widgetstopmiddle_widgets	focus_colmiddlebottompile_widgets	focus_pospiles                         r(   r)   zLineBox.__init__f   st   > ENEENEe$Ee$E!(^T(^(!(^T(^(MNN $j$2C2CE2J%K LD $T%6%6u%= >D"== !Z[[f$"($*;*;!<e D!&1B1B(C D(*!((/ ' 6D!X&!!!X& C !%DC!!7Au"56 !!7Ay~">?o.'!+	!!7Au"56F< !X&H/E F F.F#%)	 01LY7!!$8D$'r*   c                 *    t        |      dkD  rd|z  S y)Nr   z %s r@   )rC   r%   r-   s     r(   rd   zLineBox.format_title   s    t9q=D= r*   c                     | j                   st        d      | j                   j                  | j                  |             | j                  j                          y )Nz$Cannot set title when tline is unset)re   rc   r$   rd   rf   r/   r}   s     r(   	set_titlezLineBox.set_title   sH      CDD""4#4#4T#:;%%'r*   c                     t        | j                  j                  ||            }|dxx   dz  cc<   |dxx   dz  cc<   |S )aY  
        Return the number of screen columns and rows required for
        this Linebox widget to be displayed without wrapping or
        clipping, as a single element tuple.

        :param size: ``None`` for unlimited screen columns or (*maxcol*,) to
                     specify a maximum column size
        :type size: widget size
        r   r_   r?   )list_original_widgetr=   r%   r8   r9   s      r(   r=   zLineBox.pack   s@     D))..tU;<Q1Q1r*   )r@   r[   Nu   ┌   ─   │u   ┐u   └r   r   u   ┘rO   )rQ   rR   rS   r)   rd   r   r=   rV   r*   r(   rX   rX   d   s'    .0266<9?(.	f(P(r*   rX   c                   "     e Zd ZdZ fdZ xZS )BarGraphMetaz
    Detect subclass get_data() method and dynamic change to
    get_data() method and disable caching in these cases.

    This is for backwards compatibility only, new programs
    should use set_data() instead of overriding get_data().
    c                     t         t        |   |||       d|v r!t        |       | _        | j
                  | _        t        d t              | _        y )Nget_datac                     | j                   S r,   )	_get_datar1   s    r(   <lambda>z'BarGraphMeta.__init__.<locals>.<lambda>   s
     r*   )	superr   r)   r   rD   r   r   propertynocache_bargraph_get_data)clsnamebasesd	__class__s       r(   r)   zBarGraphMeta.__init__   sF    lC)$q9?.s3CJLLCM'%'r*   )rQ   rR   rS   __doc__r)   __classcell__)r   s   @r(   r   r      s    ' 'r*   r   c                 2    t        |       | _        || _        y)zm
    Disable caching on this bargraph because get_data_fn needs
    to be polled to get the latest data.
    N)r   rD   r   )r%   get_data_fns     r(   r   r      s    
 16DK DNr*   c                       e Zd Zy)BarGraphErrorN)rQ   rR   rS   rV   r*   r(   r   r     s    r*   r   c                   z    e Zd Z eeg      ZdZdZdZddZ	ddZ
ddZd Zd	 Zd
 Zd Zd Zd Zd Zd ZddZy)BarGraphTu    ▁▂▃▄▅▆▇u   _⎺⎻─⎼⎽Nc                 r    | j                  |||       | j                  g dd       | j                  d       y)z
        Create a bar graph with the passed display characteristics.
        see set_segment_attributes for a description of the parameters.
        r?   N)set_segment_attributesset_dataset_bar_width)r%   attlisthattsatts       r(   r)   zBarGraph.__init__  s4     	##GT48b!T"4 r*   c                 r   g | _         g | _        t        |      dk  rt        d|      t        |      dk\  sJ d       |D ]  }t	        |      t
        k7  r7| j                   j                  |       | j                  j                  d       L|\  }}| j                   j                  |       | j                  j                  |        g | _        || j                   d   g}nt	        |      t        k7  r|g}|| _        |i }|j                         D ]~  }	 |\  \  }}	}t	        |      t        k7  s|t        |      k\  rt        d|      t	        |	      t        k7  s|	t        |      k\  rt        d	|      ||	k  snt        d
|d|	d       || _        y# t        $ r t        d|      w xY w)a  
        :param attlist: list containing display attribute or
                        (display attribute, character) tuple for background,
                        first segment, and optionally following segments.
                        ie. len(attlist) == num segments+1
                        character defaults to ' ' if not specified.
        :param hatt: list containing attributes for horizontal lines. First
                     element is for lines on background, second is for lines
                     on first segment, third is for lines on second segment
                     etc.
        :param satt: dictionary containing attributes for smoothed
                     transitions of bars in UTF-8 display mode. The values
                     are in the form:

                       (fg,bg) : attr

                     fg and bg are integers where 0 is the graph background,
                     1 is the first segment, 2 is the second, ...
                     fg > bg in all values.  attr is an attribute with a
                     foreground corresponding to fg and a background
                     corresponding to bg.

        If satt is not None and the bar graph is being displayed in
        a terminal using the UTF-8 encoding then the character cell
        that is shared between the segments specified will be smoothed
        with using the UTF-8 vertical eighth characters.

        eg: set_segment_attributes( ['no', ('unsure',"?"), 'yes'] )
        will use the attribute 'no' for the background (the area from
        the top of the graph to the top of the bar), question marks
        with the attribute 'unsure' will be used for the topmost
        segment of the bar, and the attribute 'yes' will be used for
        the bottom segment of the bar.
        r_   z3attlist must include at least background and seg1: z must at least specify bg and fg! Nr   zsatt not in (fg,bg:attr) form: zfg not valid integer: zbg not valid integer: zfg (z) not > bg ())attrcharrC   r   typetuplerF   r   r   itemsrc   intr   )
r%   r   r   r   rH   r   rL   ifgbgs
             r(   r   zBarGraph.set_segment_attributes  s   F 		w<![b dee7|q D"DD  	%AAw%		  #		  %b		  &		  $	% 	<IIaL>D$Z46D	<D 
	HAP!"R$ Bx3"G"4#"$FGGBx3"G"4#"$FGGRx#r2$FGG
	H 	  P#1$NOOPs   FF6c                     |%|dd }|j                          |j                          |||f| _        | j                          y)a  
        Store bar data, bargraph top and horizontal line positions.

        bardata -- a list of bar values.
        top -- maximum value for segments within bardata
        hlines -- None or a bar value marking horizontal line positions

        bar values are [ segment1, segment2, ... ] lists where top is
        the maximal value corresponding to the top of the bar graph and
        segment1, segment2, ... are the values for the top of each
        segment of this bar.  Simple bar graphs will only have one
        segment in each bar value.

        Eg: if top is 100 and there is a bar value of [ 80, 30 ] then
        the top of this bar will be at 80% of full height of the graph
        and it will have a second segment that starts at 30%.
        N)sortreversedatar/   )r%   bardatart   hliness       r(   r   zBarGraph.set_dataa  s@    $ AYFKKMNNS&(	r*   c                     |\  }}| j                   \  }}}| j                  ||f|      }t        |      t        |      kD  r|dt        |       ||fS |||fS )a/  
        Return (bardata, top, hlines)

        This function is called by render to retrieve the data for
        the graph. It may be overloaded to create a dynamic bar graph.

        This implementation will truncate the bardata list returned
        if not all bars will fit within maxcol.
        N)r   calculate_bar_widthsrC   )r%   r8   rA   maxrowr   rt   r   widthss           r(   r   zBarGraph._get_dataz  sj      #yyf**FF+;WEw<#f+%<CK(#v55V##r*   c                 D    ||dkD  sJ || _         | j                          y)z
        Set a preferred bar width for calculate_bar_widths to use.

        width -- width of bar or None for automatic width adjustment
        Nr   )	bar_widthr/   )r%   rM   s     r(   r   zBarGraph.set_bar_width  s(     }	))r*   c                 F   |\  }}| j                   0| j                   gt        t        |      || j                   z        z  S t        |      |k\  rdg|z  S g }|}t        |      }|D ]7  }t        t	        |      |z  dz         }	|j                  |	       ||	z  }|dz  }9 |S )z
        Return a list of bar widths, one for each bar in data.

        If self.bar_width is None this implementation will stretch
        the bars across the available space specified by maxcol.
        r?         ?)r   minrC   r   floatrF   )
r%   r8   r   rA   r   r   growremainrowws
             r(   r   zBarGraph.calculate_bar_widths  s      >>%NN#cGf6'8 8 8 w<6!3<W 	CE$K&(3./AMM!AIDaKF		
 r*   c                      yz
        Return False.
        FrV   r1   s    r(   
selectablezBarGraph.selectable       r*   c                 8    | j                   xr t               dk(  S )Nutf8)r   r   r1   s    r(   use_smoothedzBarGraph.use_smoothed  s    yy:.0F::r*   c                    |\  }}| j                  ||f      \  }}}| j                  ||f|      }| j                         r#t        ||||dz        }| j	                  |      }nt        ||||      }|r| j                  ||||      }|S )z)
        Calculate display data.
           )r   r   r   calculate_bargraph_displaysmooth_displayhlines_display)	r%   r8   rA   r   r   rt   r   r   disps	            r(   calculate_displayzBarGraph.calculate_display  s      #}}ff-=>f**FF+;WE-gsF.4qj:D&&t,D .gsF.46D &&tS&&ADr*   c                      j                         rd}g d}nd}dg}g }|D ]0  }t        ||z
        |z  |z  |z
  }	|	dk  r |j                  |	       2 g }
d}|D ]>  }	t        |	      }||k(  r|	|z
  }|D ]  \  }}||k  s|
j                  ||f        n |}@  fd}g }d}d}|D ]  \  }}|t	        |
      k\  r|j                  ||f       (||z   }|t	        |
      k  ro|
|   d   |k  rd|
|   \  }}||z
  dkD  r|j                  ||z
  |f       |j                  d |||      f       |dz   }|dz  }|t	        |
      k  r|
|   d   |k  rd||k  s|j                  ||z
  |f       |} |S )a+  
        Add hlines to display structure represented as bar_type tuple
        values:
        (bg, 0-5)
        bg is the segment that has the hline on it
        0-5 is the hline graphic to use where 0 is a regular underscore
        and 1-5 are the UTF-8 horizontal scan line characters.
        r   ))g?r?   )g?r_   )g333333?   )g?   )      ?   r   )r   r   c                     g }| D ]X  \  }}t        |      t        k(  r.t        j                        |kD  r|j	                  ||f|f       F|j	                  ||f       Z |S r,   )r   r   rC   r   rF   )r   chnumroutbar_typerM   r%   s        r(   fill_rowz)BarGraph.hlines_display.<locals>.fill_row  sh    D#& /%Nc)DII1KK(E!2E :;Xu-./ Kr*   r?   )r   r   rF   r   rC   )r%   r   rt   r   r   shiftrrrhlhrhhrowslast_ir   fsplr   r   rK   krnumy_countr   	end_blocks   `                      r(   r   zBarGraph.hlines_display  s    FA FA  	AsQw&(3.7BAvJJrN		  		BBAF{QA 
Us7LL!U, F			   	!LGSCJ'3(wIc%j.U1Xa[9%< 85t8a<HHa$h_-!Xc51231uQ c%j.U1Xa[9%< i)d*C01 	!" r*   c                 Z   	 g d fd		fd}|D ]s  \  }}r*t        dz
  |      } |||       ||z  }|z  dz  |s2dk(  sJ |dkD  r!j                  |dz  dz  |f       |dz  }|s_j                  ||f       |u D cg c]  \  }}|dz  |f c}}S c c}}w )a0  
        smooth (col, row*8) display into (col, row) display using
        UTF vertical eighth characters represented as bar_type
        tuple values:
        ( fg, bg, 1-7 )
        where fg is the lower segment, bg is the upper segment and
        1-7 is the vertical eighth character to use.
        r   c                    | |c\  }}\  }}||f||fk(  r||fd d fS t        ||      }d x}}||kD  r|||z
  f}n||kD  r|||z
  f}t        |      t        k(  r||f||fS ||f
j                  vr	dk  r||f||fS ||f||fS ||d	z
  f|f||fS )Nr   r   )r   r   r   r   )rH   bbt1w1bt2w2wminl1l2r   r%   s            r(   seg_combinez,BarGraph.smooth_display.<locals>.seg_combine'  s    #$a IS"yRRyS"I%Ry$,,r2;DNBBw27^b27^CyE!T{B**Sz*q5;B..T{B**#q1u%t,b"44r*   c                 2   	d   \  }}|d d  }|d d  }g }|rr 
|j                  d      |j                  d            \  \  }}}}|r|d   d   |k(  r||d   d   |z   f|d<   n|j                  ||f       |r|g|z   }|r|g|z   }|rr|rJ || z   |f	d<   y )Nr   r   r?   )poprF   )countr   o_counto_rowlbtr   r   r   rK   r   s            r(   row_combine_lastz1BarGraph.smooth_display.<locals>.row_combine_last9  s    rUNGUa&C!HEA"-IIaL#''!*#.QR2qR2qA.AbEHHb!W%D5LE$*C  9u_a(AbEr*   r      )r   rF   )
r%   r   r   r   r   r   yrK   r   r   s
   `      @@@r(   r   zBarGraph.smooth_display  s     	5$	)* ! 	LGSAE7+ ,5 U
E6M6{'Q,*C01!A+HHgs^$A#	$ /00(1ca000s   B'c                 H   |\  }}| j                  ||f      }g }|D ]  \  }}g }	|D ]  \  }
}t        |
      t        k(  r_t        |
      dk(  r*|
\  }}}| j                  ||f   }| j
                  |   |z  }nH|
\  }}| j                  |   }| j                  |   |z  }n!| j                  |
   }| j                  |
   |z  }|	j                  ||f        t        |	      j                  |f      }|j                         dk(  sJ d       ||ddfg|z  z  } t        |      }|S )z"
        Render BarGraph.
        r   r?   zInvalid characters in BarGraph!NF)r   r   r   rC   r   eighthsr   r   r   r   rF   r   rD   r:   r   )r%   r8   r9   rA   r   r   combinelistr   r   r   r   rM   r   r   r   rH   tr<   rN   s                      r(   rD   zBarGraph.renderb  sM     %%vv&67  	8LGSA#& !%>U*8})$,	B IIr2h/ LLOe3 !)A IIbM KKNU2		(+A		(+e3A!Q !  Qy)A668q=C"CC=Qe,-77K)	8, [)r*   )NNr,   rP   )rQ   rR   rS   rT   r   rU   ignore_focusr   r   r)   r   r   r   r   r   r   r   r   r   r   rD   rV   r*   r(   r   r     s_    GL'G F!EN2$&4;,IVE1Nr*   r   c                    t        |       t        |      k(  sJ t        |      }dg|z  }|fd}d}d}| D ]l  }	||   }
|
dk  r|}t        |	||      }t        t        |	      dz
  dd      D ]*  }||   }||k\  r|dk  rd}||k  s|} ||dz   |||
       , ||
z  }|dz  }n g }d}d|fg}|D ]  }||dz   }|r|j	                  ||f       d}d}||   \  }}d}g }|D ]%  \  }}}|||z   kD  r.|j	                  ||f       |dz  }||z  }||   \  }}|||z   kD  r.||k(  r|j	                  |||z
  f       n4||z
  dkD  r|j	                  |||z
  f       |j	                  |||z
  f       ||k(  rt        |      } n|||z   k\  r|dz  }||z  }||   \  }}|||z   k\  r||k7  r||z   |z
  }|}|d   \  }}|||z   |z
  z  }||f|d<   |dz  }||z  }||k(  r n+|t        |      k  sJ t        ||f             ||   \  }}( |t        |      k  r|||fg||dz   d z   z  }|}|dz  } |r|j	                  ||f       |S )a  
    Calculate a rendering of the bar graph described by data, bar_widths
    and height.

    bardata -- bar information with same structure as BarGraph.data
    top -- maximal value for bardata segments
    bar_widths -- list of integer column widths for each bar
    maxrow -- rows for display of bargraph

    Returns a structure as follows:
      [ ( y_count, [ ( bar_type, width), ... ] ), ... ]

    The outer tuples represent a set of identical rows. y_count is
    the number of rows in this set, the list contains the data to be
    displayed in the row repeated through the set.

    The inner tuple describes a run of width characters of bar_type.
    bar_type is an integer starting from 0 for the background, 1 for
    the 1st segment, 2 for the 2nd segment etc..

    This function should complete in approximately O(n+m) time, where
    n is the number of bars displayed and m is the number of rows.
    Nc                     ||   rB||   d   \  }}}||kD  r||k\  r||   d= n/|||f||   d<   n#|| k(  r||k(  r||||z   f||   d<   y ||   g ||<   ||   j                  | |||z   f       y )Nr   )rF   )seg_numcolr   rM   r:   last_seglast_collast_ends           r(   add_segmentz/calculate_bargraph_display.<locals>.add_segment  s    9+/9R=(Hh#~s?S	"%-%-s%4DIbMW$S!)8!)E!1!3S	"#YDIS	'3e45r*   r   r?   r   )rC   sumscale_bar_valuesrangerF   repr)r   rt   
bar_widthsr   rA   r:   r  r  barnumbarrM   tallestsegmentsr   srowsetsr   lastr   r   lalnr<   rK   r  startendoaons                                r(   r   r     s;   2 w<3z?***_F 6F?D37 6" CF 6"19#Cf5s3x!|R, 
	2AAF{1u7{AE351
	2 	u!'. GGK=D 99kGNNGT?+GaB#$ (	GUC!b&."b"QRaB	 !b&. W}"cAg'19q=HHb%!)_-'3;/0f}I R-QRaB R-
 W}Vc\ rUFB!b&3,BFAbEFAGAF{s4y=4$F|"44=!WFBQ(	T s4y=2r(d1q56l**A1s9v 'Nr*   c                   8    e Zd Z eeg      Zd Zd Zd ZddZ	y)GraphVScalec                 (    | j                  ||       y)a]  
        GraphVScale( [(label1 position, label1 markup),...], top )
        label position -- 0 < position < top for the y position
        label markup -- text markup for this label
        top -- top y position

        This widget is a vertical scale for the BarGraph widget that
        can correspond to the BarGraph's horizontal lines
        N)	set_scale)r%   labelsrt   s      r(   r)   zGraphVScale.__init__  s     	vs#r*   c                 
   |dd }|j                          |j                          g | _        g | _        |D ]D  \  }}| j                  j	                  |       | j                  j	                  t        |             F || _        y)z
        set_scale( [(label1 position, label1 markup),...], top )
        label position -- 0 < position < top for the y position
        label markup -- text markup for this label
        top -- top y position
        N)r   r   postxtrF   r   rt   )r%   r"  rt   r   r&   s        r(   r!  zGraphVScale.set_scale"  sn      	*IAvHHOOAHHOODL)	* r*   c                      yr   rV   r1   s    r(   r   zGraphVScale.selectable4  r   r*   c                    |\  }}t        | j                  | j                  |      }g }d}t        || j                        D ]w  \  }}	|dz  }||k\  r nh||k  r|	j                  |f      }
||kD  r"||z
  }t        |
      }
|
j                  |d       ||
j                         z  }|j                  |
ddf       y |st        d|d   |d         S t        |      }
||z
  r|
j                  d||z
         |
S )z%
        Render GraphVScale.
        r   r?   NFr   )r  r$  rt   zipr%  rD   r	   pad_trim_top_bottomr:   rF   r   r   )r%   r8   r9   rA   r   plr  r:   pr  r<   runs               r(   rD   zGraphVScale.render:  s     dhh&9DHH% 	1DAqFAF{4x&#A4x$h#A&%%c1-AFFHD4/0	1 sDGT!W55+&D=!!!Vd]3r*   NrP   )
rQ   rR   rS   rT   r   rU   r)   r!  r   rD   rV   r*   r(   r  r    s"    G
$$r*   r  c           	      h    | D cg c]"  }|t        t        |      |z  |z  dz         z
  $ c}S c c}w )zJ
    Return a list of bar values aliased to integer values of maxrow.
    r   )r   r   )r  rt   r   vs       r(   r  r  Z  s7     BEEAFSqF*S03677EEEs   '/c                   x    e Zd Z eeg      ZdZeZddZ	d Z
 ed e
      Zd Z ed e      ZddZd	 Zdd
Zy)ProgressBaru    ▏▎▍▌▋▊▉Nc                 J    || _         || _        || _        || _        || _        y)a  
        :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.

        >>> 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 u'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, ))
        N)normalcomplete_current_doner   )r%   r2  r3  currentdoner   s         r(   r)   zProgressBar.__init__h  s(    B  
	r*   c                 2    || _         | j                          y)z-
        current -- current progress
        N)r4  r/   )r%   r6  s     r(   set_completionzProgressBar.set_completion  s      r*   c                     | j                   S r,   )r4  r1   s    r(   r   zProgressBar.<lambda>  s
    DMM r*   c                 2    || _         | j                          y)z1
        done -- progress amount at 100%
        N)r5  r/   )r%   r7  s     r(   	_set_donezProgressBar._set_done  s     
r*   c                     | j                   S r,   )r5  r1   s    r(   r   zProgressBar.<lambda>  s
     r*   c                      y)Nr?   rV   r   s      r(   r:   zProgressBar.rows  s    r*   c           
          t        dt        dt        | j                  dz  | j                  z                    }t        |      dz   S )zw
        Return the progress bar percentage text.
        You can override this method to display custom text.
        d   r   z %)r   maxr   r6  r7  str)r%   percents     r(   r2   zProgressBar.get_text  s=    
 c3q#dllS&8499&D"EFG7|d""r*   c                    |\  }t        | j                         | j                  t              }|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
|dk(  r|	dk(  r| j                  |fgg|_        |S ||k\  r| j                   |fgg|_        |S |	rt#        |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   rD   r   r6  r7  r   rC   _textdecodeencoder   r2  _attrr3  r   r   rF   _cs)r%   r8   r9   rA   r%  r<   cf
ccol_dirtyccolcsr  cencrH   s                r(   rD   zProgressBar.render  s;    	4==?DOOT:JJy!4<< 6)DII5W
1771:kz*11X

&

 99 b4i1_%B!8	bAgf-./AG$ # V^/01AG   DD)*b0
A<<#**73D5DD1TAXY<7AGGAJAax$--./HHdiiT+,}q 1$$++v}q'89:cAGS_-./AE  -ftm46 7AGr*   )r   r@  NrP   )rQ   rR   rS   rT   r   rU   r   r   rG  r)   r9  r   r6  r<  r7  r:   r2   rD   rV   r*   r(   r0  r0  a  sU    G'GJ%N 1>BG +Y7D#%r*   r0  c                   4    e Zd Z eeg      Zd ZddZddZy)
PythonLogoc                     t        dd      }t        dd      }d}t        |df|df|df|df|d	f|d
f|df|dfg      j                  |f      | _        y)zd
        Create canvas containing an ASCII version of the Python
        Logo and store it.
        z
light bluedefaultyellow   z     ______
z   _|_o__  |z__
z  |   _____|z  |
z  |__|  z______|
z     |____o_|N)r   r   rD   _canvas)r%   bluyelrM   s       r(   r)   zPythonLogo.__init__  s~    
 |Y/x+/".!C=.!C>*[1/"$ %
 &,VUH%5 	r*   Nc                 j    | j                   j                         | j                   j                         fS )z?
        Return the size from our pre-rendered canvas.
        )rX  r;   r:   r   s      r(   r=   zPythonLogo.pack  s)     ||  "DLL$5$5$777r*   c                 0    t        |       | j                  S )z1
        Return the pre-rendered canvas.
        )r   rX  r   s      r(   rD   zPythonLogo.render  s     	4||r*   rO   rP   )	rQ   rR   rS   rT   r   rU   r)   r=   rD   rV   r*   r(   rS  rS    s     G68r*   rS  c                  ,    dd l } | j                          y r5   )doctesttestmod)r^  s    r(   _testr`    s    OOr*   __main__N)3
__future__r   r   urwid.compatr   r   
urwid.utilr   r   urwid.canvasr	   r
   r   r   r   urwid.widgetr   r   r   r   r   r   r   r   r   r   r   r   r   r   urwid.containerr   r   urwid.display_commonr   urwid.decorationr   r!   rX   r   r   	Exceptionr   r   r   r  r  r0  rS  r`  rQ   rV   r*   r(   <module>rk     s   . 0 - = 7 7 7 7 * ) -<f <~C
 CL': '&!	I 	y~lF3 yxL^C& CNFn& nb > Z	G r*   