@@ -70,7 +70,10 @@ class Label(LabelBase):
70
70
:param bool save_text: Set True to save the text string as a constant in the
71
71
label structure. Set False to reduce memory use.
72
72
: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"""
74
77
75
78
# pylint: disable=unused-argument, too-many-instance-attributes, too-many-locals, too-many-arguments
76
79
# pylint: disable=too-many-branches, no-self-use, too-many-statements
@@ -88,7 +91,10 @@ def __init__(self, font, **kwargs):
88
91
self .local_group
89
92
) # the local_group will always stay in the self Group
90
93
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 " ))
92
98
93
99
# Create the two-color palette
94
100
@@ -114,6 +120,7 @@ def __init__(self, font, **kwargs):
114
120
save_text = kwargs .get ("save_text" , True ),
115
121
scale = kwargs .get ("scale" , 1 ),
116
122
base_alignment = kwargs .get ("base_alignment" , False ),
123
+ tab_replacement = kwargs .get ("tab_replacement" , (4 , " " )),
117
124
)
118
125
119
126
def _reset_text (
@@ -133,6 +140,7 @@ def _reset_text(
133
140
save_text = None ,
134
141
scale = None ,
135
142
base_alignment = None ,
143
+ tab_replacement = None ,
136
144
):
137
145
138
146
# Store all the instance variables
@@ -162,13 +170,15 @@ def _reset_text(
162
170
self ._save_text = save_text
163
171
if base_alignment is not None :
164
172
self .base_alignment = base_alignment
173
+ if tab_replacement is not None :
174
+ self ._tab_replacement = tab_replacement
165
175
166
176
# if text is not provided as a parameter (text is None), use the previous value.
167
177
if (text is None ) and self ._save_text :
168
178
text = self ._text
169
179
170
180
if self ._save_text : # text string will be saved
171
- self ._text = text
181
+ self ._text = self . _tab_text . join ( text . split ( " \t " ))
172
182
else :
173
183
self ._text = None # save a None value since text string is not saved
174
184
@@ -203,7 +213,7 @@ def _reset_text(
203
213
loose_box_y ,
204
214
loose_y_offset ,
205
215
) = self ._text_bounding_box (
206
- text ,
216
+ self . _text ,
207
217
self ._font ,
208
218
self ._line_spacing ,
209
219
) # calculate the box size for a tight and loose backgrounds
@@ -226,7 +236,7 @@ def _reset_text(
226
236
# Place the text into the Bitmap
227
237
self ._place_text (
228
238
self .bitmap ,
229
- text ,
239
+ self . _text ,
230
240
self ._font ,
231
241
self ._line_spacing ,
232
242
self ._padding_left - x_offset ,
@@ -542,4 +552,5 @@ def _set_font(self, new_font):
542
552
raise RuntimeError ("font is immutable when save_text is False" )
543
553
544
554
def _set_text (self , new_text , scale ):
555
+ new_text = self ._tab_text .join (new_text .split ("\t " ))
545
556
self ._reset_text (text = new_text , scale = self .scale )
0 commit comments