如何获得焦点小部件的子项以显示焦点/活动调色板样式

时间:2019-01-28 19:38:20

标签: python urwid

我有一个自定义按钮小部件,用于显示具有列布局的表。 选择行BoxButton会激活reversed样式,但是嵌套reversed2小部件的Text样式不会被激活。我该如何实现?

palette = [
    ('reversed', 'standout', '', '', 'white', '#6af'),
    ('reversed2', 'standout', '', '', 'g66', '#6af'),
]

class BoxButton(urwid.WidgetWrap):
    _border_char = u'─'
    signals = ["click"]

    def __init__(self, widget, on_press=None, user_data=None):
        padding_size = 2
        self.widget = widget
        if on_press:
            urwid.connect_signal(self, 'click', on_press, user_data)
        super(BoxButton, self).__init__(self.widget)

    def selectable(self):
        return True

    def keypress(self, size, key):
        if self._command_map[key] != urwid.ACTIVATE:
            return key
        self._emit('click')

    def mouse_event(self, size, event, button, x, y, focus):
        if button != 1 or not is_mouse_press(event):
            return False
        self._emit('click')
        return True

def menu(choices):
    body = []
    for c in choices:
        button = BoxButton(urwid.Columns([
            ('weight', 1, urwid.Text(c['name'])),
            # This is the nested widget that should change to activated too
            ('weight', 1, urwid.AttrMap(urwid.Text(c['command']), 'commandCol', 'reversed2')), 
            ('weight', 4, urwid.Text(c['description']))
        ]))
        urwid.connect_signal(button, 'click', item_chosen, c)
        body.append(urwid.AttrMap(button, None, focus_map='reversed'))
    return urwid.ListBox(urwid.SimpleFocusListWalker(body))

main = menu(choices)
loop = urwid.MainLoop(main, palette, unhandled_input=unhandled_input)

这不是完整的代码,但足以理解该问题。

0 个答案:

没有答案