Rewritten GetPartialText; moved in util.py
This commit is contained in:
31
util.py
31
util.py
@@ -94,6 +94,37 @@ def fromClipboard():
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
def GetPartialText(dc, text , maxWidth):
|
||||
ellipsis = "..."
|
||||
base_w, h = dc.GetTextExtent(ellipsis)
|
||||
|
||||
lenText = len(text)
|
||||
drawntext = text
|
||||
w, dummy = dc.GetTextExtent(text)
|
||||
|
||||
while lenText > 1:
|
||||
|
||||
if w + base_w <= maxWidth:
|
||||
break
|
||||
|
||||
w_c, h_c = dc.GetTextExtent(drawntext[-1])
|
||||
drawntext = drawntext[0:-1]
|
||||
lenText -= 1
|
||||
w -= w_c
|
||||
|
||||
while len(ellipsis) > 0 and w + base_w > maxWidth:
|
||||
ellipsis = ellipsis[0:-1]
|
||||
base_w, h = dc.GetTextExtent(ellipsis)
|
||||
if len(text) > lenText:
|
||||
return drawntext + ellipsis
|
||||
else:
|
||||
return text
|
||||
|
||||
|
||||
|
||||
|
||||
def set_float(val,default=None):
|
||||
""" utility to set a floating value, useful for converting from strings """
|
||||
if val in (None,''): return default
|
||||
|
||||
Reference in New Issue
Block a user