core:text make shorten work with a single word. closes #1334

This commit is contained in:
qua-non 2013-08-07 01:15:34 +05:30
parent 3b2d493e50
commit cf5fc48229
1 changed files with 4 additions and 4 deletions

View File

@ -203,15 +203,15 @@ class LabelBase(object):
def shorten(self, text, margin=2): def shorten(self, text, margin=2):
# Just a tiny shortcut # Just a tiny shortcut
textwidth = lambda txt: self.get_extents(txt)[0] textwidth = self.get_extents
if self.text_size[0] is None: if self.text_size[0] is None:
width = 0 width = 0
else: else:
width = int(self.text_size[0]) width = int(self.text_size[0])
letters = ' ... ' + text letters = '_..._' + text
while textwidth(letters) > width: while textwidth(letters)[0] > width:
letters = letters[: letters.rfind(' ')] letters = letters[:letters.rfind(' ')]
max_letters = len(letters) - 2 max_letters = len(letters) - 2
segment = (max_letters // 2) segment = (max_letters // 2)