Skip to content
This repository was archived by the owner on Sep 16, 2025. It is now read-only.

Commit b605e53

Browse files
committed
quera progress bar
0 parents  commit b605e53

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
**/__pycache__/

__init__.py

Whitespace-only changes.

pyproject.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[tool.poetry]
2+
name = "qprogress"
3+
version = "1.0.0"
4+
description = "Quera Progress Bar - A decoupled progress bar to show the progress of your loops!"
5+
authors = ["Mohammad Jafari <m.jafari9877@gmail.com>"]
6+
7+
[tool.poetry.dependencies]
8+
python = "^3.8"
9+
10+
[tool.poetry.dev-dependencies]
11+
12+
[build-system]
13+
requires = ["poetry-core>=1.0.0"]
14+
build-backend = "poetry.core.masonry.api"

qprogress/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .progress_bar import ProgressBar

qprogress/formatters.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
def default_format_func(current_index: int, total_count: int) -> None:
2+
percent = (current_index / total_count) * 100
3+
fill_count = int(percent / 2)
4+
print(f"\rProcessing [{'=' * fill_count}{' ' * (50 - fill_count)}] {percent:.1f}%", end="")

qprogress/progress_bar.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from typing import Callable, Any, Tuple
2+
3+
from .formatters import default_format_func
4+
5+
6+
class ProgressBar:
7+
def __init__(self, iterable: Tuple[Any], format_func: Callable[[int, int], None] = default_format_func):
8+
if not isinstance(iterable, tuple):
9+
iterable = tuple(iterable)
10+
self.length = len(iterable)
11+
self.index = 0
12+
self.iterable = iterable
13+
self.format_func = format_func
14+
15+
def __iter__(self):
16+
return self
17+
18+
def __next__(self):
19+
try:
20+
next_item = self.iterable[self.index]
21+
except IndexError:
22+
raise StopIteration
23+
self.index += 1
24+
self.format_func(self.index, self.length)
25+
return next_item

0 commit comments

Comments
 (0)