Skip to content

Commit 5256dfc

Browse files
committed
Drop staticmethod for format_meter + mininterval controls looping animation speed (instead of n)
Signed-off-by: Stephen L. <[email protected]>
1 parent f0231e6 commit 5256dfc

1 file changed

Lines changed: 25 additions & 15 deletions

File tree

tqdm/_tqdm_custom.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class tqdm_custom(tqdm):
3535
"""
3636
tqdm with nice customizable bar symbols!
3737
"""
38-
@staticmethod
39-
def format_meter(n, total, elapsed, ncols=None, prefix='',
38+
def format_meter(self, n, total, elapsed, ncols=None, prefix='',
4039
ascii=False, unit='it', unit_scale=False, rate=None,
4140
bar_format=None):
4241
"""
@@ -187,8 +186,10 @@ def format_meter(n, total, elapsed, ncols=None, prefix='',
187186
c_symb = bar_format['symbols'].get('unicode', map(_unich, range(0x258F, 0x2587, -1)))
188187
# looping symbols: just update the symbol animation at each iteration
189188
if bar_format['symbols'].get('loop', False):
190-
# increment one step in the animation at each step
191-
bar = c_symb[divmod(n, len(c_symb))[1]]
189+
# increment one step in the animation for each display
190+
self.n_anim += 1
191+
# get the symbol for current animation step
192+
bar = c_symb[divmod(self.n_anim, len(c_symb))[1]]
192193
frac_bar = ''
193194

194195
bar_length = N_BARS # avoid the filling
@@ -254,16 +255,20 @@ def format_meter(n, total, elapsed, ncols=None, prefix='',
254255
c_symb = bar_format['symbols_indeterminate'].get('unicode', ["====="])
255256
# looping symbols: just update the symbol animation at each iteration
256257
if bar_format['symbols_indeterminate'].get('loop', False):
257-
# increment one step in the animation at each step
258-
bar = c_symb[divmod(n, len(c_symb))[1]]
258+
# increment one step in the animation for each display
259+
self.n_anim += 1
260+
# Get current bar animation based on current iteration
261+
bar = c_symb[divmod(self.n_anim, len(c_symb))[1]]
259262

260263
bar_length = N_BARS # avoid the filling
261264
# indeterminate progress bar (cycle from left to right then right to left)
262265
else:
266+
# increment one step in the animation for each display
267+
self.n_anim += 1
263268
# Get current bar animation based on current iteration
264-
bar = c_symb[divmod(n, len(c_symb))[1]]
269+
bar = c_symb[divmod(self.n_anim, len(c_symb))[1]]
265270
# Get left filling space and animation step (right pass or left?)
266-
anim_step, fill_left = divmod(n, (N_BARS - len(bar)))
271+
anim_step, fill_left = divmod(self.n_anim, (N_BARS - len(bar)))
267272
# If anim_step is odd, then we do left pass (2nd pass)
268273
if divmod(anim_step, 2)[1] == 1:
269274
# Inverse the left filling space (now it's the right space)
@@ -289,14 +294,18 @@ def format_meter(n, total, elapsed, ncols=None, prefix='',
289294

290295
def __init__(self, *args, **kwargs):
291296
"""
297+
mininterval: float, optional
298+
Controls display refresh rate just like for core tqdm,
299+
but in addition also controls looping symbols animation speed
300+
(except if miniters is set, then miniters controls the animation).
292301
bar_format: str/dict, optional
293-
Can either be a string, or a dict for more complex templating.
294-
Format: {'template': '{l_bar}{bar}{r_bar}',
295-
'symbols': {'unicode': ['1', '2', '3', '4', '5', '6'],
296-
'ascii': ['1', '2', '3'],
297-
'loop': False}
298-
'symbols_indeterminate': {'unicode': ....
299-
}
302+
Can either be a string, or a dict for more complex templating.
303+
Format: {'template': '{l_bar}{bar}{r_bar}',
304+
'symbols': {'unicode': ['1', '2', '3', '4', '5', '6'],
305+
'ascii': ['1', '2', '3'],
306+
'loop': False}
307+
'symbols_indeterminate': {'unicode': ....
308+
}
300309
"""
301310
# get bar_format
302311
bar_format = kwargs.get('bar_format', None)
@@ -310,6 +319,7 @@ def __init__(self, *args, **kwargs):
310319
# Store the arguments
311320
bar_format['template'] = self.bar_format
312321
self.bar_format = bar_format
322+
self.n_anim = 0 # animation step for looping symbols
313323

314324

315325
def tcrange(*args, **kwargs):

0 commit comments

Comments
 (0)