mirror of https://github.com/tqdm/tqdm.git
Add ncols to specify tqdm_notebook bar width
Signed-off-by: Stephen L. <lrq3000@gmail.com>
This commit is contained in:
parent
6dad2e8901
commit
f8831d0a41
|
@ -80,7 +80,7 @@ class tqdm_notebook(tqdm):
|
|||
"""
|
||||
|
||||
@staticmethod
|
||||
def status_printer(_, total=None, desc=None):
|
||||
def status_printer(_, total=None, desc=None, ncols=None):
|
||||
"""
|
||||
Manage the printing of an IPython/Jupyter Notebook progress bar widget.
|
||||
"""
|
||||
|
@ -104,6 +104,17 @@ class tqdm_notebook(tqdm):
|
|||
ptext = HTML()
|
||||
# Only way to place text to the right of the bar is to use a container
|
||||
container = HBox(children=[pbar, ptext])
|
||||
# Prepare layout (if available in ipywidgets version)
|
||||
#try: # commented until it works, ease debugging
|
||||
if not ncols:
|
||||
ncols = '100%'
|
||||
pbar.layout.width = ncols
|
||||
container.layout.width = ncols
|
||||
container.layout.display = 'inline-flex'
|
||||
container.layout.flex_flow = 'row wrap'
|
||||
#except Exception:
|
||||
#pass
|
||||
# Display!
|
||||
display(container)
|
||||
|
||||
def print_status(s='', close=False, bar_style=None, desc=None):
|
||||
|
@ -172,8 +183,14 @@ class tqdm_notebook(tqdm):
|
|||
# Delete first pbar generated from super() (wrong total and text)
|
||||
# DEPRECATED by using gui=True
|
||||
# self.sp('', close=True)
|
||||
|
||||
# Get bar width
|
||||
ncols = kwargs.get('ncols', None)
|
||||
if ncols is None or self.dynamic_ncols:
|
||||
self.ncols = '100%'
|
||||
|
||||
# Replace with IPython progress bar display (with correct total)
|
||||
self.sp = self.status_printer(self.fp, self.total, self.desc)
|
||||
self.sp = self.status_printer(self.fp, self.total, self.desc, self.ncols)
|
||||
self.desc = None # trick to place description before the bar
|
||||
|
||||
# Print initial bar state
|
||||
|
|
Loading…
Reference in New Issue