2

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:

Enter image description here

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"

1 Answer 1

3

… 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.

Sign up to request clarification or add additional context in comments.

7 Comments

even then chances are there might not be correct integer counts which would align the text
There's stackoverflow.com/questions/2922295/… which is probably about as good as you can get, and that will only be a best guess, since this isn't using tkinter to do the actual display.
Just wondering if forcing the first column to a certain width (char wise) would make sense/work... '{:50}: {}'.format('a', 'b')
Alternatively, since the OP says he's targeting Ubuntu, he could try to push the output from Python through a terminal/OS based formatting utility via a subprocess or something, since that would presumably already know font settings and spacings for the display interface.
perhaps someone knows how to get python to set the indicator font to a mono font instead then? I.e. somewhere near my call to pynotify.Notification(title, text)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.