@@ -909,6 +909,37 @@ def get_values(self, progress, data):
909909 return ranges
910910
911911
912+ class FormatLabelBar (FormatLabel , Bar ):
913+ '''A bar which has a formatted label in the center.'''
914+ def __init__ (self , format , ** kwargs ):
915+ FormatLabel .__init__ (self , format , ** kwargs )
916+ Bar .__init__ (self , ** kwargs )
917+
918+ def __call__ (self , progress , data , width , format = None ):
919+ center = FormatLabel .__call__ (self , progress , data , format = format )
920+ bar = Bar .__call__ (self , progress , data , width )
921+
922+ # Aligns the center of the label to the center of the bar
923+ center_len = progress .custom_len (center )
924+ center_left = int ((width - center_len ) / 2 )
925+ center_right = center_left + center_len
926+ return bar [:center_left ] + center + bar [center_right :]
927+
928+
929+ class PercentageLabelBar (Percentage , FormatLabelBar ):
930+ '''A bar which displays the current percentage in the center.'''
931+ # %3d adds an extra space that makes it look off-center
932+ # %2d keeps the label somewhat consistently in-place
933+ def __init__ (self , format = '%(percentage)2d%%' , na = 'N/A%%' , ** kwargs ):
934+ Percentage .__init__ (self , format , na = na , ** kwargs )
935+ FormatLabelBar .__init__ (self , format , ** kwargs )
936+
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+
942+
912943class Variable (FormatWidgetMixin , VariableMixin , WidgetBase ):
913944 '''Displays a custom variable.'''
914945
0 commit comments