[Urwid] Creating a border around a widget
Sébastien Pierre
sebastien at xprima.com
Fri Aug 11 12:24:25 EDT 2006
Ian Ward a écrit :
>> 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.
It would be great to make this clearer... because it is quite unnatural
that a widget found in 'top-level widgets' (Filler, in this case) does
not implement the 'widgets' interface.
I think it would be simpler to say : if a class does not implement the
widget interface, it is not a widget. And then Filler would not be a
widget. So maybe there is a need for an intermediate interface ?
> 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 is great !
Would you consider including it in the next release of URWID ?
> I have tried to document the widget interface definition:
> http://excess.org/urwid/reference.html#Widget_interface_definition
I find it hard to get the hierarchy of classes in the documentation.
> 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.
This would be really helpful, as I personnaly would like to
iterate/manipulate the content of containers using a uniform interface
(instead of having to care about each particular case).
I can't wait to see this implemented :)
Thanks,
-- Sébastien
More information about the Urwid
mailing list