[Urwid] Creating a border around a widget
Ian Ward
ian at excess.org
Fri Aug 11 11:36:19 EDT 2006
Sébastien Pierre wrote:
> File "urwid/widget.py", line 1661, in render
> focus and self.focus_part == 'body')
> File "urwid/listbox.py", line 248, in render
> middle, top, bottom = self.calculate_visible(
> File "urwid/listbox.py", line 203, in calculate_visible
> n_rows = next.rows ( (maxcol,) )
> AttributeError: Filler instance has no attribute 'rows'
>
> It seems like Filler does not implement the `rows` method... is it on
> purpose ?
Yes, Filler is a box widget whose purpose is to add lines above and/or
below a flow widget so that it "fills" the area provided to the Filler
widget. Since it is a box widget it needs to be told how many rows it
has -- it can't have a rows() function.
As of 0.9.5 you can use Pile widgets as either box widgets or flow
widgets. This is a widget similar to the new "LineBox" class in
graphics.py, which you could use for a border:
class Border(urwid.WidgetWrap):
def __init__(self, w):
# Define the border characters
tline = bline = urwid.Divider("B")
lline = rline = urwid.SolidFill("B")
tlcorner = urwid.Text("B")
trcorner = blcorner = brcorner = tlcorner
top = Columns([ ('fixed', 1, tlcorner),
tline, ('fixed', 1, trcorner) ])
middle = Columns( [('fixed', 1, lline),
w, ('fixed', 1, rline)], box_columns = [0,2],
focus_column = 1)
bottom = Columns([ ('fixed', 1, blcorner),
bline, ('fixed', 1, brcorner) ])
pile = Pile([('flow',top),middle,('flow',bottom)],
focus_item = 1)
WidgetWrap.__init__(self, pile)
> This leads me to the fact that it would be really nice to define a
> global Widget interface, and a global Container interface, so that we
> can really know what methods are required in the layout process.
I have tried to document the widget interface definition:
http://excess.org/urwid/reference.html#Widget_interface_definition
A global container interface would allow a generic render function to
walk the tree of widgets. That could really improve the error messages
when the wrong type of widget is used, and in reporting exactly which
widget failed. That is high on my list of priorities, but it might break
backwards compatibility.
Ian
More information about the Urwid
mailing list