Skip to content

Commit 8ba5064

Browse files
committed
Allow customizing the N/A% string in Percentage.
Move the selection of whether to use N/A% to a separate method.
1 parent ff05b64 commit 8ba5064

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

progressbar/widgets.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,17 +628,20 @@ def __call__(self, progress, data, format=None):
628628
class Percentage(FormatWidgetMixin, WidgetBase):
629629
'''Displays the current percentage as a number with a percent sign.'''
630630

631-
def __init__(self, format='%(percentage)3d%%', **kwargs):
631+
def __init__(self, format='%(percentage)3d%%', na='N/A%%', **kwargs):
632+
self.na = na
632633
FormatWidgetMixin.__init__(self, format=format, **kwargs)
633634
WidgetBase.__init__(self, format=format, **kwargs)
634635

635636
def __call__(self, progress, data, format=None):
637+
return FormatWidgetMixin.__call__(self, progress, data, self.get_format(progress, data))
638+
639+
def get_format(self, progress, data):
636640
# If percentage is not available, display N/A%
637641
if 'percentage' in data and not data['percentage']:
638-
return FormatWidgetMixin.__call__(self, progress, data,
639-
format='N/A%%')
642+
return self.na
640643

641-
return FormatWidgetMixin.__call__(self, progress, data)
644+
return self.format
642645

643646

644647
class SimpleProgress(FormatWidgetMixin, WidgetBase):

0 commit comments

Comments
 (0)