[Urwid] Rendering standout attribute across entire Columns widget

Jacob Courtneay jacob at sporkexec.com
Wed Aug 24 03:15:22 EDT 2011


I'm trying to get a ListBox full of 1-row Columns containing styled Text's to 
render the focused row (or any row for that matter) in standout. Here's my 
smallest possible example:

#!/usr/bin/env python2
from urwid import MainLoop, Text, Columns, ListBox, AttrMap
palette = [
    ('one',       'yellow',          'default'),
    ('two',       'white',          'default'),
    ('one.focus', 'yellow,standout', 'default'),
    ('two.focus', 'white,standout', 'default'),

def mkcolumns(text, moretext):
    one = ('weight', 1.0, Text(('col1', text)))
    two = ('weight', 2.0, Text(('col2', moretext)))
    cols = Columns((one, two))
    return AttrMap(cols,                                     
                   {'col1': 'one', 'col2': 'two'},           
                   {'col1': 'one.focus', 'col2': 'two.focus'})
cols = mkcolumns('text', 'more text'), mkcolumns('stuff', 'more stuff')
root = ListBox(cols)
loop = MainLoop(root, palette)

The output can be seen here on the bottom right. My actual application is on the 
left, and the desired behavior on the middle right.

I'm not sure if the Columns is truncating the output, or not rendering the Text 
with all available width, or something else. A standout'ed Text put directly in 
a ListBox renders full width as expected. Am I getting something wrong with 

Also, is there a simple way to have attributes "inherit" from their parents or 
vice versa? i.e. in the above example, instead of making the row standout is 
there a way to make the entire row bold without remapping every attribute?

Thank you!
-- Jacob

More information about the Urwid mailing list