input_test.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:Adwear 作者: Uberi 项目源码 文件源码
def key_test():
    screen = Screen()
    header = urwid.Text("Values from get_input(). Q exits.")
    header = urwid.AttrWrap(header,'header')
    lw = urwid.SimpleListWalker([])
    listbox = urwid.ListBox(lw)
    listbox = urwid.AttrWrap(listbox, 'listbox')
    top = urwid.Frame(listbox, header)

    def input_filter(keys, raw):
        if 'q' in keys or 'Q' in keys:
            raise urwid.ExitMainLoop

        t = []
        a = []
        for k in keys:
            if type(k) == tuple:
                out = []
                for v in k:
                    if out:
                        out += [', ']
                    out += [('key',repr(v))]
                t += ["("] + out + [")"]
            else:
                t += ["'",('key',k),"' "]

        rawt = urwid.Text(", ".join(["%d"%r for r in raw]))

        if t:
            lw.append(
                urwid.Columns([
                    ('weight',2,urwid.Text(t)),
                    rawt])
                )
            listbox.set_focus(len(lw)-1,'above')
        return keys

    loop = urwid.MainLoop(top, [
        ('header', 'black', 'dark cyan', 'standout'),
        ('key', 'yellow', 'dark blue', 'bold'),
        ('listbox', 'light gray', 'black' ),
        ], screen, input_filter=input_filter)

    try:
        old = screen.tty_signal_keys('undefined','undefined',
            'undefined','undefined','undefined')
        loop.run()
    finally:
        screen.tty_signal_keys(*old)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号