[Urwid] Edit widgets with multiple attributes
ian at excess.org
Mon Jun 4 09:48:36 EDT 2007
James Reeves wrote:
> Hi there,
> I'm having a little difficulty understanding how urwid renders palette
> attributes to a canvas. I'd like to subclass the Edit widget and have it
> apply different attributes to areas of text that match certain regular
> expressions - in other words, a syntax-highlighting feature.
> Is it currently possible to do this in urwid, and if so, does anyone
> have any suggestions about how might be the best way to go about it?
You can either override the get_text() method to figure out which
attributes are needed on the fly, or you can modify the attrib array in
the Edit object after each call to set_edit_text().
Attribute arrays look like this:
>>> urwid.Text(["hello", ('big', " there")]).attrib
[(None, 5), ('big', 6)]
ie. they are (attribute, number of character) tuples in a list.
More information about the Urwid