refactor eta widget
This commit is contained in:
@@ -103,21 +103,23 @@ class ProgressBarWidgetHFill(object):
|
|||||||
|
|
||||||
class ETA(ProgressBarWidget):
|
class ETA(ProgressBarWidget):
|
||||||
"Widget for the Estimated Time of Arrival"
|
"Widget for the Estimated Time of Arrival"
|
||||||
def __init__(self, prefix='ETA: ', format='%H:%M:%S'):
|
def __init__(self, prefix='ETA: ', format=None):
|
||||||
self.format = format
|
|
||||||
self.prefix = prefix
|
self.prefix = prefix
|
||||||
|
if format:
|
||||||
def format_time(self, seconds):
|
self.format = format
|
||||||
return time.strftime(self.format, time.gmtime(seconds))
|
else:
|
||||||
|
self.format = lambda seconds: '%02ih %02im %02is' % \
|
||||||
|
(seconds // 3600, (seconds % 3600) // 60, seconds % 60)
|
||||||
|
|
||||||
def update(self, pbar):
|
def update(self, pbar):
|
||||||
if pbar.currval == 0:
|
if pbar.finished:
|
||||||
return self.prefix + '-' * len(self.format)
|
return 'Time: ' + self.format(pbar.seconds_elapsed)
|
||||||
elif pbar.finished:
|
|
||||||
return 'Time: %s' % self.format_time(pbar.seconds_elapsed)
|
|
||||||
else:
|
else:
|
||||||
|
if pbar.currval:
|
||||||
eta = pbar.seconds_elapsed * pbar.maxval / pbar.currval - pbar.seconds_elapsed
|
eta = pbar.seconds_elapsed * pbar.maxval / pbar.currval - pbar.seconds_elapsed
|
||||||
return self.prefix + self.format_time(eta)
|
return self.prefix + self.format(eta)
|
||||||
|
else:
|
||||||
|
return self.prefix + '-' * 6
|
||||||
|
|
||||||
class GenericSpeed(ProgressBarWidget):
|
class GenericSpeed(ProgressBarWidget):
|
||||||
"Widget for showing the values/s"
|
"Widget for showing the values/s"
|
||||||
|
|||||||
Reference in New Issue
Block a user