Skip to main content

Easy to make progress bars

Project description

1 ConsLoadingBar Documentation

Creator: FlameChain

Github Link: flamechain/Modules/

PyPi Link: project/ConsLoadingBar

If this PyPi link doesn't work, you can try finding it on pydigger.

Note: Some links may not work as this documentation was made for github. You can visit that github page to have the full expeirence, and get some extra documentation, by clicking the link above or here.

Version: 1.3.0

Description: A module to make easy progress bars with lots of customizability and a built-in demo class to show whats possible.


1.1 Contents


1.2 New Changes

Notice: Please report any bugs directly to me and they will be acknowledged and added to this page. You can view all contact details at pydigger, PyPi, and github.


1.3 Installation

1.3.1 PiP

Install via pip using pip install ConsLoadingBar.

pip install ConsLoadingBar

You can also use '==' to specify the version. This would only be used to downgrade.

pip install ConsLoadingBar == 1.2.2

To make sure you have the current version you can use this command instead:

pip install --upgrade ConsLoadingBar

1.3.2 Manual Install (NOT SUGGESTED)

If you want to download the file directly follow these steps:

  1. Download the file here python file named consloadingbar.py here. Make sure you only download the python file, as everything else is for the PiP package.
  2. Open the zip and copy the python file
  3. Move the file into your python directory by going to AppData\Local\Programs\Python\
%appdata%\..\Local\Programs\Python\
  1. Then locate the current python version, is this case, 3.9.
\Python39\Lib

This folder contains all built-in modules, so just paste the python file into there.

Full Path: .\%appdata%\..\Local\Programs\Python\Python39\Lib\


1.4 Quick Start Guide

This is a short guide to get your started with this module. The rest of the documentation is more specific, so you can go on to read that in depth if you have any questions.

1.4.1 Initilizing an instance of Bar()

import consloadingbar, time

lb = consloadingbar.Bar()

This is the default values. You can read more on the parameters further in the documentation. You should also import time for later.

1.4.2 Using the progress() method

To do this, just trigger the progress() method with the current percentage you want.

lb.progress(0)

This will show a progress bar with 0% complete.

|â–ˆ                   |   0%

Try adjusting the 'current' param to show different percentages of completion. Then you can make a simple for loop to make the bar go up and complete. You can also import the time module and use time.sleep() to create a delay.

for i in range(101):
    lb.progress(i)
    time.sleep(0.01)

1.4.3 Tasks and ETA

You can use tasks by declaring the total task amount with Bar(), and then using progress() to show how many are complete. Try this:

lb = consloadingbar.Bar(taskCount=10)

for i in range(101):
    lb.progress(i, tasksDone=i//10)
    time.sleep(0.01)

You can also put in time to let the program calculate an eta.

start = time.time()

for i in range(101):
    currentTime = time.time() - start
    lb.progress(i, time_=currentTime)
    time.sleep(0.01)

1.4.4 Using the start() method

This method is used to show an empty progress bar. This is similar to the end() method, where it just prints once.

lb = consloadingbar.Bar(useColor=True, taskCount=10)

start = time.time()

lb.start()
for i in range(101):
    currentTime = time.time() - start
    lb.progress(i, time_=currentTime, tasksDone=i//10)
    time.sleep(0.01)

Using default params, calling the start() method would print this to the console:

lb.start()
Running...
        |                    |   0%  [tasks=0/5]

In this example there were 5 tasks specified, so it shows that.

1.4.5 Using the end() method

This method is easy to use. Just call it after the progress bar is done, and it will print a finished screen. You can also enable color via the Bar() class.

lb = consloadingbar.Bar(useColor=True, taskCount=10)

start = time.time()

lb.start()
for i in range(101):
    currentTime = time.time() - start
    lb.progress(i, time_=currentTime, tasksDone=i//10)
    time.sleep(0.01)

lb.end()
Finished
        |████████████████████| 100%

1.5 consloadingbar.Bar()

1.5.1 Parameters

Param Name Description Type Default
barLength The length, in characters, that the bar progress bar expands. This only includes the moving part of the bar. integer 20
useETACalculation Used with the SimulateTasks() class, and changes overall delay on the visual based on prior delay. Used when threading. boolean False
taskCount The total amount of tasks used. If not specified there will be not tasks indicator with the bar. integer None
mainBarChar Used for the moving bar. Often '#' is used. string 'â–ˆ'
progressPointBarChar Used for the front character of the bar. Often '>' is used. string 'â–ˆ'
endPointChars List with 2 indices, the front and last character of the bar. Often '[' and ']' is used. list ['|', '|']
title What the title is for the progress bar while running. string 'Running Tasks...'
useColor If you want to have some color in on the bar. boolean False

1.5.2 Description

This class takes advantage of the python '\r' or 'replace' ending to make a moving progress bar. Its called simply:

import consloadingbar

lb = consloadingbar.Bar(args)

1.5.3 barLength

The length if the moving status bar indicator. In this example its set to 20 using the block character:

|████████████████████|

1.5.4 useETACalculation

When enabled this will estimate how long it will take, based on how long prior tasks took. Sometimes not accurate. Read more about using this here.

1.5.5 taskCount

This is used just for the indicator on the bar to show how many tasks there are. There is no checking if the number of tasks is equal to this value. Both examples use a value of 5:

|                    |   0%  [tasks=0/5]
|████████████████████| 100%  [tasks=5/5]

The top example is before the tasks have started, and the bottom example is after its done. Unlike the eta box, it stays after the tasks are finished.

1.5.6 mainBarChar

This is simply the character used for the bar:

|████████████████████| 100%
|####################| 100%

The top example uses the default block character, and the bottom one used a pound.

1.5.7 progressPointBarChar

This is the head of the current bar status:

|██████████          |  50%
|#########>          |  50%

The top example is the default, and the bottom uses the greater than symbol. The bottom also uses the pound as the barChar because it looks better, and would most likely be used with that more often.

1.5.8 endPointChars

This is a list with the bounds of the bar. The default is the pipe, but with any other character for the bar, e.g. '#', square brackets are more commonly used:

[####################] 100%

1.5.9 title

Title for the progress bar while running. The default is 'Running Tasks...', but it could be anything.

Running Tasks...
        |██████████          |  50%

1.5.10 useColor

Boolian used if you want to have some color. Currently color param only applies to the base class, not the SimulateTasks() class, hence an error message on SimulateTasks() is always red. Default to off because its purely visual and personal preference. This color appears when the end() method is called:

Finished
        |████████████████████| 100%

And also when the pastBar progress bar is being updated, the knew progress is green until its to the right point.


1.6 Using

1.6.1 progressBar()

For this you can call the class like mentioned above, and then use the progress method to change the status of the bar. This is an example using only default values, and setting the status of the bar to 100%.

import consloadingbar

lb = consloadingbar.Bar()
lb.progressBar(100)
|████████████████████| 100%

You can also add tasks to the bar by adding thath parameter to the Bar(), and then telling the progress method how many tasks are done.

lb = consloadingbar.Bar(taskCount=10)

for i in range(11):
    percent = i * 10
    lb.progressBar(percent, tasksDone=i)

In this example, every iteration the bar's completion goes up by 10%, and 1 task finishes. Here is the result of the bar after completion.

Finished
        |████████████████████| 100%  [tasks=10/10]

To use the eta, just specify how long its been since starting. The eta gets automatically calculated from there.

import consloadingbar, time

lb = consloadingbar.Bar(taskCount=10)
startTime = time.time()

for i in range(11):
    percent = i * 10
    currentTime = time.time() - startTime

    lb.progressBar(percent, time_=currentTime, tasksDone=i)

    time.sleep(0.1)

In this example, we use the time module to calculate how many seconds have passed. Then we simple pass how much time has elapsed into the bar. This is what the bar would look like at iteration 6, just over half way. Notice how we also used time.sleep() to make it look more real.

|████████████        |  60%  [eta=00:04.36] [tasks=6/10]

1.6.2 start()

This method is most similar to the end() method. It shows an empty progress bar.

Running...
        |                    |   0%  [tasks=0/5]

1.6.3 end()

What this does is it just prints the consloadingbar with all values maxed out, and eta gone (if there was one).

lb = consloadingbar.Bar(taskCount=5)

lb.end()
Finished
        |████████████████████| 100%  [tasks=5/5]

1.6.4 progressCircle()

This was made to replace the old start() method. This shows a title, and a spinning circle that either goes until stopped using threading, or stops after a specified time.

lb.progressCircle(time_=2)
Loading /

This simple code example will run this spinning circle loading indicator for 2 seconds, then it stops itself. Read more on threading it externally here.

1.7 consloadingbar.SimulateTasks()

1.7.1 Parameters (SimulateTasks)

Param Name Description Optional Default
eta Changes overall delay on the visual. Not exact, only average. Based on seconds True 15
barLength The length, in characters, that the bar progress bar expands. This only includes the moving part of the bar. True 20

All parameters have been explained above in the Bar() parameters section. These values go directly into that class.

1.7.2 Example

This has been shown above, but here are a couple examples of the output it could print.

Start

Loading Tasks /

Middle

Running Tasks...
        |███████████████     |  79%  [eta=00:07.07] [tasks=4/5]

End

Finshed
        |████████████████████| 100%  [tasks=5/5]

1.8 Advanced Features

1.8.1 pastBar

This is a parameter to the progress method. All of progress's methods will we listed here.

Param Name Description Optional Default
current Current percentage you want the bar to show. False
time_ How long has elapsed since the start of the bar. Used for eta. True None
tasksDone How many tasks are complete. Used for visualization True 0
pastBar Used for dynamic animation. True None

pastBar is at the bottom because its hardest to use. Basically progress will return a value if this is not None, and then you put that value back into progress.

past = 0
past = lb.progress(0, pastBar=past)

time.sleep(1)
past = lb.progress(50, pastBar=past)

time.sleep(1)
past = lb.progress(100, pastBar=past)

Each second it will jump up by 50 percent, but the bar will update each character with a tiny delay, so it appears to go up more slowly, instead of a sudden jump.

Note: The progress() method only returns when pastBar is specified, thats why the past variable needed to be defined first so it could be used for the first iteration. Likewise at the end, the past var is not doing anything, just a placeholder for the return value.

1.8.2 SimulateTasks() *args

This is a parameter in the SimulateTasks() class that lets you put in custom test-cases. Here is an example of how its used:

Note: The first 2 values aren't tasks, just there so *args gets properly evaluated.

lb.SimulateTasks(15, 20, 50, 20, 30)

In this example there are 3 custom tasks. The first one takes 50%, the next takes 20%, and the last takes the final 30%. If these values are greater than the total, then an error will be raised.

lb.SimulateTasks(15, 20, 50, 50, 10)
Value Error: Your custom tasks exceded the total (150 > 100)

If these values are less than, it will prompt a warning for 2 seconds, and then contiue the program as normal.

Warning: Your custom tasks did not reach the total (50 < 100)
The Program will continue but there may be errors.

1.9 Known Issues

Note: This bug log only contains bugs going back to version 1.1.6

Version Bug ID Description Status Fix Date
1.2.0 003 pastBar sometimes has random prints. Not Fixed
1.2.7 004 PiP not finding package, has bad files. Fixed
1.2.2 004 SimulateTasks() runs when using import. Fixed 12/02/20
1.1.8 002 pastBar would freeze program Fixed 12/02/20
1.1.6 001 time_ param in progress() method froze program if over 100 Fixed 12/01/20

1.10 Future Updates

Note: These release dates aren't offical and are only estimations

| Version | Planned Changes | |-|-|:-:| | 1.5.0 | More features including multi-bar version, and different types of progress indicators | | 1.4.0 | Compatibility with non-terminal formats | | 1.3.0 | Ability to change bar format, pre-sets, and more than 1 example class |


1.11 Version Log

1.11.1 Modern Versions

Version New Changes Release Date
1.3.0 Final version of progressCircle() method 12/03/20
1.2.9 SimulateTasks() would run when initilizing Bar() 12/03/20
1.2.8 Bug fixes 12/03/20
1.2.7 Replaced start() method with progressCircle() to allow for more customization, start() method is now like the end() method for the beginning; Also added more title customization including placement 12/03/20
1.2.6 Added email and website to pypi page 12/03/20
1.2.5 Setup tokens so updates are easier and more frequent 12/02/20
1.2.4 Tweaks to documentation for more clarity 12/02/20
1.2.3 Converted module to offical PyPi / PiP package 12/02/20
1.2.2 Minor tweaks to eta calculation, fixed documentation mistakes 12/02/20
1.2.1 Added Quick Start Guide to documentation, revised doc-strings in consloadingbar.py 12/02/20
1.2.0 Changed all param names to be more clear, and removed some useless ones. Overall easier to use. 12/02/20
1.1.9 Added colors to end() method, and pastBar. Added color param to Bar() class so the user has the ability to toggle color mode. 12/02/20
1.1.8 SimulateTasks() has an *args param to accept custom pre-set tasks. Updated all doc-strings and added technical comments. 12/01/20
1.1.7 SimulateTasks() no longer has nested functions, and doesn't have its own redundent start() method. Also added title param to all methods so printing the title is built in. 12/01/20
1.1.6 Created Bug Log 12/01/20
1.1.5 Created Version Log 12/01/20
1.1.4 Bug fixes 12/01/20
1.1.3 Released Documentation 1.0 11/30/20
1.1.2 Bug fixes 11/30/20
1.1.1 Bug fixes 11/30/20
1.1.0 Added SimulateTasks() class to main module 11/29/20
1.0.2 Bug fixes 11/29/20
1.0.1 Converted SimulateTasks() to class form 11/28/20
1.0.0 Inital Release 11/27/20

1.11.2 Early Stage Versions

Stage Version ID New Changes Release Date
beta 3.0 Threading with eta estimation 11/27/20
beta 2.0 Tasks visual and ability to detect them 11/26/20
beta 1.3 Various big fixes 11/26/20
beta 1.2 Loading bar now has eta display 11/26/20
beta 1.1 Loading bar with percent of completion 11/25/20
beta 1.0 Dynamic loading bar 11/25/20
alpha 1.2 Eta calculator 11/25/20
alpha 1.1 Class form 11/25/20
alpha 1.0 First version, only progress method as single function 11/24/20

Documentation Version 2.6 - Module Version 1.3.0 - PyPi Release 6 - GitHub Release - 0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ConsLoadingBar-1.3.0.tar.gz (18.3 kB view hashes)

Uploaded Source

Built Distribution

ConsLoadingBar-1.3.0-py3-none-any.whl (8.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page