Skip to main content

Easy to make progress bars

Project description

1 ConsLoadingBar Documentation

Creator: FlameChain

Github Link: flamechain/Modules/ PyPi Link: project/ConsLoadingBar

Version: 1.2.2

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.


1.3 Installation

Install via pip using this command:

pip install consloadingbar

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

  1. Download the file here here.
  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

To use the start method, you can read more about it here, or on the second documentation here. If you want a brief summary keep reading.

To use this, call it and then cancel it after a given time. Import concurrent.futures and put it on another thread. Then stop it on the main thread. If these seems complicated its suggested you read more about this method using the links above.

import consloadingbar, time, concurrent.futures

lb = consloadingbar.Bar(title='')

stop_threads = False
with concurrent.futures.ThreadPoolExecutor() as executor:
    future2 = executor.submit(lb.start, lambda: stop_threads)

    time.sleep(2)

    stop_threads = True

This waits 2 seconds and then stops the method.

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()

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
estimatedTotalTime Used with the SimulateTasks() class, and changes overall delay on the visual. Not exact, only average. Based on seconds. float 10
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 estimatedTotalTime

This is not the eta that shows up on the bar during runtime, but rather an estimated time it will take to complete the bar. Only valid if its for demo purposes and no tasks running.

Rather for future there might be a eta param to toggle the eta status next to the bar. Here is 2 examples of the bar, using the same code:

|                    |   0%  [eta=00:00.00]
|████████████████████| 100%

In the top example the tasks haven't started so an eta can't be calculated. In the bottom example its complete, so the eta box doesn't show up on the screen.

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 progress()

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.progress(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.progress(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.progress(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 not used often, because most people would rather not have a flashy intro, or it doesn't fit there requirments.

Loading Tasks /

It simple runs a spinning bar until stopped. You can stop this method by triggering the stop parameter, which stops itself.

import consloadingbar, time, concurrent.futures

lb = consloadingbar.Bar()

stop_threads = False
with concurrent.futures.ThreadPoolExecutor() as executor:
    future2 = executor.submit(lb.start, lambda: stop_threads)

    time.sleep(1)

    stop_threads = True

This example uses the concurrent module to thread this task, so the thread can be manipulated while running. When run this program will run the 'loading tasks' prompt for 1 second, then the program will stop. This print() statement uses '\r' or 'replace' so you can take advantage by completely clearing it from the screen after finished.

1.6.3 end()

This is used much more often. 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.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
total .Where you put the total percent or other unit that the loading bar reaches at the end. True 100
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.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 Big Updates

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

Version Planned Changes Release Date
1.5.0 More features including multi-bar version, and different types of progress indicators. 01/10/21
1.4.0 Compatibility with non-terminal formats. 12/20/20
1.3.0 Ability to change bar format, pre-sets, and more than 1 example class. 12/10/20

1.11 Version Log

1.11.1 Modern Versions

Version New Changes Release Date
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 Added bug log and fixed bugs 12/01/20
1.1.5 Bug fixes, added version log 12/01/20
1.1.4 Bug fixes 12/01/20
1.1.3 Bug fixes, added documentation 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.2.2 - Release 8

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.2.3.tar.gz (21.3 kB view hashes)

Uploaded Source

Built Distribution

ConsLoadingBar-1.2.3-py3-none-any.whl (8.4 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