[Urwid] possible bug: AttrMap does not pass function calls/property lookups to the wrapped widget

Vlad vlad at demoninsight.com
Mon Feb 17 10:04:08 EST 2014


Greetings,

	I've built an urwid application that makes use of several urwid features: it looks a bit like a spreadsheet with editable/tab-able cells and expandable rows, uses Columns, Buttons, Frames, as well as widgets that are extensions of urwid widgets or WidgetWrap. I can say at this point that urwid is a very useful framework and fits its niche very well.

Over the course of building this app I noticed something that might be a bug or “user error”:

	- contrary to the documentation, AttrMap does not appear to forward method calls to ‘w’, the wrapped widget. Here is a quick repro, a modification of Hello World:

import urwid

palette = [
    ('body',        'white',        'black'),
]

txt = urwid.Text(u"Hello World")
txt = urwid.AttrMap (txt, 'body')
#txt.original_widget.set_text (u"Goodbye World") # this works
txt.set_text (u"Goodbye World") # this doesn’t (but will if you use the deprecated AttrWrap)
fill = urwid.Filler(txt, 'top')
loop = urwid.MainLoop(fill)
loop.run()

I find AttrMap to be a very useful design concept. But I think it falls short of its intended purpose because I find myself constantly needing to insert .base_widget in various places — AttrMap is not as transparent as the docs suggest. A piece of urwid code will work but later break when you add an extra AttrMap layer somewhere. Note that using AttrWrap instead makes the example above work — even though AttrWrap is deprecated in favor of AttrMap. Several stock urwid examples also break if AttrWrap is replaced with AttrMap, and it originally took me a few hours to figure out why.

HTH,
Vlad 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.excess.org/pipermail/urwid/attachments/20140217/a3574019/attachment.htm 


More information about the Urwid mailing list