Skip to content

Commit

Permalink
documentation, tidy, and function reordering
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed May 13, 2019
1 parent c7015f4 commit 0e1961c
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 126 deletions.
64 changes: 34 additions & 30 deletions .readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -329,29 +329,19 @@ Returns
"""
def close(self):
"""
Cleanup and (if leave=False) close the progressbar.
"""
def unpause(self):
"""
Restart tqdm timer from last print time.
"""
"""Cleanup and (if leave=False) close the progressbar."""
def clear(self, nomove=False):
"""
Clear current bar display
"""
"""Clear current bar display."""
def refresh(self):
"""
Force refresh the display of this bar
"""
"""Force refresh the display of this bar."""
def write(cls, s, file=sys.stdout, end="\n"):
"""
Print a message via tqdm (without overlap with bars)
"""
def unpause(self):
"""Restart tqdm timer from last print time."""
def reset(self, total=None):
"""Resets a bar to n=0 for repeated use."""
def set_description(self, desc=None, refresh=True):
"""
Expand All @@ -375,31 +365,45 @@ Returns
Forces refresh [default: True].
"""
@classmethod
def write(cls, s, file=sys.stdout, end="\n"):
"""Print a message via tqdm (without overlap with bars)."""
@property
def format_dict(self):
"""Public API for read-only member access."""
def display(self, msg=None, pos=None):
"""
Use ``self.sp`` to display ``msg`` in the specified ``pos``.
Consider overloading this function when inheriting to use e.g.:
``self.some_frontend(**self.format_dict)`` instead of ``self.sp``.
Parameters
----------
msg : str, optional. What to display (default: ``repr(self)``).
pos : int, optional. Position to ``moveto``
(default: ``abs(self.pos)``).
"""
def trange(*args, **kwargs):
"""
A shortcut for tqdm(xrange(*args), **kwargs).
On Python3+ range is used instead of xrange.
"""
class tqdm_gui(tqdm):
"""
Experimental GUI version of tqdm!
"""
"""Experimental GUI version"""
def tgrange(*args, **kwargs):
"""
Experimental GUI version of trange!
"""
"""Experimental GUI version of trange"""
class tqdm_notebook(tqdm):
"""
Experimental IPython/Jupyter Notebook widget using tqdm!
"""
"""Experimental IPython/Jupyter Notebook widget"""
def tnrange(*args, **kwargs):
"""
Experimental IPython/Jupyter Notebook widget using tqdm!
"""
"""Experimental IPython/Jupyter Notebook widget version of trange"""
Examples and Advanced Usage
Expand Down
64 changes: 34 additions & 30 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -438,29 +438,19 @@ Returns
"""
def close(self):
"""
Cleanup and (if leave=False) close the progressbar.
"""
def unpause(self):
"""
Restart tqdm timer from last print time.
"""
"""Cleanup and (if leave=False) close the progressbar."""
def clear(self, nomove=False):
"""
Clear current bar display
"""
"""Clear current bar display."""
def refresh(self):
"""
Force refresh the display of this bar
"""
"""Force refresh the display of this bar."""
def write(cls, s, file=sys.stdout, end="\n"):
"""
Print a message via tqdm (without overlap with bars)
"""
def unpause(self):
"""Restart tqdm timer from last print time."""
def reset(self, total=None):
"""Resets a bar to n=0 for repeated use."""
def set_description(self, desc=None, refresh=True):
"""
Expand All @@ -484,31 +474,45 @@ Returns
Forces refresh [default: True].
"""
@classmethod
def write(cls, s, file=sys.stdout, end="\n"):
"""Print a message via tqdm (without overlap with bars)."""
@property
def format_dict(self):
"""Public API for read-only member access."""
def display(self, msg=None, pos=None):
"""
Use ``self.sp`` to display ``msg`` in the specified ``pos``.
Consider overloading this function when inheriting to use e.g.:
``self.some_frontend(**self.format_dict)`` instead of ``self.sp``.
Parameters
----------
msg : str, optional. What to display (default: ``repr(self)``).
pos : int, optional. Position to ``moveto``
(default: ``abs(self.pos)``).
"""
def trange(*args, **kwargs):
"""
A shortcut for tqdm(xrange(*args), **kwargs).
On Python3+ range is used instead of xrange.
"""
class tqdm_gui(tqdm):
"""
Experimental GUI version of tqdm!
"""
"""Experimental GUI version"""
def tgrange(*args, **kwargs):
"""
Experimental GUI version of trange!
"""
"""Experimental GUI version of trange"""
class tqdm_notebook(tqdm):
"""
Experimental IPython/Jupyter Notebook widget using tqdm!
"""
"""Experimental IPython/Jupyter Notebook widget"""
def tnrange(*args, **kwargs):
"""
Experimental IPython/Jupyter Notebook widget using tqdm!
"""
"""Experimental IPython/Jupyter Notebook widget version of trange"""
Examples and Advanced Usage
Expand Down
125 changes: 59 additions & 66 deletions tqdm/_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def __new__(cls, *args, **kwargs):

@classmethod
def _get_free_pos(cls, instance=None):
"""Skips specified instance"""
"""Skips specified instance."""
positions = set(abs(inst.pos) for inst in cls._instances
if inst is not instance and hasattr(inst, "pos"))
return min(set(range(len(positions) + 1)).difference(positions))
Expand Down Expand Up @@ -517,9 +517,7 @@ def _decr_instances(cls, instance):

@classmethod
def write(cls, s, file=None, end="\n", nolock=False):
"""
Print a message via tqdm (without overlap with bars)
"""
"""Print a message via tqdm (without overlap with bars)."""
fp = file if file is not None else sys.stdout
with cls.external_write_mode(file=file, nolock=nolock):
# Write the message
Expand Down Expand Up @@ -965,21 +963,6 @@ def __exit__(self, *exc):
def __del__(self):
self.close()

@property
def format_dict(self):
"""Public API for read-only member access"""
return dict(
n=self.n, total=self.total,
elapsed=self._time() - self.start_t
if hasattr(self, 'start_t') else 0,
ncols=self.dynamic_ncols(self.fp)
if self.dynamic_ncols else self.ncols,
prefix=self.desc, ascii=self.ascii, unit=self.unit,
unit_scale=self.unit_scale,
rate=1 / self.avg_time if self.avg_time else None,
bar_format=self.bar_format, postfix=self.postfix,
unit_divisor=self.unit_divisor)

def __repr__(self):
return self.format_meter(**self.format_dict)

Expand Down Expand Up @@ -1152,9 +1135,7 @@ def update(self, n=1):
self.last_print_t = cur_t

def close(self):
"""
Cleanup and (if leave=False) close the progressbar.
"""
"""Cleanup and (if leave=False) close the progressbar."""
if self.disable:
return

Expand Down Expand Up @@ -1195,14 +1176,45 @@ def fp_write(s):
if not pos:
fp_write('\r')

def clear(self, nolock=False):
"""Clear current bar display."""
if self.disable:
return

if not nolock:
self._lock.acquire()
self.moveto(abs(self.pos))
self.sp('')
self.fp.write('\r') # place cursor back at the beginning of line
self.moveto(-abs(self.pos))
if not nolock:
self._lock.release()

def refresh(self, nolock=False):
"""Force refresh the display of this bar."""
if self.disable:
return

if not nolock:
self._lock.acquire()
self.display()
if not nolock:
self._lock.release()

def unpause(self):
"""
Restart tqdm timer from last print time.
"""
"""Restart tqdm timer from last print time."""
cur_t = self._time()
self.start_t += cur_t - self.last_print_t
self.last_print_t = cur_t

def reset(self, total=None):
"""Resets a bar to n=0 for repeated use."""
self.last_print_n = self.n = 0
self.last_print_t = self.start_t = self._time()
if total is not None:
self.total = total
self.refresh()

def set_description(self, desc=None, refresh=True):
"""
Set/modify description of the progress bar.
Expand All @@ -1218,9 +1230,7 @@ def set_description(self, desc=None, refresh=True):
self.refresh()

def set_description_str(self, desc=None, refresh=True):
"""
Set/modify description without ': ' appended.
"""
"""Set/modify description without ': ' appended."""
self.desc = desc or ''
if refresh:
self.refresh()
Expand Down Expand Up @@ -1269,43 +1279,33 @@ def moveto(self, n):
self.fp.write(_unicode('\n' * n + _term_move_up() * -n))
self.fp.flush()

def clear(self, nolock=False):
"""
Clear current bar display
"""
if self.disable:
return

if not nolock:
self._lock.acquire()
self.moveto(abs(self.pos))
self.sp('')
self.fp.write('\r') # place cursor back at the beginning of line
self.moveto(-abs(self.pos))
if not nolock:
self._lock.release()

def refresh(self, nolock=False):
"""
Force refresh the display of this bar
"""
if self.disable:
return

if not nolock:
self._lock.acquire()
self.display()
if not nolock:
self._lock.release()
@property
def format_dict(self):
"""Public API for read-only member access."""
return dict(
n=self.n, total=self.total,
elapsed=self._time() - self.start_t
if hasattr(self, 'start_t') else 0,
ncols=self.dynamic_ncols(self.fp)
if self.dynamic_ncols else self.ncols,
prefix=self.desc, ascii=self.ascii, unit=self.unit,
unit_scale=self.unit_scale,
rate=1 / self.avg_time if self.avg_time else None,
bar_format=self.bar_format, postfix=self.postfix,
unit_divisor=self.unit_divisor)

def display(self, msg=None, pos=None):
"""
Use `self.sp` and to display `msg` in the specified `pos`.
Use `self.sp` to display `msg` in the specified `pos`.
Consider overloading this function when inheriting to use e.g.:
`self.some_frontend(**self.format_dict)` instead of `self.sp`.
Parameters
----------
msg : what to display (default: repr(self))
pos : position to display in. (default: abs(self.pos))
msg : str, optional. What to display (default: `repr(self)`).
pos : int, optional. Position to `moveto`
(default: `abs(self.pos)`).
"""
if pos is None:
pos = abs(self.pos)
Expand All @@ -1316,13 +1316,6 @@ def display(self, msg=None, pos=None):
if pos:
self.moveto(-pos)

def reset(self, total=None):
"""Resets a bar to n=0 for repeated use"""
self.last_print_n = self.n = 0
self.last_print_t = self.start_t = self._time()
if total is not None:
self.total = total
self.refresh()

def trange(*args, **kwargs):
"""
Expand Down

0 comments on commit 0e1961c

Please sign in to comment.