Skip to content

Commit

Permalink
Merge branch 'release/3.55.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Oct 15, 2021
2 parents 308096a + e5d37e3 commit 005d8a1
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ of widgets:
- `FormatCustomText <http://progressbar-2.readthedocs.io/en/latest/_modules/progressbar/widgets.html#FormatCustomText>`_
- `FormatLabel <http://progressbar-2.readthedocs.io/en/latest/_modules/progressbar/widgets.html#FormatLabel>`_
- `FormatLabelBar <http://progressbar-2.readthedocs.io/en/latest/_modules/progressbar/widgets.html#FormatLabel>`_
- `GranularBar <http://progressbar-2.readthedocs.io/en/latest/_modules/progressbar/widgets.html#GranularBar>`_
- `Percentage <http://progressbar-2.readthedocs.io/en/latest/_modules/progressbar/widgets.html#Percentage>`_
- `PercentageLabelBar <http://progressbar-2.readthedocs.io/en/latest/_modules/progressbar/widgets.html#PercentageLabelBar>`_
- `ReverseBar <http://progressbar-2.readthedocs.io/en/latest/_modules/progressbar/widgets.html#ReverseBar>`_
Expand Down
14 changes: 14 additions & 0 deletions examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ def multi_progress_bar_example(left=True):
time.sleep(0.02)


@example
def granular_progress_example():
widgets = [
progressbar.GranularBar(markers=" ▏▎▍▌▋▊▉█", left='', right='|'),
progressbar.GranularBar(markers=" ▁▂▃▄▅▆▇█", left='', right='|'),
progressbar.GranularBar(markers=" ▖▌▛█", left='', right='|'),
progressbar.GranularBar(markers=" ░▒▓█", left='', right='|'),
progressbar.GranularBar(markers=" ⡀⡄⡆⡇⣇⣧⣷⣿", left='', right='|'),
progressbar.GranularBar(markers=" .oO", left='', right=''),
]
for i in progressbar.progressbar(range(100), widgets=widgets):
time.sleep(0.03)


@example
def percentage_label_bar_example():
widgets = [progressbar.PercentageLabelBar()]
Expand Down
2 changes: 1 addition & 1 deletion progressbar/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
long running operations.
'''.strip().split())
__email__ = 'wolph@wol.ph'
__version__ = '3.54.0'
__version__ = '3.55.0'
__license__ = 'BSD'
__copyright__ = 'Copyright 2015 Rick van Hattem (Wolph)'
__url__ = 'https://github.com/WoLpH/python-progressbar'
2 changes: 2 additions & 0 deletions progressbar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
VariableMixin,
MultiRangeBar,
MultiProgressBar,
GranularBar,
FormatLabelBar,
PercentageLabelBar,
Variable,
Expand Down Expand Up @@ -74,6 +75,7 @@
'VariableMixin',
'MultiRangeBar',
'MultiProgressBar',
'GranularBar',
'FormatLabelBar',
'PercentageLabelBar',
'Variable',
Expand Down
2 changes: 1 addition & 1 deletion progressbar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def __init__(self, target, capturing=False, listeners=set()):
self.listeners = listeners
self.needs_clear = False

def isatty(self):
def isatty(self): # pragma: no cover
return self.target.isatty()

def write(self, value):
Expand Down
69 changes: 69 additions & 0 deletions progressbar/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,75 @@ def get_values(self, progress, data):
return ranges


class GranularMarkers:
smooth = ' ▏▎▍▌▋▊▉█'
bar = ' ▁▂▃▄▅▆▇█'
snake = ' ▖▌▛█'
fade_in = ' ░▒▓█'
dots = ' ⡀⡄⡆⡇⣇⣧⣷⣿'
growing_circles = ' .oO'


class GranularBar(AutoWidthWidgetBase):
'''A progressbar that can display progress at a sub-character granularity
by using multiple marker characters.
Examples of markers:
- Smooth: ` ▏▎▍▌▋▊▉█` (default)
- Bar: ` ▁▂▃▄▅▆▇█`
- Snake: ` ▖▌▛█`
- Fade in: ` ░▒▓█`
- Dots: ` ⡀⡄⡆⡇⣇⣧⣷⣿`
- Growing circles: ` .oO`
The markers can be accessed through GranularMarkers. GranularMarkers.dots
for example
'''

def __init__(self, markers=GranularMarkers.smooth, left='|', right='|',
**kwargs):
'''Creates a customizable progress bar.
markers - string of characters to use as granular progress markers. The
first character should represent 0% and the last 100%.
Ex: ` .oO`.
left - string or callable object to use as a left border
right - string or callable object to use as a right border
'''
self.markers = markers
self.left = string_or_lambda(left)
self.right = string_or_lambda(right)

AutoWidthWidgetBase.__init__(self, **kwargs)

def __call__(self, progress, data, width):
left = converters.to_unicode(self.left(progress, data, width))
right = converters.to_unicode(self.right(progress, data, width))
width -= progress.custom_len(left) + progress.custom_len(right)

if progress.max_value is not base.UnknownLength \
and progress.max_value > 0:
percent = progress.value / progress.max_value
else:
percent = 0

num_chars = percent * width

marker = self.markers[-1] * int(num_chars)

marker_idx = int((num_chars % 1) * (len(self.markers) - 1))
if marker_idx:
marker += self.markers[marker_idx]

marker = converters.to_unicode(marker)

# Make sure we ignore invisible characters when filling
width += len(marker) - progress.custom_len(marker)
marker = marker.ljust(width, self.markers[0])

return left + marker + right


class FormatLabelBar(FormatLabel, Bar):
'''A bar which has a formatted label in the center.'''
def __init__(self, format, **kwargs):
Expand Down
20 changes: 20 additions & 0 deletions tests/test_monitor_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,26 @@ def test_percentage_label_bar(testdir):
]


def test_granular_bar(testdir):
result = testdir.runpython(testdir.makepyfile(_create_script(
widgets='[progressbar.GranularBar(markers=" .oO")]',
line_breaks=False,
items=list(range(5)),
)))
pprint.pprint(result.stderr.lines, width=70)
assert result.stderr.lines == [
u'',
u'| |',
u'|OOOOOOOOOOO. |',
u'|OOOOOOOOOOOOOOOOOOOOOOO |',
u'|OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOo |',
u'|OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO. |',
u'|OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO|',
u'',
u'|OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO|'
]


def test_colors(testdir):
kwargs = dict(
items=range(1),
Expand Down

0 comments on commit 005d8a1

Please sign in to comment.