@@ -114,15 +114,19 @@ def __init__(self, format, new_style=False, **kwargs):
114114 self .new_style = new_style
115115 self .format = format
116116
117+ def get_format (self , progress , data , format = None ):
118+ return format or self .format
119+
117120 def __call__ (self , progress , data , format = None ):
118121 '''Formats the widget into a string'''
122+ format = self .get_format (progress , data , format )
119123 try :
120124 if self .new_style :
121- return ( format or self . format ) .format (** data )
125+ return format .format (** data )
122126 else :
123- return ( format or self . format ) % data
127+ return format % data
124128 except (TypeError , KeyError ):
125- print ('Error while formatting %r' % self . format , file = sys .stderr )
129+ print ('Error while formatting %r' % format , file = sys .stderr )
126130 pprint .pprint (data , stream = sys .stderr )
127131 raise
128132
@@ -633,17 +637,13 @@ def __init__(self, format='%(percentage)3d%%', na='N/A%%', **kwargs):
633637 FormatWidgetMixin .__init__ (self , format = format , ** kwargs )
634638 WidgetBase .__init__ (self , format = format , ** kwargs )
635639
636- def __call__ (self , progress , data , format = None ):
637- return FormatWidgetMixin .__call__ (self , progress , data ,
638- self .get_format (progress , data ))
639-
640640 def get_format (self , progress , data , format = None ):
641641 # If percentage is not available, display N/A%
642- if ( ' percentage' in data and not data [ 'percentage' ] and
643- data [ ' percentage' ] != 0 ) :
642+ percentage = data . get ( 'percentage' , base . Undefined )
643+ if not percentage and percentage != 0 :
644644 return self .na
645645
646- return format or self . format
646+ return FormatWidgetMixin . get_format ( self , progress , data , format )
647647
648648
649649class SimpleProgress (FormatWidgetMixin , WidgetBase ):
@@ -934,11 +934,6 @@ def __init__(self, format='%(percentage)2d%%', na='N/A%%', **kwargs):
934934 Percentage .__init__ (self , format , na = na , ** kwargs )
935935 FormatLabelBar .__init__ (self , format , ** kwargs )
936936
937- def __call__ (self , progress , data , width , format = None ):
938- return FormatLabelBar .__call__ (
939- self , progress , data , width ,
940- format = Percentage .get_format (self , progress , data , format = None ))
941-
942937
943938class Variable (FormatWidgetMixin , VariableMixin , WidgetBase ):
944939 '''Displays a custom variable.'''
0 commit comments