How to create nested listboxes in urwid?

后端 未结 1 1460
别跟我提以往
别跟我提以往 2021-01-18 22:21

Is it possible to put ListBoxes inside of SimpleListWalkers ? I\'m trying to make nested ListBoxes, but I have this error :

AttributeError: \'MyListBox\' obje

相关标签:
1条回答
  • 2021-01-18 22:56

    According to the manual ListBox is a box widget that contains flow widgets inside.

    The difference between the types of widgets (box, flow and fixed) lies in the method of calculating their size. The details are described in the aforementioned link. In short: ListBox is informed about its size from its container, but requires its children to calculate their heights on their own. As another ListBox is inside it can't provide this value (has no rows method).

    The solution is to wrap the inner ListBox in BoxAdapter that makes box widget to look and behave like flow widget:

    ...
    widgets   = [urwid.AttrMap(urwid.Text(str(x)),None,"focus") for x in xrange(3)]
    nested    = [urwid.AttrMap(urwid.Text(str(x)+"_sous"),None,"focus") for x in xrange(3)]
    nested_lb = MyListBox(urwid.SimpleListWalker(nested))
    lb        = MyListBox(urwid.SimpleListWalker(widgets+[urwid.BoxAdapter(nested_lb, 10)]))
    ...
    
    0 讨论(0)
提交回复
热议问题