项目作者: theeko74

项目描述 :
A loading bar for a terminal window
高级语言: Python
项目地址: git://github.com/theeko74/loadingbar.git
创建时间: 2018-02-19T16:42:05Z
项目社区:https://github.com/theeko74/loadingbar

开源协议:MIT License

下载


Python Loading Bar

Travis Test

Python module to display a nice loading bar in a terminal window.

Install

Go to the module directory and run:

  1. $ pip install setup.py

Or:

  1. $ python3 setup.py install

Getting Started

There are 3 different loading bar:

  1. Standard loading bar
  2. Loading bar with size loaded, speed and remaining time
  3. Loading bar with infos above plus a custom message (usefull to display a verbose loading bar)

Option 1

Standard loading bar without any other infos.

Loading bar option 1

  1. import loading
  2. total_file_size = 1000
  3. # Create a loading bar object with total_file_size in bytes
  4. lb = loadingbar.LoadingBar(total_file_size)
  5. # For every piece of file
  6. for chunk in file:
  7. # Update the loading bar with the len of new data
  8. lg.update(len(chunk))
  9. # When finished, display a 100% loading bar
  10. lg.done()

Option 2

Standard loading bar with infos such as size downloaded, speed, eta.

Loading bar option 2

  1. import loading
  2. total_file_size = 1000
  3. lb = loadingbar.InfoLoadingBar(total_file_size)
  4. # Run as above

Option 3

This special InternetLoadingBar smooth the speed calculation by taking the overall average time rather than a instant speed.

  1. import loading
  2. total_file_size = 1000
  3. lb = loadingbar.InternetLoadingBar(total_file_size)
  4. # Run as above

Option 4

Loading bar that displays a message, like for example the filename that it is downloaded. Two options:

  • loadingbar.MessageLoadingBar
  • loadingbar.VerboseLoadingBar

Loading bar option 3

  1. import loading
  2. total_file_size = 1000
  3. lb = loadingbar.VerboseLoadingBar(total_file_size)
  4. # For every piece of file
  5. for chunk in file:
  6. # Update the loading bar with the len of new data
  7. lg.update(len(chunk), "Message to be displayed, such as filename, etc.")
  8. # When finished, display a 100% loading bar
  9. lg.done()

Option 5

Add a percentage after the loading bar.

  • loadingbar.PercentageLoadingBar(tot_size)
    Loading bar option 5-1

  • loadingbar.PercentageInfoLoadingBar(tot_size)
    Loading bar option 5-2

Option 6

Add a percentage after the loading bar.

  • loadingbar.PercentageBeforeLoadingBar(tot_size)
    Loading bar option 6-0

  • loadingbar.PercentageBeforeLoadingBarAndInfo(tot_size)
    Loading bar option 6-1

Customization

If a new and custom loading bar is needed, you can implement a new one by inheriting from the LoadingBar class or the abstract class ILoadingBar.
See loading > loading_bar.py for examples.

License

MIT license.
Feel free to use, share, or improve it.