[Urwid] Fwd: custom padding?

Ian Ward ian at excess.org
Fri Aug 19 14:39:07 EDT 2011

Patrick Totzke wrote on 2011-08-17 11:15:
> Hi!
> I wonder how I can use a Decoration widget to pad a line with something different from whitespaces:
> I have a Column of text widgets and a very long string.
> If I render my Column line I get something like this
> ^|first text|second text|third text|                        $
> Here ^ is the begining of the line on the screen, $ marks the end.
> All texts but the last one are give as fixed length:
> first = firststring
> second = secondstring
> third = thirdstring
> Columms([('fixed', len(first), Text(first)),
>          ('fixed', len(second), Text(second)),
>          Text(third, wrap='clip')])
> The reason I don't fix the length of the last string is because its length varies
> and if its long, longer as the space on the screen, it doesn't get displayed at all.
> Lets say my long string is pi = '3.141592653589793238462643383279502884197169399375105820974944592307'.
> I want to render the above line as 
> ^|first text|second text|third text|3.1415926535897932384626$
> Now, I add the long string as a Column.
> If I fix the third text widget as ('fixed', len(third), Text(third)),
> and if it is long, it doesn't fill the line with a prefix.
> If I don't fix it and also not the pi-string, both get weight 1, which results in something like this:
> ^|first text|second text| long third text cut|3.141592653589$,
> both pi and the last string get equal size.
> If i fix both:
>      ('fixed', len(third), Text(third)),
>      ('fixed', len(pi), Text(pi)),
> pi never gets displayed as it is always larger than my screen.
> So, I want something like padding, but with a custom string instead of ' '.
> What's the easiest way to do this?
> Thanks!
> /p

For endless repeating characters you can use Divider or a SolidFill
widget (if you need a box widget).

I've thought about making the fill customizable for the Padding and
Filler widgets (kind of like the background in an Overlay).  That might
simplify some common cases.


More information about the Urwid mailing list