ó <Ô­Tc@ sïdZddlmZddlZddlZddlZddlZddlZy0ddlm Z ddl m Z ddl Z Wne k r•nXddl TddlTdZdZd Zd Zd dd „ƒYZd efd„ƒYZdS(sMText progress bar library for Python. A text progress bar is typically used to display the progress of a long running operation, providing a visual cue that processing is underway. The ProgressBar class manages the current progress, and the format of the line is given by a number of widgets. A widget is an object that may display differently depending on the state of the progress bar. There are three types of widgets: - a string, which always shows itself - a ProgressBarWidget, which may return a different value every time its update method is called - a ProgressBarWidgetHFill, which is like ProgressBarWidget, except it expands to fill the remaining width of the line. The progressbar module is very easy to use, yet very powerful. It will also automatically enable features like auto-resizing when the system supports it. iÿÿÿÿ(tdivisionN(tioctl(tarray(t*sNilton Volpatos$first-name dot last-name @ gmail.coms 2011-05-14s2.3t UnknownLengthcB seZRS((t__name__t __module__(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyRDst ProgressBarcB sãeZdZd$ZdZdZeƒdeƒgZd%d%d%de e j d„Z d„Zd„Zd„ZeZd„Zd%d%d„Zd„ZeeƒZd„Zd„Zd„Zd „Zd%d!„Zd"„Zd#„ZRS(&sÌThe ProgressBar class which updates and prints the bar. A common way of using it is like: >>> pbar = ProgressBar().start() >>> for i in range(100): ... # do something ... pbar.update(i+1) ... >>> pbar.finish() You can also use a ProgressBar as an iterator: >>> progress = ProgressBar() >>> for i in progress(some_iterable): ... # do something ... Since the progress bar is incredibly customizable you can specify different widgets of any type in any order. You can even write your own widgets! However, since there are already a good number of widgets you should probably play around with them before moving on to create your own widgets. The term_width parameter represents the current terminal width. If the parameter is set to an integer then the progress bar will use that, otherwise it will attempt to determine the terminal width falling back to 80 columns if the width cannot be determined. When implementing a widget's update method you are passed a reference to the current progress bar. As a result, you have access to the ProgressBar's methods and attributes. Although there is nothing preventing you from changing the ProgressBar you should treat it as read only. Useful methods and attributes include (Public API): - currval: current progress (0 <= currval <= maxval) - maxval: maximum (and final) value - finished: True if the bar has finished (reached 100%) - start_time: the time when start() method of ProgressBar was called - seconds_elapsed: seconds elapsed since start_time and last call to update - percentage(): progress in percent [0..100] tcurrvaltfdtfinishedtlast_update_timet left_justifytmaxvalt next_updatet num_intervalstpolltseconds_elapsedt signal_sett start_timet term_widthtupdate_intervaltwidgetst_time_sensitivet __iterableidiPt icC s+|dkrt|jƒ}n||_||_||_||_t|_|dk rc||_ nry@|j ƒt j t j |j ƒt j t j tƒt|_Wn/ttfk r¿‚n|jƒ|_ nXd|_|jƒd|_t|_d|_||_d|_d|_d|_dS(s-Initializes a progress bar with sane defaultsiiN(tNonetlistt_DEFAULT_WIDGETSR RR R tFalseRRt_handle_resizetsignaltSIGWINCHt siginterrupttTruet SystemExittKeyboardInterruptt _env_sizet_ProgressBar__iterablet_update_widgetsRR R RRRR(tselfR RRRR R ((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt__init__|s6                  cC sKyt|ƒ|_Wn"|jdkr8t|_q8nXt|ƒ|_|S(s0Use a ProgressBar to iterate through an iterableN(tlenR RRtiterR&(R(titerable((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt__call__¡scC s|S(N((R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt__iter__®scC slyGt|jƒ}|jdkr.|jƒn|j|jdƒ|SWntk rg|jƒ‚nXdS(Ni( tnextR&RRtstarttupdateRt StopIterationtfinish(R(tvalue((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt__next__²s   cC s ttjjd|jƒƒdS(s2Tries to find the term_width from the environment.tCOLUMNSi(tinttostenvirontgett_DEFAULT_TERMSIZE(R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyR%ÂscC s8tdt|jtjdƒƒd \}}||_dS(s5Tries to catch resize signals sent from the terminal.thtiiNt(RRR ttermiost TIOCGWINSZR(R(tsignumtframeR<tw((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyRÈs+cC s|jd|jS(s%Returns the progress as a percentage.gY@(RR (R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt percentageÏscC sg}g}|j}xxt|jƒD]g\}}t|tƒr`|j|ƒ|jd|ƒq%t||ƒ}|j|ƒ|t|ƒ8}q%Wt|ƒ}xv|rt t t j |d|ƒƒdƒ}|j ƒ}|d8}||j||ƒ}|t|ƒ8}|||sN(tanyRR(R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyR's cC sæ|dk rb|tk rb|jtk rVd|koA|jkn rVtdƒ‚n||_n|jƒsrdS|jdkrtdƒ‚ntjƒ}||j|_ |j|j |_ |j j |jƒdƒ||_dS(s'Updates the ProgressBar to a new value.isValue out of rangeNs-You must call "start" before calling "update"s (RRR t ValueErrorRR^Rt RuntimeErrorR\RRRR twriteR[R (R(R4tnow((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyR1 s    cC s¦|jdkr|j|_ntd|jƒ|_d|_|jtk r|jdkritdƒ‚n|j|j|_ nt j ƒ|_ |_ |j dƒ|S(sStarts measuring time, and prints the bar at 0%. It returns self so you can use it like this: >>> pbar = ProgressBar().start() >>> for i in range(100): ... # do something ... pbar.update(i+1) ... >>> pbar.finish() idisValue out of rangeN(R Rt_DEFAULT_MAXVALRKRRRRRcRR\RR R1(R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyR0 s   cC sOt|_|j|jƒ|jjdƒ|jrKtjtjtj ƒndS(s/Puts the ProgressBar bar in the finished state.s N( R"R R1R R ReRRR tSIG_DFL(R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyR3=s   (scurrvalsfdsfinishedslast_update_times left_justifysmaxvals next_updates num_intervalsspollsseconds_elapseds signal_sets start_times term_widthsupdate_intervalswidgetss_time_sensitives __iterableN(RRt__doc__t __slots__RgR;t PercentagetBarRRR"tsyststderrR)R-R.R5R/R%RRDtpropertytpercentRVR[R^R'R1R0R3(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyRGs4) $          ((Rit __future__RRLR8RRmR\tfcntlRRR?t ImportErrortprogressbar.compattprogressbar.widgetst __author__t__author_email__t__date__t __version__RtobjectR(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt)s(