diff --git a/README.md b/README.md index 19fdbe3..89eacfa 100644 --- a/README.md +++ b/README.md @@ -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! ``` @@ -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! ``` @@ -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! ``` @@ -294,12 +294,30 @@ 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.
@@ -307,54 +325,71 @@ 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). @@ -365,12 +400,14 @@ Examples:
#### 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: @@ -382,12 +419,14 @@ 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. @@ -395,24 +434,28 @@ 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 @@ -422,5 +465,3 @@ Set the total If you want to support me, please contact me at kudoshiko@gmail.com. My website is at [http://www.WhatsYourIdea.com/](http://www.WhatsYourIdea.com/ "Website") - - diff --git a/build/lib/pyprog/ProgressBar.py b/build/lib/pyprog/ProgressBar.py index dd30672..ae86b43 100644 --- a/build/lib/pyprog/ProgressBar.py +++ b/build/lib/pyprog/ProgressBar.py @@ -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 @@ -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): ''' @@ -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. @@ -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: @@ -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") - diff --git a/build/lib/pyprog/ProgressIndicatorFraction.py b/build/lib/pyprog/ProgressIndicatorFraction.py index 0afa178..0a0c479 100644 --- a/build/lib/pyprog/ProgressIndicatorFraction.py +++ b/build/lib/pyprog/ProgressIndicatorFraction.py @@ -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): ''' @@ -49,4 +50,3 @@ def end(self): End the progress indicator. ''' self.__print("", end="\n") - diff --git a/dist/pyprog-1.0.2-py2.py3-none-any.whl b/dist/pyprog-1.0.2-py2.py3-none-any.whl deleted file mode 100644 index 7dcc8c8..0000000 Binary files a/dist/pyprog-1.0.2-py2.py3-none-any.whl and /dev/null differ diff --git a/dist/pyprog-1.0.2.tar.gz b/dist/pyprog-1.0.2.tar.gz deleted file mode 100644 index 79a1961..0000000 Binary files a/dist/pyprog-1.0.2.tar.gz and /dev/null differ diff --git a/dist/pyprog-1.1.0.post0-py2.py3-none-any.whl b/dist/pyprog-1.1.0.post0-py2.py3-none-any.whl new file mode 100644 index 0000000..bf64eef Binary files /dev/null and b/dist/pyprog-1.1.0.post0-py2.py3-none-any.whl differ diff --git a/dist/pyprog-1.1.0.post0.tar.gz b/dist/pyprog-1.1.0.post0.tar.gz new file mode 100644 index 0000000..7b954bf Binary files /dev/null and b/dist/pyprog-1.1.0.post0.tar.gz differ diff --git a/pyprog.egg-info/PKG-INFO b/pyprog.egg-info/PKG-INFO index 96787cb..c0cec83 100644 --- a/pyprog.egg-info/PKG-INFO +++ b/pyprog.egg-info/PKG-INFO @@ -1,192 +1,192 @@ -Metadata-Version: 1.0 -Name: pyprog -Version: 1.0.2 -Summary: A library for creating super customizable progress indicators. -Home-page: https://github.com/Bill13579/pyprog -Author: Bill Kudo -Author-email: bluesky42624@gmail.com -License: GNU AGPLv3 -Description: PyProg is an Open-Source library for creating progress indicators (e.g. progress bars). It helps you create customizable progress indicators. This library is for Python. It does not have any dependencies. - - ============= - Compatibility - ============= - - PyProg is compatible with both Python 3 and Python 2. - - ============ - Installation - ============ - - Latest build: ``pip install pyprog`` - - Latest development build: ``pip install git+https://github.com/Bill13579/pyprog.git@develop`` - - After you have installed PyProg, you can test if it has been successfully installed by running ``import pyprog`` in python. If PyProg was installed successfully, it should show no errors. - - ================================== - How to use the PyProg Progress Bar - ================================== - - To create a progress bar, follow these steps: - - 1. Import PyProg: ``import pyprog`` - 2. Create a ``ProgressBar`` object: ``prog = pyprog.ProgressBar("", "")`` - 3. Show the bar: ``prog.update()`` - 4. To update the status, use ``prog.set_stat()`` to set the status and then use ``prog.update()`` to actually show the change - 5. When finished, use ``prog.end()`` to make the Progress Bar last - - Example Code with Fake For loop: - - .. code-block:: python - - import pyprog - from time import sleep - - # Create a PyProg ProgressBar Object - prog = pyprog.ProgressBar(":-) ", " OK!") - - # Show the initial status - prog.update() - - # Fake for loop - for i in range(0, 100): - - # Sleep for a while (This is just to slow down the for loop so that it won't end in an instant) - sleep(0.1) - - # Update status - prog.set_stat(i + 1) - - # Show (Update) the current status - prog.update() - - # Make the Progress Bar final - prog.end() - - Output: - - .. code-block:: - - Initial State: - :-) Progress: 0% -------------------------------------------------- OK! - - When progress is 50: - :-) Progress: 50% #########################------------------------- OK! - - Final State: - :-) Progress: 100% ################################################## OK! - - Pretty Progress Bar - =================== - - You can also add more options to make it look good. - - Adding options ``complete_symbol="â–ˆ", not_complete_symbol="-"`` will change the original output to: - - .. code-block:: - - Initial State: - :-) Progress: 0% -------------------------------------------------- OK! - - When progress is 50: - :-) Progress: 50% █████████████████████████------------------------- OK! - - Final State: - :-) Progress: 100% ██████████████████████████████████████████████████ OK! - - Auto calculate the percentage - ============================= - - PyProg can also auto calculate the current percentage. You just need to tell PyProg the total number of things you need to process. - - Change the line ``prog = pyprog.ProgressBar("", "")`` to ``prog = pyprog.ProgressBar("", "", )``, and PyProg will calculate the percentage for you based on the status that you give it. - - To use it in our simple progress bar code, if we have 37 tasks to do, we can change this: - - .. code-block:: python - - # Create a PyProg ProgressBar Object - prog = pyprog.ProgressBar(":-) ", " OK!") - - to this: - - .. code-block:: python - - # Create a PyProg ProgressBar Object - prog = pyprog.ProgressBar(":-) ", " OK!", 37) - - And also change the fake for loop from ``for i in range(0, 100):`` to ``for i in range(0, 37):``, and it will auto calculate the percentage and show it to the user. - - =================================================== - How to use the PyProg Progress Indicator (Fraction) - =================================================== - - To create a basic progress indicator (fraction), follow these steps: - - 1. Import PyProg: ``import pyprog`` - 2. Create a ``ProgressIndicatorFraction`` object: ``prog = pyprog.ProgressIndicatorFraction("", "", )`` (Replace "" with the total number of tasks or things you need to process) - 3. Show the indicator: ``prog.update()`` - 4. To update the status, use ``prog.set_stat()`` to set the status and then use ``prog.update()`` to actually show the change - 5. When finished, use ``prog.end()`` to make the Progress Indicator (Fraction) last - - Example Code with Fake For loop (We are using 56 as the total in this example): - - .. code-block:: python - - import pyprog - from time import sleep - - # Create a PyProg ProgressIndicatorFraction Object - prog = pyprog.ProgressIndicatorFraction(":-) ", " OK!", 56) - - # Show the initial status - prog.update() - - # Fake for loop - for i in range(0, 56): - - # Sleep for a while (This is just to slow down the for loop so that it won't end in an instant) - sleep(0.1) - - # Update status - prog.set_stat(i + 1) - - # Show (Update) the current status - prog.update() - - # Make the Progress Indicator (Fraction) final - prog.end() - - Output: - - .. code-block:: - - Initial State: - :-) 0/56 OK! - - When half done: - :-) 28/56 OK! - - Final State: - :-) 56/56 OK! - - ============= - Documentation - ============= - - The documentation is at the Github page for this project. - - Github page: ``_ - - ======= - Contact - ======= - - If you want to support me, please contact me at kudoshiko@gmail.com. - - My website is at ``_ - - -Keywords: progress bar indicator pyprog -Platform: UNKNOWN +Metadata-Version: 1.0 +Name: pyprog +Version: 1.1.0.post0 +Summary: A library for creating super customizable progress indicators. +Home-page: https://github.com/Bill13579/pyprog +Author: Bill Kudo +Author-email: bluesky42624@gmail.com +License: GNU AGPLv3 +Description: PyProg is an Open-Source library for creating progress indicators (e.g. progress bars). It helps you create customizable progress indicators. This library is for Python. It does not have any dependencies. + + ============= + Compatibility + ============= + + PyProg is compatible with both Python 3 and Python 2, and will also work on Qt Console. + + ============ + Installation + ============ + + Latest build: ``pip install pyprog`` + + Latest development build: ``pip install git+https://github.com/Bill13579/pyprog.git@develop`` + + After you have installed PyProg, you can test if it has been successfully installed by running ``import pyprog`` in python. If PyProg was installed successfully, it should show no errors. + + ================================== + How to use the PyProg Progress Bar + ================================== + + To create a progress bar, follow these steps: + + 1. Import PyProg: ``import pyprog`` + 2. Create a ``ProgressBar`` object: ``prog = pyprog.ProgressBar("", "")`` + 3. Show the bar: ``prog.update()`` + 4. To update the status, use ``prog.set_stat()`` to set the status and then use ``prog.update()`` to actually show the change + 5. When finished, use ``prog.end()`` to make the Progress Bar last + + Example Code with Fake For loop: + + .. code-block:: python + + import pyprog + from time import sleep + + # Create a PyProg ProgressBar Object + prog = pyprog.ProgressBar(":-) ", " OK!") + + # Show the initial status + prog.update() + + # Fake for loop + for i in range(0, 100): + + # Sleep for a while (This is just to slow down the for loop so that it won't end in an instant) + sleep(0.1) + + # Update status + prog.set_stat(i + 1) + + # Show (Update) the current status + prog.update() + + # Make the Progress Bar final + prog.end() + + Output: + + .. code-block:: + + Initial State: + :-) Progress: 0% -------------------------------------------------- OK! + + When progress is 50: + :-) Progress: 50% #########################------------------------- OK! + + Final State: + :-) Progress: 100% ################################################## OK! + + Pretty Progress Bar + =================== + + You can also add more options to make it look good. + + Adding options ``complete_symbol="█", not_complete_symbol="-"`` will change the original output to: + + .. code-block:: + + Initial State: + :-) Progress: 0% -------------------------------------------------- OK! + + When progress is 50: + :-) Progress: 50% █████████████████████████------------------------- OK! + + Final State: + :-) Progress: 100% ██████████████████████████████████████████████████ OK! + + Auto calculate the percentage + ============================= + + PyProg can also auto calculate the current percentage. You just need to tell PyProg the total number of things you need to process. + + Change the line ``prog = pyprog.ProgressBar("", "")`` to ``prog = pyprog.ProgressBar("", "", )``, and PyProg will calculate the percentage for you based on the status that you give it. + + To use it in our simple progress bar code, if we have 37 tasks to do, we can change this: + + .. code-block:: python + + # Create a PyProg ProgressBar Object + prog = pyprog.ProgressBar(":-) ", " OK!") + + to this: + + .. code-block:: python + + # Create a PyProg ProgressBar Object + prog = pyprog.ProgressBar(":-) ", " OK!", 37) + + And also change the fake for loop from ``for i in range(0, 100):`` to ``for i in range(0, 37):``, and it will auto calculate the percentage and show it to the user. + + =================================================== + How to use the PyProg Progress Indicator (Fraction) + =================================================== + + To create a basic progress indicator (fraction), follow these steps: + + 1. Import PyProg: ``import pyprog`` + 2. Create a ``ProgressIndicatorFraction`` object: ``prog = pyprog.ProgressIndicatorFraction("", "", )`` (Replace "" with the total number of tasks or things you need to process) + 3. Show the indicator: ``prog.update()`` + 4. To update the status, use ``prog.set_stat()`` to set the status and then use ``prog.update()`` to actually show the change + 5. When finished, use ``prog.end()`` to make the Progress Indicator (Fraction) last + + Example Code with Fake For loop (We are using 56 as the total in this example): + + .. code-block:: python + + import pyprog + from time import sleep + + # Create a PyProg ProgressIndicatorFraction Object + prog = pyprog.ProgressIndicatorFraction(":-) ", " OK!", 56) + + # Show the initial status + prog.update() + + # Fake for loop + for i in range(0, 56): + + # Sleep for a while (This is just to slow down the for loop so that it won't end in an instant) + sleep(0.1) + + # Update status + prog.set_stat(i + 1) + + # Show (Update) the current status + prog.update() + + # Make the Progress Indicator (Fraction) final + prog.end() + + Output: + + .. code-block:: + + Initial State: + :-) 0/56 OK! + + When half done: + :-) 28/56 OK! + + Final State: + :-) 56/56 OK! + + ============= + Documentation + ============= + + The documentation is at the Github page for this project. + + Github page: ``_ + + ======= + Contact + ======= + + If you want to support me, please contact me at kudoshiko@gmail.com. + + My website is at ``_ + + +Keywords: progress bar indicator pyprog +Platform: UNKNOWN diff --git a/pyprog/ProgressBar.py b/pyprog/ProgressBar.py index 39557b7..ae86b43 100644 --- a/pyprog/ProgressBar.py +++ b/pyprog/ProgressBar.py @@ -27,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): ''' diff --git a/pyprog/ProgressBar.pyc b/pyprog/ProgressBar.pyc index fa2c1f0..77233e6 100644 Binary files a/pyprog/ProgressBar.pyc and b/pyprog/ProgressBar.pyc differ diff --git a/pyprog/ProgressIndicatorFraction.py b/pyprog/ProgressIndicatorFraction.py index 0afa178..0a0c479 100644 --- a/pyprog/ProgressIndicatorFraction.py +++ b/pyprog/ProgressIndicatorFraction.py @@ -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): ''' @@ -49,4 +50,3 @@ def end(self): End the progress indicator. ''' self.__print("", end="\n") - diff --git a/pyprog/ProgressIndicatorFraction.pyc b/pyprog/ProgressIndicatorFraction.pyc index eec0b1a..4d55319 100644 Binary files a/pyprog/ProgressIndicatorFraction.pyc and b/pyprog/ProgressIndicatorFraction.pyc differ diff --git a/pyprog/__pycache__/ProgressBar.cpython-35.pyc b/pyprog/__pycache__/ProgressBar.cpython-35.pyc index 1db4ee2..ce67b7e 100644 Binary files a/pyprog/__pycache__/ProgressBar.cpython-35.pyc and b/pyprog/__pycache__/ProgressBar.cpython-35.pyc differ diff --git a/setup.py b/setup.py index f2b4c63..4a013c8 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name = 'pyprog', - version = '1.0.2', + version = '1.1.0-0', packages = find_packages(), description = ('A library for creating super customizable progress indicators.'), long_description = long_description, @@ -15,4 +15,4 @@ license = 'GNU AGPLv3', url = 'https://github.com/Bill13579/pyprog', keywords = 'progress bar indicator pyprog', -) \ No newline at end of file +)