ó
    Ãu„j^3  ã                  ó  • S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	  SSK
JrJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  \	" 5       r  " S S\SS9r " S S\5      r " S S\5      r  " S S\SS9r!g)z!Implements a progress bar widget.é    )Úannotations)ÚOptionalÚType)ÚStyle)ÚUnusedParameter)ÚComposeResultÚRenderResult)ÚClock)ÚGradient)ÚETA)Úclamp)Úreactive)ÚBar)ÚWidget)ÚLabelc                  óØ   ^ • \ rS rSr% Sr1 Skr Sr\\\	      " S5      r
S\S'    \" S5      rS\S	'    SSSS
SS\4             SU 4S jjjrSS jrSS jrSS jrSS jrSrU =r$ )r   é   z$The bar portion of the progress bar.>   úbar--barúbar--completeúbar--indeterminateai  
    Bar {
        width: 32;
        height: 1;

        &> .bar--bar {
            color: $primary;
            background: $surface;
        }
        &> .bar--indeterminate {
            color: $error;
            background: $surface;
        }
        &> .bar--complete {
            color: $success;
            background: $surface;
        }
    }
    Núreactive[float | None]Ú
percentageúreactive[Gradient | None]ÚgradientFc                óº   >• U=(       d
    [        5       R                  5       U l        [        TU ]  XX4S9  U R                  [        R                  U5        Xpl        g)z@Create a bar for a [`ProgressBar`][textual.widgets.ProgressBar].©ÚnameÚidÚclassesÚdisabledN)	r
   ÚcloneÚ_clockÚsuperÚ__init__Úset_reactiver   r   Úbar_renderable)	Úselfr   r   r   r    Úclockr   r&   Ú	__class__s	           €Ú«C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\textual/widgets/_progress_bar.pyr$   ÚBar.__init__C   sH   ø€ ð ×'¤£×.Ñ.Ó0ˆŒÜ‰Ñ˜d°7ÐÑNØ×Ñœ#Ÿ,™,¨Ô1Ø,Õó    c                óp   • U R                   R                  S-  nUc  S$ U(       a  [        X-  5      U-  $ U$ )zJAvoid updating the bar, if the percentage increase is too small to render.é   N)ÚsizeÚwidthÚint)r'   r   r0   s      r*   Ú_validate_percentageÚBar._validate_percentageS   sK   € à—	‘	—‘ !Ñ#ˆð Ñ!ð ð	
ö 6;”#�jÑ(Ó)¨EÑ1ð	
ð AKð	
r,   c                ó(   • Ub  SU l         gSU l         g)z>Manage the timer that enables the indeterminate bar animation.Ng±?)Úauto_refresh©r'   r   s     r*   Úwatch_percentageÚBar.watch_percentage\   s   € àÑ!Ø $ˆDÕà &ˆDÕr,   c                ó–  • U R                   c  U R                  5       $ U R                   S:  a  U R                  S5      OU R                  S5      nU R                  SU R                  R
                  U R                   -  4[        R                  " UR                  5      [        R                  " UR                  5      U R                  S9$ )z/Render the bar with the correct portion filled.é   r   r   r   )Úhighlight_rangeÚhighlight_styleÚbackground_styler   )r   Úrender_indeterminateÚget_component_rich_styler&   r/   r0   r   Ú
from_colorÚcolorÚbgcolorr   )r'   Ú	bar_styles     r*   ÚrenderÚ
Bar.renderc   s¬   € à�?‰?Ñ"Ø×,Ñ,Ó.Ð.ð —?‘? QÓ&ð ×-Ñ-¨jÔ9à×2Ñ2°?ÓCð ð
 ×&Ñ&Ø!" D§I¡I§O¡O°d·o±oÑ$EÐ FÜ %× 0Ò 0°·±Ó AÜ!&×!1Ò!1°)×2CÑ2CÓ!DØŸ™ð	 'ð ð r,   c                óà  • U R                   R                  nSU-  nX-   nU R                  R                  S:X  a  SnUnO>SnU(       a  X`R                  R
                  -  SU-  -  OSnXC:”  a  SU-  U-
  nXB-  nXB-   nU R                  S5      nU R                  [        SU5      [        XQ5      4[        R                  " UR                  5      [        R                  " UR                  5      S9$ )z;Render a frame of the indeterminate progress bar animation.g      Ð?Únoner   é   r.   r   )r;   r<   r=   )r/   r0   ÚappÚanimation_levelr"   Útimer?   r&   ÚmaxÚminr   r@   rA   rB   )r'   r0   Úhighlighted_bar_widthÚtotal_imaginary_widthÚstartÚendÚspeedrC   s           r*   r>   ÚBar.render_indeterminatet   sø   € à—	‘	—‘ˆØ $ u¡Ðà %Ñ =Ðð �8‰8×#Ñ# vÓ-ØˆEØ‰CàˆEö )ð Ÿ™×)Ñ)Ñ)¨aÐ2GÑ.GÒHàð ð
 Ó,àÐ1Ñ1°EÑ9�ØÑ*ˆEØÑ/ˆCà×1Ñ1Ð2FÓGˆ	Ø×"Ñ"Ü   E›]¬C°«OÐ<Ü!×,Ò,¨Y¯_©_Ó=Ü"×-Ò-¨i×.?Ñ.?Ó@ð #ð 
ð 	
r,   )r"   r5   r&   )r   ú
str | Noner   rT   r   rT   r    Úboolr(   úClock | Noner   úGradient | Noner&   úType[BarRenderable])r   úfloat | NoneÚreturnrY   )r   rY   rZ   ÚNone©rZ   r	   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚCOMPONENT_CLASSESÚDEFAULT_CSSr   r   Úfloatr   Ú__annotations__r   ÚBarRenderabler$   r2   r7   rD   r>   Ú__static_attributes__Ú__classcell__©r)   s   @r*   r   r      sÆ   ø‡ Ù.âKÐðð€Kð( *2°(¸5±/Ò)BÀ4Ó)H€JÐ&ÓHØ=á*2°4«.€HÐ'Ó8Øð  ØØ"ØØ"Ø$(Ø.;ð-àð-ð ð-ð ð	-ð
 ð-ð ð-ð "ð-ð ,÷-ð -ô 
ô'ô÷"
ò 
r,   r   F)Ú	can_focusc                  óZ   • \ rS rSr% SrSr\\\      " S5      r	S\
S'    S
S jrSS jrS	rg)ÚPercentageStatusé•   z=A label to display the percentage status of the progress bar.z]
    PercentageStatus {
        width: 5;
        content-align-horizontal: right;
    }
    Núreactive[int | None]r   c                ó(   • Uc  S $ [        US-  5      $ )Néd   )Úroundr6   s     r*   r2   Ú%PercentageStatus._validate_percentage¢   s   € Ø!Ñ)ˆtÐF¬u°ZÀ#Ñ5EÓ/FÐFr,   c                ó>   • U R                   c  S$ U R                    S3$ )Nz--%Ú%)r   ©r'   s    r*   rD   ÚPercentageStatus.render¥   s"   € ØŸ™Ñ/ˆuÐJ¸¿¹Ð7HÈÐ5JÐJr,   © )r   rY   rZ   z
int | Noner\   )r]   r^   r_   r`   ra   rc   r   r   r1   r   re   r2   rD   rg   rw   r,   r*   rl   rl   •   s6   ‡ ÙGð€Kð (0°¸±Ò'>¸tÓ'D€JÐ$ÓDØ=ôG÷Kr,   rl   c                  óP   • \ rS rSr% SrSr\\\      " S5      r	S\
S'    S	S jrSrg)
Ú	ETAStatusé©   zKA label to display the estimated time until completion of the progress bar.zV
    ETAStatus {
        width: 9;
        content-align-horizontal: right;
    }
    Nr   Úetac                óª   • U R                   nUc  g[        [        U5      S5      u  p#[        US5      u  pBUS:”  a  gUS:”  a  U S3$ US SUS SUS 3$ )	zRender the ETA display.z--:--:--é<   i?B z+999999héc   ÚhÚ02Ú:)r{   Údivmodrq   )r'   r{   ÚminutesÚsecondsÚhourss        r*   rD   ÚETAStatus.renderµ   sn   € à�h‰hˆØ‰;Øä%¤e¨C£j°"Ó5ÑˆGÜ# G¨RÓ0‰NˆEØ�v‹~Ø!Ø˜“Ø˜ �{Ð"à ˜ 1 W¨R L°°'¸"°Ð>Ð>r,   rw   r\   )r]   r^   r_   r`   ra   rc   r   r   rd   r{   re   rD   rg   rw   r,   r*   ry   ry   ©   s/   ‡ ÙUð€Kð #+¨8°E©?Ò";¸DÓ"A€CÐ	ÓAØ]÷?r,   ry   c                  ó¦  ^ • \ rS rSr% SrSr\" S5      rS\S'    \\	\
      " S5      rS\S	'    \\	\
      " S5      rS\S
'    \\	\      " S5      rS\S'   \" S5      rS\S'    \rS\S'     SSSSSSSSSSS.	                   S U 4S jjjjrS!S jrS"S jrS#S jrS$S jrS%S jrS&S jrS'S(S jjr\\\S.       S)S jjrSrU =r$ )*ÚProgressBaréÅ   zA progress bar widget.za
    ProgressBar {
        width: auto;
        height: 1;
        layout: horizontal;
    }
    ç        zreactive[float]ÚprogressNr   Útotalr   rn   Ú_display_etar   r   rX   ÚBAR_RENDERABLETF)	Úshow_barÚshow_percentageÚshow_etar   r   r   r    r(   r   c       	        óà   >• U	=(       d
    [        5       U l        [        5       U l        [        TU ]  XVXxS9  Xl        X l        X0l        X@l	        U R                  [        R                  U
5        g)av  Create a Progress Bar widget.

The progress bar uses "steps" as the measurement unit.

Example:
    ```py
    class MyApp(App):
        def compose(self):
            yield ProgressBar(total=100)

        def key_space(self):
            self.query_one(ProgressBar).advance(5)
    ```

Args:
    total: The total number of steps in the progress if known.
    show_bar: Whether to show the bar portion of the progress bar.
    show_percentage: Whether to show the percentage status of the bar.
    show_eta: Whether to show the ETA countdown of the progress bar.
    name: The name of the widget.
    id: The ID of the widget in the DOM.
    classes: The CSS classes for the widget.
    disabled: Whether the widget is disabled or not.
    clock: An optional clock object (leave as default unless testing).
    gradient: An optional Gradient object (will replace CSS styles in the bar).
r   N)r
   r"   r   Ú_etar#   r$   rŒ   r�   r�   r‘   r%   rˆ   r   )r'   rŒ   r�   r�   r‘   r   r   r   r    r(   r   r)   s              €r*   r$   ÚProgressBar.__init__î   sZ   ø€ ðP ×&œu›wˆŒÜ“EˆŒ	Ü‰Ñ˜d°7ÐÑNØŒ
Ø ŒØ.ÔØ ŒØ×Ñœ+×.Ñ.°Õ9r,   c                ó�   • U R                  5         U R                  SU R                   5        U R                  R                  5         g )Nr:   )ÚupdateÚset_intervalr"   Úresetru   s    r*   Úon_mountÚProgressBar.on_mount  s/   € Ø�‰ŒØ×Ñ˜!˜TŸ[™[Ô)Ø�‰×ÑÕr,   c              #  óÆ  #   • U R                   (       a[  [        SU R                  U R                  S9R	                  [
        R                  5      R	                  [
        R                  5      v •  U R                  (       a(  [        SS9R	                  [
        R                  5      v •  U R                  (       a'  [        SS9R	                  [
        R                  S9v •  g g 7f)NÚbar)r   r(   r&   r   )r   r{   )r{   )r�   r   r"   rŽ   Ú	data_bindrˆ   r   r   r�   rl   r‘   ry   r�   ru   s    r*   ÚcomposeÚProgressBar.compose$  s™   é € Ø�=�=ä�u D§K¡KÀ×@SÑ@SÑTß‘œ;×1Ñ1Ó2ß‘œ;×/Ñ/Ó0òð
 ××Ü" lÑ3×=Ñ=¼k×>TÑ>TÓUÒUØ�=�=Ü˜uÑ%×/Ñ/´K×4LÑ4LÐ/ÐMÓMð ùs   ‚CC!c                ó$   • Uc  U$ [        SU5      $ )z!Ensure the total is not negative.r   )rL   ©r'   rŒ   s     r*   Ú_validate_totalÚProgressBar._validate_total0  s   € à‰=ØˆLÜ�1�e‹}Ðr,   c                ó�   • U R                   (       a$  [        U R                  U R                   -  SS5      $ U R                   S:X  a  gg)zsKeep the percentage of progress updated automatically.

This will report a percentage of `1` if the total is zero.
rŠ   g      ð?r   N)rŒ   r   r‹   ru   s    r*   Ú_compute_percentageÚProgressBar._compute_percentage6  s8   € ð
 �:�:Ü˜Ÿ™¨¯©Ñ3°S¸#Ó>Ð>Ø�Z‰Z˜1‹_ØØr,   c                ó"   • U R                  US9  g)z)Perform update when progress is modified.)r‹   N©r–   )r'   r‹   s     r*   Ú_watch_progressÚProgressBar._watch_progressA  s   € à�‰˜XˆÒ&r,   c                ó"   • U R                  US9  g)z"Update when the total is modified.)rŒ   Nr¨   r¡   s     r*   Ú_watch_totalÚProgressBar._watch_totalE  s   € à�‰˜%ˆÒ r,   c                ó"   • U R                  US9  g)zÈAdvance the progress of the progress bar by the given amount.

Example:
    ```py
    progress_bar.advance(10)  # Advance 10 steps.
    ```

Args:
    advance: Number of steps to advance progress by.
)ÚadvanceNr¨   )r'   r¯   s     r*   r¯   ÚProgressBar.advanceI  s   € ð 	�‰˜GˆÒ$r,   )rŒ   r‹   r¯   c               óê  ^ ^• T R                   R                  m[        U[        5      (       d4  Ub  UT R                  :w  a  T R
                  R                  5         UT l        SUU 4S jjn[        U[        5      (       d  UT l        U" 5         [        U[        5      (       d  T =R                  U-  sl        U" 5         T R                  c  ST l	        gT R
                  R                  T5      T l	        g)a  Update the progress bar with the given options.

Example:
    ```py
    progress_bar.update(
        total=200,  # Set new total to 200 steps.
        progress=50,  # Set the progress to 50 (out of 200).
    )
    ```

Args:
    total: New total number of steps.
    progress: Set the progress to the given number of steps.
    advance: Advance the progress by this number of steps.
Nc                 ó¬   >• TR                   bF  TR                  (       a4  TR                  R                  T TR                   TR                  -  5        ggg)zAdd a new sample.N)r‹   rŒ   r“   Ú
add_sample)Úcurrent_timer'   s   €€r*   r³   Ú&ProgressBar.update.<locals>.add_sampler  s<   ø€ à�}‰}Ñ(¨T¯Z¯ZØ—	‘	×$Ñ$ \°4·=±=À4Ç:Á:Ñ3MÕNð .8Ð(r,   ©rZ   r[   )
r"   rK   Ú
isinstancer   rŒ   r“   r˜   r‹   Úget_etar�   )r'   rŒ   r‹   r¯   r³   r´   s   `    @r*   r–   ÚProgressBar.updateV  s½   ù€ ð, —{‘{×'Ñ'ˆÜ˜%¤×1Ñ1Ø‰} ¨¯©Ó 3Ø—	‘	—‘Ô!ØˆDŒJ÷	Oð 	Oô
 ˜(¤O×4Ñ4Ø$ˆDŒMÙŒLä˜'¤?×3Ñ3Ø�MŠM˜WÑ$�MÙŒLð —J‘JÑ&ˆDð 	ÕØ,0¯I©I×,=Ñ,=¸lÓ,Kð 	Õr,   )r"   r�   r“   r‹   r�   r‘   r�   rŒ   )N)rŒ   rY   r�   rU   r�   rU   r‘   rU   r   rT   r   rT   r   rT   r    rU   r(   rV   r   rW   r¶   )rZ   r   )rŒ   rY   rZ   rY   )rZ   rY   )r‹   rd   rZ   r[   )rŒ   rd   rZ   r[   )r:   )r¯   rd   rZ   r[   )rŒ   zNone | float | UnusedParameterr‹   úfloat | UnusedParameterr¯   rº   rZ   r[   )r]   r^   r_   r`   ra   rc   r   r‹   re   r   rd   rŒ   r   r1   r�   r   rf   rŽ   r$   r™   rž   r¢   r¥   r©   r¬   r¯   ÚUNUSEDr–   rg   rh   ri   s   @r*   rˆ   rˆ   Å   sŽ  ø‡ Ù ð€Kñ !)¨£€HˆoÓ-Ø2Ø$,¨X°e©_Ò$=¸dÓ$C€EÐ!ÓCðð *2°(¸5±/Ò)BÀ4Ó)H€JÐ&ÓHðð *2°(¸3±-Ò)@ÀÓ)F€LÐ&ÓFá*2°4«.€HÐ'Ó8ØEà*7€NÐ'Ó7ØLð #ð/:ð Ø $ØØØØ"ØØ"Ø$(ñ/:àð/:ð ð	/:ð
 ð/:ð ð/:ð ð/:ð ð/:ð ð/:ð ð/:ð ð/:ð "÷/:ñ /:ôbô

Nôô	ô'ô!ö%ð  17Ø,2Ø+1ñ+
ð .ð+
ð *ð	+
ð
 )ð+
ð 
÷+
ó +
r,   rˆ   N)"ra   Ú
__future__r   Útypingr   r   Ú
rich.styler   Útextual._typesr   Útextual.appr   r	   Útextual.clockr
   Útextual.colorr   Útextual.etar   Útextual.geometryr   Útextual.reactiver   Útextual.renderables.barr   rf   Útextual.widgetr   Útextual.widgetsr   r»   rl   ry   rˆ   rw   r,   r*   Ú<module>rÉ      su   ðÙ 'å "ç !å å *ß 3Ý Ý "Ý Ý "Ý %Ý 8Ý !Ý !á	Ó	€Ø %ôz
ˆ&˜Eò z
ôzK�uô Kô(?�ô ?ô8|
�& Eó |
r,   