Skip to content

Commit

Permalink
fix ASCII notebook export
Browse files Browse the repository at this point in the history
- fixes #1098, fixes #1035, fixes #937
  • Loading branch information
casperdcl committed Dec 20, 2020
1 parent 468bf27 commit a6542b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -3,7 +3,7 @@ universal = 1

[flake8]
ignore = W503,W504,E722
max_line_length = 80
max_line_length = 88
exclude = .asv,.eggs,.tox,.ipynb_checkpoints,build,dist,.git,__pycache__

[tool:pytest]
Expand Down
19 changes: 16 additions & 3 deletions tqdm/notebook.py
Expand Up @@ -57,6 +57,7 @@
except ImportError:
IPY = 0
IProgress = None
HBox = object

try:
from IPython.display import display # , clear_output
Expand All @@ -74,6 +75,18 @@
__all__ = ['tqdm_notebook', 'tnrange', 'tqdm', 'trange']


class TqdmHBox(HBox):
def __repr__(self):
if not hasattr(self, "pbar"):
return super(TqdmHBox, self).__repr__()
return self.pbar.format_meter(**dict(
self.pbar.format_dict,
bar_format=(
self.pbar.format_dict['bar_format'] or "{l_bar}{bar}{r_bar}"
).replace("<bar/>", "{bar}"),
ascii=True))


class tqdm_notebook(std_tqdm):
"""
Experimental IPython/Jupyter Notebook widget using tqdm!
Expand Down Expand Up @@ -110,7 +123,7 @@ def status_printer(_, total=None, desc=None, ncols=None):
rtext = HTML()
if desc:
ltext.value = desc
container = HBox(children=[ltext, pbar, rtext])
container = TqdmHBox(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 @@ -228,8 +241,8 @@ def __init__(self, *args, **kwargs):
# Replace with IPython progress bar display (with correct total)
unit_scale = 1 if self.unit_scale is True else self.unit_scale or 1
total = self.total * unit_scale if self.total else self.total
self.container = self.status_printer(
self.fp, total, self.desc, self.ncols)
self.container = self.status_printer(self.fp, total, self.desc, self.ncols)
self.container.pbar = self
if display_here:
display(self.container)
self.sp = self.display
Expand Down

0 comments on commit a6542b5

Please sign in to comment.