Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notebook: fix description width for unknown total #1032

Merged
merged 1 commit into from
Sep 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 11 additions & 14 deletions tqdm/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,11 @@ def status_printer(_, total=None, desc=None, ncols=None):
if ncols is None:
pbar.layout.width = "20px"

ltext = HTML()
rtext = HTML()
if desc:
pbar.description = desc
if IPYW >= 7:
pbar.style.description_width = 'initial'
# Prepare status text
ptext = HTML()
# Only way to place text to the right of the bar is to use a container
container = HBox(children=[pbar, ptext])
ltext.value = desc
container = HBox(children=[ltext, pbar, rtext])
# Prepare layout
if ncols is not None: # use default style of ipywidgets
# ncols could be 100, "100px", "100%"
Expand Down Expand Up @@ -151,7 +148,7 @@ def display(self, msg=None, pos=None,
if not msg and not close:
msg = self.__repr__()

pbar, ptext = self.container.children
ltext, pbar, rtext = self.container.children
pbar.value = self.n

if msg:
Expand All @@ -168,13 +165,10 @@ def display(self, msg=None, pos=None,
right = right[1:]

# Update description
pbar.description = left
if IPYW >= 7:
pbar.style.description_width = 'initial'

ltext.value = left
# never clear the bar (signal: msg='')
if right:
ptext.value = right
rtext.value = right

# Change bar style
if bar_style:
Expand Down Expand Up @@ -273,9 +267,12 @@ def reset(self, total=None):
----------
total : int or float, optional. Total to use for the new bar.
"""
_, pbar, _ = self.container.children
pbar.bar_style = ''
if total is not None:
pbar, _ = self.container.children
pbar.max = total
if not self.total and self.ncols is None: # no longer unknown total
pbar.layout.width = None # reset width
return super(tqdm_notebook, self).reset(total=total)


Expand Down