Main index > Python programming > Spaces before text

By dessaya (Desklet Author), on Thu Jul 7 20:59:58 2005: Spaces before text.

Thanks for your exhaustive explanation in the previous topic, Sylvain! I have one more issue:
I want to show several lines of text with spaces as first characters, like:

Code:

'     Line1\n     Line2'

but the adesklets implementation forbids me to do so. What is the best workaround you can imagine?
I came up with this crappy solution, which I would like to simplify:

Code:

Split text into lines
For each line, prepend a dummy character (I use the '.' character). '  Hello' becomes '.  Hello'
Create a temporary buffer
Draw each line at a negative x position, so that the dummy character ends up outside the buffer.
Blit the buffer on the desklet.


Initially I thought of using a clipping rectangle, but it seems to be buggy, so I ended up with this ugly hack.
Thanks for your help,
Diego

By syfou (Core Developer & Desklet Author), on Thu Jul 7 23:22:31 2005.

Look at the TorsmoString class from torsmotoy... Of course, you do not have to go that far; basically, the method used was to determine the width of the leading spaces characters by asking for the width of the same-lenght string of underscore, and then simply draw the text taking into account this offset, reiterating for each line.


adesklets is proud to be hosted on:

SourceForge.net Logo

Back to adesklets.sf.net.