Skip to content

Commit

Permalink
Fixed #1, and created wheel and source files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Chen committed Mar 8, 2018
1 parent f94cc1c commit 3467e15
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 213 deletions.
63 changes: 52 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ prog.end()
Output:

```
Initial State:
Initial State:
:-) Progress: 0% -------------------------------------------------- OK!
When progress is 50:
When progress is 50:
:-) Progress: 50% #########################------------------------- OK!
Final State:
Final State:
:-) Progress: 100% ################################################## OK!
```

Expand All @@ -89,13 +89,13 @@ You can also add more options to make it look good.
Adding options `complete_symbol="█", not_complete_symbol="-"` will change the original output to:

```
Initial State:
Initial State:
:-) Progress: 0% -------------------------------------------------- OK!
When progress is 50:
When progress is 50:
:-) Progress: 50% █████████████████████████------------------------- OK!
Final State:
Final State:
:-) Progress: 100% ██████████████████████████████████████████████████ OK!
```

Expand Down Expand Up @@ -164,13 +164,13 @@ prog.end()
Output:

```
Initial State:
Initial State:
:-) 0/56 OK!
When half done:
When half done:
:-) 28/56 OK!
Final State:
Final State:
:-) 56/56 OK!
```

Expand Down Expand Up @@ -294,67 +294,102 @@ Initial status to show on the indicator.

#### set_stat()

Available on: PyProg 1.0.0 ~
Params: current

Set the current progress.

#### stat()

Available on: PyProg 1.1.0-0 ~
Params: current
Note: This function is currently only available on the ProgressBar. Support for ProgressIndicatorFraction will come soon.

Set the current progress and update the progress bar.

#### progress()

Available on: PyProg 1.1.0-0 ~
Params: progress
Note: This function is currently only available on the ProgressBar. Support for ProgressIndicatorFraction will come soon.

Increase the progress by the given amount.

#### update()

Available on: PyProg 1.0.0 ~
Params: (none)

Update the progress bar so that it shows the current progress.<br/>
Note: Also call this to initiate the bar.

#### end()

Available on: PyProg 1.0.0 ~
Params: (none)

End the progress bar.

#### end_m()

Available on: PyProg 1.1.0-0 ~
Params: msg
Note: This function is currently only available on the ProgressBar. Support for ProgressIndicatorFraction will come soon.

End the progress bar with a message.

#### set_prefix()

Available on: PyProg 1.0.0 ~
Params: prefix

Set the prefix

#### set_suffix()

Available on: PyProg 1.0.0 ~
Params: suffix

Set the suffix

#### set_total()

Available on: PyProg 1.0.0 ~
Params: total

Set the total

#### set_bar_length()

Available on: PyProg 1.0.0 ~
Params: bar_length

Set the length of the bar

#### set_decimals()

Available on: PyProg 1.0.0 ~
Params: decimals

Set the number of decimals for the percent

#### set_symbols()

Available on: PyProg 1.0.0 ~
Params: symbols

Set the complete symbol and the not complete symbol. `symbols` has to be a tuple: (complete symbol, not complete symbol)

#### set_progress_loc()

Available on: PyProg 1.0.0 ~
Params: progress_loc

Set the progress explanation (prefix) and the progress text location. See [the progress_loc parameter](#user-content-progress_loc-default-is-0 "progress_loc") section for the possible values.

#### set_progress_explain()

Available on: PyProg 1.0.0 ~
Params: progress_explain

Set the progress explanation (prefix).
Expand All @@ -365,12 +400,14 @@ Examples:<br/>

#### set_wrap_bar_text()

Available on: PyProg 1.0.0 ~
Params: prefix, suffix

Set the wrap bar text (the prefix and the suffix of the bar).

#### set_progress_format()

Available on: PyProg 1.0.0 ~
Params: progress_format

Set the format for the progress text. PyProg replaces special characters with actual values. Here is a list of special characters:
Expand All @@ -382,37 +419,43 @@ Set the format for the progress text. PyProg replaces special characters with ac

#### set_stat()

Available on: PyProg 1.0.0 ~
Params: current

Set the current progress.

#### update()

Available on: PyProg 1.0.0 ~
Params: (none)

Update the progress indicator so that it shows the current progress.
Note: Also call this to initiate the indicator.

#### end()

Available on: PyProg 1.0.0 ~
Params: (none)

End the progress indicator.

#### set_prefix()

Available on: PyProg 1.0.0 ~
Params: prefix

Set the prefix

#### set_suffix()

Available on: PyProg 1.0.0 ~
Params: suffix

Set the suffix

#### set_total()

Available on: PyProg 1.0.0 ~
Params: total

Set the total
Expand All @@ -422,5 +465,3 @@ Set the total
If you want to support me, please contact me at [email protected].

My website is at [http://www.WhatsYourIdea.com/](http://www.WhatsYourIdea.com/ "Website")


39 changes: 33 additions & 6 deletions build/lib/pyprog/ProgressBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ProgressBar:
PROGRESS_LOC_EXP_END_PROGRESS_MID = 4

def __init__(self, prefix, suffix, total=100, bar_length=50, initial=0, decimals=0, complete_symbol="#", not_complete_symbol="-", progress_loc=0, progress_format="+p%", progress_explain="Progress: ", wrap_bar_prefix=" ", wrap_bar_suffix=" "):
self.__end_m = False
self.p = prefix
self.s = suffix
self.length = bar_length
Expand All @@ -26,6 +27,7 @@ def __init__(self, prefix, suffix, total=100, bar_length=50, initial=0, decimals

def __print(self, data, start="", end=""):
sys.stdout.write(start + data + end)
sys.stdout.flush()

def set_prefix(self, prefix):
'''
Expand Down Expand Up @@ -105,10 +107,24 @@ def set_progress_format(self, progress_format):

def set_stat(self, current):
'''
Set the current progress. Only accept integers.
Set the current progress.
'''
self.current_stat = current

def stat(self, current):
'''
Set the current progress and showing the progress bar.
'''
self.current_stat = current
self.update()

def progress(self, progress=1):
'''
Progress forward by an amount.
'''
self.current_stat += progress
self.update()

def update(self):
'''
Update the progress bar so that it shows the current progress.
Expand All @@ -120,11 +136,15 @@ def update(self):
final = self.complete_sym * blocks_to_fill + self.not_complete_sym * blocks_not_to_fill
final = self.wrap_bar_prefix + final + self.wrap_bar_suffix
percent = round(round(decimal, self.decimals + 2) * 100, self.decimals + 2)
if percent.is_integer():
progress_str = self.progress_format.replace("+p", str(int(percent)))
if self.__end_m:
progress_str = ""
self.progress_explain = self.__end_m
else:
progress_str = self.progress_format.replace("+p", str(percent))
progress_str = progress_str.replace("+c", str(self.current_stat))
if percent.is_integer():
progress_str = self.progress_format.replace("+p", str(int(percent)))
else:
progress_str = self.progress_format.replace("+p", str(percent))
progress_str = progress_str.replace("+c", str(self.current_stat))
if self.progress_loc == ProgressBar.PROGRESS_LOC_START:
final = self.progress_explain + progress_str + final
elif self.progress_loc == ProgressBar.PROGRESS_LOC_MIDDLE:
Expand Down Expand Up @@ -161,9 +181,16 @@ def update(self):
final = self.p + final + self.s
self.__print(final, start="\r")

def end_m(self, msg):
'''
End the progress bar with a message.
'''
self.__end_m = msg
self.update()
self.end()

def end(self):
'''
End the progress bar.
'''
self.__print("", end="\n")

2 changes: 1 addition & 1 deletion build/lib/pyprog/ProgressIndicatorFraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(self, prefix, suffix, total, initial=0):

def __print(self, data, start="", end=""):
sys.stdout.write(start + data + end)
sys.stdout.flush()

def set_prefix(self, prefix):
'''
Expand Down Expand Up @@ -49,4 +50,3 @@ def end(self):
End the progress indicator.
'''
self.__print("", end="\n")

Binary file removed dist/pyprog-1.0.2-py2.py3-none-any.whl
Binary file not shown.
Binary file removed dist/pyprog-1.0.2.tar.gz
Binary file not shown.
Binary file added dist/pyprog-1.1.0.post0-py2.py3-none-any.whl
Binary file not shown.
Binary file added dist/pyprog-1.1.0.post0.tar.gz
Binary file not shown.
Loading

0 comments on commit 3467e15

Please sign in to comment.