From f8831d0a4121fafbf65dd6736d8bb2a02ff4806d Mon Sep 17 00:00:00 2001 From: Stephen L Date: Mon, 17 Oct 2016 03:02:44 +0200 Subject: [PATCH 1/3] Add ncols to specify tqdm_notebook bar width Signed-off-by: Stephen L. --- tqdm/_tqdm_notebook.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tqdm/_tqdm_notebook.py b/tqdm/_tqdm_notebook.py index 5189d8c3..606ea9af 100644 --- a/tqdm/_tqdm_notebook.py +++ b/tqdm/_tqdm_notebook.py @@ -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 From 47df7d6d1b511985d3cea008116519360f3cf03e Mon Sep 17 00:00:00 2001 From: Guangshuo CHEN Date: Wed, 11 Apr 2018 17:04:33 +0200 Subject: [PATCH 2/3] closes #292 --- tqdm/_tqdm_notebook.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tqdm/_tqdm_notebook.py b/tqdm/_tqdm_notebook.py index 606ea9af..89915be4 100644 --- a/tqdm/_tqdm_notebook.py +++ b/tqdm/_tqdm_notebook.py @@ -104,17 +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! + # Prepare layout + if ncols is not None: # if ncols is None, use default style of ipywidgets + # ncols could be 100, "100px", "100%" + ncols = str(ncols) # ipywidgets only accepts string, + if ncols[-1].isnumeric(): + # if last value is digit, assume the value is digit + ncols += 'px' + pbar.layout.flex = '2' + container.layout.width = ncols + container.layout.display = 'inline-flex' + container.layout.flex_flow = 'row wrap' display(container) def print_status(s='', close=False, bar_style=None, desc=None): @@ -185,8 +185,8 @@ class tqdm_notebook(tqdm): # self.sp('', close=True) # Get bar width - ncols = kwargs.get('ncols', None) - if ncols is None or self.dynamic_ncols: + self.ncols = kwargs.get('ncols', None) + if self.dynamic_ncols: self.ncols = '100%' # Replace with IPython progress bar display (with correct total) From 34457bd2b0c5980e8b2eca475dbdbbf0a7e1b8b8 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sun, 15 Apr 2018 02:08:47 +0100 Subject: [PATCH 3/3] tidy,flake8 --- tqdm/_tqdm_notebook.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tqdm/_tqdm_notebook.py b/tqdm/_tqdm_notebook.py index 89915be4..f57395e8 100644 --- a/tqdm/_tqdm_notebook.py +++ b/tqdm/_tqdm_notebook.py @@ -105,9 +105,9 @@ class tqdm_notebook(tqdm): # Only way to place text to the right of the bar is to use a container container = HBox(children=[pbar, ptext]) # Prepare layout - if ncols is not None: # if ncols is None, use default style of ipywidgets + if ncols is not None: # use default style of ipywidgets # ncols could be 100, "100px", "100%" - ncols = str(ncols) # ipywidgets only accepts string, + ncols = str(ncols) # ipywidgets only accepts string if ncols[-1].isnumeric(): # if last value is digit, assume the value is digit ncols += 'px' @@ -185,12 +185,11 @@ class tqdm_notebook(tqdm): # self.sp('', close=True) # Get bar width - self.ncols = kwargs.get('ncols', None) - if self.dynamic_ncols: - self.ncols = '100%' + self.ncols = '100%' if self.dynamic_ncols else kwargs.get("ncols", None) # Replace with IPython progress bar display (with correct total) - self.sp = self.status_printer(self.fp, self.total, self.desc, self.ncols) + 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 @@ -203,7 +202,7 @@ class tqdm_notebook(tqdm): # return super(tqdm...) will not catch exception yield obj # NB: except ... [ as ...] breaks IPython async KeyboardInterrupt - except: + except: # NOQA self.sp(bar_style='danger') raise