Skip to content

Commit

Permalink
notebook: total=None display improvements
Browse files Browse the repository at this point in the history
- fixes #1015
- also fix potential `kwarg` override issue
  • Loading branch information
casperdcl committed Aug 2, 2020
1 parent 543053d commit e602bb5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tqdm/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def status_printer(_, total=None, desc=None, ncols=None):
pbar = IProgress(min=0, max=1)
pbar.value = 1
pbar.bar_style = 'info'
if ncols is None:
pbar.layout.width = "20px"

if desc:
pbar.description = desc
Expand All @@ -129,6 +131,13 @@ def status_printer(_, total=None, desc=None, ncols=None):

return container

@staticmethod
def format_meter(n, total, *args, **kwargs):
if total and 'bar_format' not in kwargs:
kwargs = kwargs.copy()
kwargs['bar_format'] = "{l_bar}<bar/>{r_bar}"
return std_tqdm.format_meter(n, total, *args, **kwargs)

def display(self, msg=None, pos=None,
# additional signals
close=False, bar_style=None):
Expand Down Expand Up @@ -182,15 +191,17 @@ def display(self, msg=None, pos=None,
self.container.visible = False

def __init__(self, *args, **kwargs):
kwargs = kwargs.copy()
# Setup default output
file_kwarg = kwargs.get('file', sys.stderr)
if file_kwarg is sys.stderr or file_kwarg is None:
kwargs['file'] = sys.stdout # avoid the red block in IPython

# Initialize parent class + avoid printing by using gui=True
kwargs['gui'] = True
kwargs.setdefault('bar_format', '{l_bar}{bar}{r_bar}')
kwargs['bar_format'] = kwargs['bar_format'].replace('{bar}', '<bar/>')
if 'bar_format' in kwargs:
kwargs['bar_format'] = kwargs['bar_format'].replace(
'{bar}', '<bar/>')
# convert disable = None to False
kwargs['disable'] = bool(kwargs.get('disable', False))
super(tqdm_notebook, self).__init__(*args, **kwargs)
Expand Down

0 comments on commit e602bb5

Please sign in to comment.