Skip to content

Commit

Permalink
fix notebook gui-mode extra spaces
Browse files Browse the repository at this point in the history
- fixes and/or related to #433, #479, #550, #935
  • Loading branch information
casperdcl committed Dec 20, 2020
1 parent 2c3c3a6 commit 2f56a1f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions tqdm/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, *args, **kwargs):
import matplotlib as mpl
import matplotlib.pyplot as plt
from collections import deque
kwargs = kwargs.copy()
kwargs['gui'] = True

super(tqdm_gui, self).__init__(*args, **kwargs)
Expand Down
14 changes: 7 additions & 7 deletions tqdm/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def __init__(self, *args, **kwargs):
display_here = kwargs.pop('display', True)
super(tqdm_notebook, self).__init__(*args, **kwargs)
if self.disable or not kwargs['gui']:
self.sp = lambda *_, **__: None
self.disp = lambda *_, **__: None
return

# Get bar width
Expand All @@ -248,7 +248,7 @@ def __init__(self, *args, **kwargs):
self.container.pbar = self
if display_here:
display(self.container)
self.sp = self.display
self.disp = self.display
self.colour = colour

# Print initial bar state
Expand All @@ -262,7 +262,7 @@ def __iter__(self, *args, **kwargs):
yield obj
# NB: except ... [ as ...] breaks IPython async KeyboardInterrupt
except: # NOQA
self.sp(bar_style='danger')
self.disp(bar_style='danger')
raise
# NB: don't `finally: close()`
# since this could be a shared bar which the user will `reset()`
Expand All @@ -274,7 +274,7 @@ def update(self, *args, **kwargs):
except: # NOQA
# cannot catch KeyboardInterrupt when using manual tqdm
# as the interrupt will most likely happen on another statement
self.sp(bar_style='danger')
self.disp(bar_style='danger')
raise
# NB: don't `finally: close()`
# since this could be a shared bar which the user will `reset()`
Expand All @@ -284,12 +284,12 @@ def close(self, *args, **kwargs):
# Try to detect if there was an error or KeyboardInterrupt
# in manual mode: if n < total, things probably got wrong
if self.total and self.n < self.total:
self.sp(bar_style='danger')
self.disp(bar_style='danger')
else:
if self.leave:
self.sp(bar_style='success')
self.disp(bar_style='success')
else:
self.sp(close=True)
self.disp(close=True)

def moveto(self, *_, **__):
# void -> avoid extraneous `\n` in IPython output cell
Expand Down
4 changes: 2 additions & 2 deletions tqdm/std.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ def __iter__(self):
avg_time = self.avg_time
time = self._time

if not hasattr(self, 'sp'):
if getattr(self, 'sp', None) is None:
raise TqdmDeprecationWarning(
"Please use `tqdm.gui.tqdm(...)` instead of"
" `tqdm(..., gui=True)`\n",
Expand Down Expand Up @@ -1301,7 +1301,7 @@ def close(self):
self._decr_instances(self)

# GUI mode
if not hasattr(self, "sp"):
if getattr(self, 'sp', None) is None:
return

# annoyingly, _supports_unicode isn't good enough
Expand Down

0 comments on commit 2f56a1f

Please sign in to comment.