This was exactly what I searched for! Thank you very much!

Best,
 Joern

On Friday 25 April 2008 11:11:03 Max E. Kuznecov wrote:
> 2008/4/25, Joern Koerner <[EMAIL PROTECTED]>:
> > Hi!
> >
> >  I've a small problem with Overlay.
> >  I want to create a "caption" for a LineBox that contains a listbox with
> > an overlay.  Just a small simple text that sits around the top left
> > corner and does nothing.
>
> For my project I've created a separate widget - linebox with title,
> based on LineBox:
>
> class Border(urwid.WidgetWrap):
>     def __init__(self, widget, title=None, attr=None):
>         """
>         Draw a line border around widget and set up a title
>         @param widget: Widget to wrap
>         @param title: (title, attribute) tuple or basestring
>         @type title: urwid.Text object
>         @param attr: Attribute of border
>         """
>
>         utf8decode = urwid.escape.utf8decode
>
>         _title = None
>
>         if title is not None:
>             if isinstance(title, tuple):
>                 _len = len(title[0])
>                 _title = urwid.Text((title[1], " %s " % title[0]),
> "center") elif isinstance(title, basestring):
>                 _len = len(title)
>                 _title = urwid.Text(title, "center")
>             else:
>                 raise UIError("Invalid title type %s. "\
>                               "Tuple or basetring expected" % type(_title))
>
>             _len += 2 # " _text "
>
>         self.attr = attr
>
>         self.tline = self._attr(urwid.Divider(utf8decode("─")))
>         self.bline = self._attr(urwid.Divider(utf8decode("─")))
>         self.lline = self._attr(urwid.SolidFill(utf8decode("│")))
>         self.rline = self._attr(urwid.SolidFill(utf8decode("│")))
>
>         self.tlcorner = self._attr(urwid.Text(utf8decode("┌")))
>         self.trcorner = self._attr(urwid.Text(utf8decode("┐")))
>         self.blcorner = self._attr(urwid.Text(utf8decode("└")))
>         self.brcorner = self._attr(urwid.Text(utf8decode("┘")))
>
>         tline_widgets = [('fixed', 1, self.tlcorner), self.tline]
>
>         if title is not None:
>             tline_widgets.append(("fixed", _len, _title))
>
>         tline_widgets.extend([self.tline, ("fixed", 1, self.trcorner)])
>
>         self.top = urwid.Columns(tline_widgets)
>         self.middle = urwid.Columns([('fixed', 1, self.lline),
>                                     widget, ('fixed', 1, self.rline)],
>                                     box_columns=[0,2], focus_column=1)
>
>         self.bottom = urwid.Columns([('fixed', 1, self.blcorner),
>                                     self.bline, ('fixed', 1,
> self.brcorner)])
>
>         self.pile = urwid.Pile([('flow',self.top), self.middle,
>                                ('flow', self.bottom)], focus_item=1)
>
>         super(Border, self).__init__(self.pile)
>
>     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>     def _attr(self, widget):
>         if self.attr is None:
>             return widget
>
>         return urwid.AttrWrap(widget, self.attr)
>
> May be it would be useful.




_______________________________________________
Urwid mailing list
[email protected]
http://lists.excess.org/mailman/listinfo/urwid

Reply via email to