Reputation: 12794
I have a Python program that creates an indicator notice in Ubuntu. How does one figure out how many tabs one needs to add in order to make sure the output is always vertically in-line?
I tried counting the characters used and inserting spaces instead of tabs, but this does not work as a non-mono font is used.
Output shown in this picture:
The code that outputs the lines:
for processName in processStatuses:
if processName in cachedProcessStatuses:
if processStatuses[processName] != cachedProcessStatuses[processName]:
output += processName
output += " : \t"
output += processStatuses[processName]
output += "\n"
else:
output += processName
output += " : \t"
output += processStatuses[processName]
output += "\n"
Upvotes: 2
Views: 241
Reputation: 212955
… as a non-mono font is used.
In this case you need to know the font geometry (not a trivial task).
The string "iiii" takes less space than "MMMM", but without knowing the font geometry (exact width of individual characters as well as their relative horizontal position), you cannot know, whether a specific string is wider than a tabwidth or not.
Upvotes: 3