[Urwid] Add 'packed' mode to Columns widget

Ian Ward ian at excess.org
Wed Mar 10 21:16:31 EST 2010


Hans-Christian Esperer wrote on 2010-03-09 08:54:
> Hi,
> 
> here's a little patch that adds a 'packed' mode to the Columns widget
> that acts like the 'fixed' mode but determines the width by calling
> the containee's pack() method. In conjunction with that, I've added a
> pack() method to the Button widget.
> 

Thanks HC,

I imagined packing for Columns would be more like what you get with
columns in an HTML table.  If there are a couple of long Text widgets in
columns that would easily fit on screen with wrapping, with this
implementation they would go off the screen, because each would pack to
its full, unwrapped size.

There should be some kind of heuristic for determining the size to pack
each widget, like:
 - calculate remaining_size as the columns_size less fixed columns
 - call pack(remaining_size) on each widget to be packed
 - if the total is greater than the width available use the returned
   values to divide up remaining_size proportionally and call pack()
   again with each proportion


Also, It would be better to avoid implementing pack() in Button by
adding it to WidgetWrap and implementing it in Columns (which is what
Button uses to draw itself).


All that said, your implementation pretty simple and useful right now.

Ian



More information about the Urwid mailing list