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.
Cheers HC
# HG changeset patch # User [email protected] # Date 1268142520 -3600 # Node ID 34707ddc1ec0731456ec58cf0119b97736b47d5f # Parent 31426f14272a86f9d09178e1907fff64c52e8a7b Add pack method to the Button widget diff -r 31426f14272a -r 34707ddc1ec0 urwid/wimp.py --- a/urwid/wimp.py Thu Feb 11 19:20:05 2010 -0500 +++ b/urwid/wimp.py Tue Mar 09 14:48:40 2010 +0100 @@ -530,6 +530,14 @@ self._emit('click') return True + def pack(self): + lbw, lbh = self.button_left.pack() + rbw, rbh = self.button_right.pack() + mew, meh = len(self._label.text) + 2, 1 + meh = lbh if lbh > meh else meh + meh = rbh if rbh > meh else meh + return lbw + rbw + mew, meh + def _test(): import doctest
# HG changeset patch # User [email protected] # Date 1268141321 -3600 # Node ID 6aaee06705332f387221d2ad71dc3821f033c2ba # Parent 762816bf42187762be9f7cf29eb84d4f349a394a Add 'packed' align type to Columns widget diff -r 762816bf4218 -r 6aaee0670533 urwid/container.py --- a/urwid/container.py Tue Mar 09 14:17:56 2010 +0100 +++ b/urwid/container.py Tue Mar 09 14:28:41 2010 +0100 @@ -1020,6 +1020,7 @@ widget_list may also contain tuples such as: ('fixed', width, widget) give this column a fixed width ('weight', weight, widget) give this column a relative weight + ('packed', widget) give this column the minimum width possible widgets not in a tuple are the same as ('weight', 1, widget) @@ -1039,6 +1040,15 @@ self.widget_list[i] = widget self.column_types.append((f,width)) w = widget + elif w[0] == 'packed': + f,widget = w + self.widget_list[i] = widget + def makepackfunc(widget, index): + def getpack(): + return widget.pack()[index] + return getpack + self.column_types.append((f,makepackfunc(widget, 0))) + w = widget else: raise ColumnsError, "widget list item invalid: %s" % `w` if focus_column is None and w.selectable(): @@ -1110,6 +1120,8 @@ for t, width in col_types: if t == 'fixed': static_w = width + elif t == 'packed': + static_w = width() else: static_w = self.min_width @@ -1118,7 +1130,7 @@ widths.append( static_w ) shared -= static_w + self.dividechars - if t != 'fixed': + if t not in ('fixed', 'packed'): weighted.append( (width,i) ) i += 1
signature.asc
Description: Digital signature
_______________________________________________ Urwid mailing list [email protected] http://lists.excess.org/mailman/listinfo/urwid
