|
27 | 27 | logger = logging.getLogger(__name__) |
28 | 28 |
|
29 | 29 |
|
| 30 | +T = types.TypeVar('T') |
| 31 | + |
| 32 | + |
30 | 33 | class ProgressBarMixinBase(object): |
31 | 34 |
|
32 | 35 | def __init__(self, **kwargs): |
@@ -265,16 +268,21 @@ class ProgressBar(StdRedirectMixin, ResizableMixin, ProgressBarBase): |
265 | 268 | the current progress bar. As a result, you have access to the |
266 | 269 | ProgressBar's methods and attributes. Although there is nothing preventing |
267 | 270 | you from changing the ProgressBar you should treat it as read only. |
268 | | -
|
269 | | - Useful methods and attributes include (Public API): |
270 | | - - value: current progress (min_value <= value <= max_value) |
271 | | - - max_value: maximum (and final) value |
272 | | - - end_time: not None if the bar has finished (reached 100%) |
273 | | - - start_time: the time when start() method of ProgressBar was called |
274 | | - - seconds_elapsed: seconds elapsed since start_time and last call to |
275 | | - update |
276 | 271 | ''' |
277 | 272 |
|
| 273 | + #: Current progress (min_value <= value <= max_value) |
| 274 | + value: T |
| 275 | + #: Maximum (and final) value. Beyond this value an error will be raised |
| 276 | + #: unless the `max_error` parameter is `False`. |
| 277 | + max_value: T |
| 278 | + #: The time the progressbar reached `max_value` or when `finish()` was |
| 279 | + #: called. |
| 280 | + end_time: datetime |
| 281 | + #: The time `start()` was called or iteration started. |
| 282 | + start_time: datetime |
| 283 | + #: Seconds between `start_time` and last call to `update()` |
| 284 | + seconds_elapsed: float |
| 285 | + |
278 | 286 | _DEFAULT_MAXVAL = base.UnknownLength |
279 | 287 | # update every 50 milliseconds (up to a 20 times per second) |
280 | 288 | _MINIMUM_UPDATE_INTERVAL = 0.050 |
@@ -568,7 +576,10 @@ def __enter__(self): |
568 | 576 |
|
569 | 577 | def __iadd__(self, value): |
570 | 578 | 'Updates the ProgressBar by adding a new value.' |
571 | | - self.update(self.value + value) |
| 579 | + return self.increment(value) |
| 580 | + |
| 581 | + def increment(self, value=1, *args, **kwargs): |
| 582 | + self.update(self.value + value, *args, **kwargs) |
572 | 583 | return self |
573 | 584 |
|
574 | 585 | def _format_widgets(self): |
@@ -788,6 +799,16 @@ def finish(self, end='\n', dirty=False): |
788 | 799 | ResizableMixin.finish(self) |
789 | 800 | ProgressBarBase.finish(self) |
790 | 801 |
|
| 802 | + @property |
| 803 | + def currval(self): |
| 804 | + ''' |
| 805 | + Legacy method to make progressbar-2 compatible with the original |
| 806 | + progressbar package |
| 807 | + ''' |
| 808 | + warnings.warn('The usage of `currval` is deprecated, please use ' |
| 809 | + '`value` instead', DeprecationWarning) |
| 810 | + return self.value |
| 811 | + |
791 | 812 |
|
792 | 813 | class DataTransferBar(ProgressBar): |
793 | 814 | '''A progress bar with sensible defaults for downloads etc. |
|
0 commit comments