@@ -70,7 +70,10 @@ class Label(LabelBase):
7070 :param bool save_text: Set True to save the text string as a constant in the
7171 label structure. Set False to reduce memory use.
7272 :param: bool base_alignment: when True allows to align text label to the baseline.
73- This is helpful when two or more labels need to be aligned to the same baseline"""
73+ This is helpful when two or more labels need to be aligned to the same baseline
74+ :param: (int,str) tab_replacement: tuple with tab character replace information. When
75+ (4, " ") will indicate a tab replacement of 4 spaces, defaults to 4 spaces by
76+ tab character"""
7477
7578 # pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments
7679 # pylint: disable=too-many-branches, no-self-use, too-many-statements
@@ -88,7 +91,10 @@ def __init__(self, font, **kwargs):
8891 self .local_group
8992 ) # the local_group will always stay in the self Group
9093
91- self ._text = kwargs .get ("text" , "" )
94+ self .tab_replacement = kwargs .get ("tab_replacement" , (4 , " " ))
95+ self .tab_text = self .tab_replacement [1 ] * self .tab_replacement [0 ]
96+ text = kwargs .get ("text" , "" )
97+ self ._text = self .tab_text .join (text .split ("\t " ))
9298
9399 # Create the two-color palette
94100
@@ -114,6 +120,7 @@ def __init__(self, font, **kwargs):
114120 save_text = kwargs .get ("save_text" , True ),
115121 scale = kwargs .get ("scale" , 1 ),
116122 base_alignment = kwargs .get ("base_alignment" , False ),
123+ tab_replacement = kwargs .get ("tab_replacement" , (4 , " " )),
117124 )
118125
119126 def _reset_text (
@@ -133,6 +140,7 @@ def _reset_text(
133140 save_text = None ,
134141 scale = None ,
135142 base_alignment = None ,
143+ tab_replacement = None ,
136144 ):
137145
138146 # Store all the instance variables
@@ -162,13 +170,15 @@ def _reset_text(
162170 self ._save_text = save_text
163171 if base_alignment is not None :
164172 self .base_alignment = base_alignment
173+ if tab_replacement is not None :
174+ self .tab_replacement = tab_replacement
165175
166176 # if text is not provided as a parameter (text is None), use the previous value.
167177 if (text is None ) and self ._save_text :
168178 text = self ._text
169179
170180 if self ._save_text : # text string will be saved
171- self ._text = text
181+ self ._text = self . tab_text . join ( text . split ( " \t " ))
172182 else :
173183 self ._text = None # save a None value since text string is not saved
174184
@@ -203,7 +213,7 @@ def _reset_text(
203213 loose_box_y ,
204214 loose_y_offset ,
205215 ) = self ._text_bounding_box (
206- text ,
216+ self . _text ,
207217 self ._font ,
208218 self ._line_spacing ,
209219 ) # calculate the box size for a tight and loose backgrounds
@@ -226,7 +236,7 @@ def _reset_text(
226236 # Place the text into the Bitmap
227237 self ._place_text (
228238 self .bitmap ,
229- text ,
239+ self . _text ,
230240 self ._font ,
231241 self ._line_spacing ,
232242 self ._padding_left - x_offset ,
@@ -542,4 +552,5 @@ def _set_font(self, new_font):
542552 raise RuntimeError ("font is immutable when save_text is False" )
543553
544554 def _set_text (self , new_text , scale ):
555+ new_text = self .tab_text .join (new_text .split ("\t " ))
545556 self ._reset_text (text = new_text , scale = self .scale )
0 commit comments