[Urwid] possible bug: AttrMap does not pass function calls/property lookups to the wrapped widget
vlad at demoninsight.com
Mon Feb 17 10:04:08 EST 2014
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:
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)
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Urwid