<ԭTc@ sdZddlmZddlZddlZddlZddlZddlZy0ddlm Z ddl m Z ddl Z Wne k rnXddl TddlTdZdZd Zd Zd dd YZd efdYZdS(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 seZdZd$ZdZdZedegZd%d%d%de e j dZ dZdZdZeZdZd%d%dZdZeeZdZdZdZd Zd%d!Zd"Zd#ZRS(&sThe 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 tt|_Wn/ttfk rn|j|_ nXd|_|jd|_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.|jn|j|jd|SWntk rg|jnXdS(Ni( tnextR&RRtstarttupdateRt StopIterationtfinish(R(tvalue((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt__next__s   cC s ttjjd|jdS(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|jtjdd \}}||_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__.pyRs+cC s|jd|jS(s%Returns the progress as a percentage.gY@(RR (R(((s8/usr/lib/python2.7/site-packages/progressbar/__init__.pyt percentagescC sg}g}|j}xxt|jD]g\}}t|tr`|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 rVtdn||_n|jsrdS|jdkrtdntj}||j|_ |j|j |_ |j j |jd||_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|jdkritdn|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(