-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress.py
More file actions
64 lines (47 loc) · 1.48 KB
/
Copy pathprogress.py
File metadata and controls
64 lines (47 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
====================================================
Universal File Converter
Progress Tracking Module
====================================================
"""
from __future__ import annotations
from dataclasses import dataclass
@dataclass
class ProgressStatus:
"""
Represents the current progress of an operation.
"""
current: int = 0
total: int = 0
message: str = "Ready"
@property
def percentage(self) -> int:
"""
Return progress percentage (0–100).
"""
if self.total == 0:
return 0
return int((self.current / self.total) * 100)
class ProgressTracker:
"""
Generic progress tracker.
"""
def __init__(self) -> None:
self.status = ProgressStatus()
def start(self, total: int, message: str = "Starting...") -> None:
self.status.total = total
self.status.current = 0
self.status.message = message
def update(self, step: int = 1, message: str | None = None) -> None:
self.status.current += step
if self.status.current > self.status.total:
self.status.current = self.status.total
if message:
self.status.message = message
def finish(self, message: str = "Completed") -> None:
self.status.current = self.status.total
self.status.message = message
def reset(self) -> None:
self.status = ProgressStatus()
def get_status(self) -> ProgressStatus:
return self.status