Python urwid 模块,SimpleListWalker() 实例源码

我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用urwid.SimpleListWalker()

项目:Drogo    作者:csrgxtu    | 项目源码 | 文件源码
def __init__(self, title, command_caption='Command:  (Tab to switch focus to upper frame, where you can scroll text)', cmd_cb=None, max_size=1000):
        self.header=urwid.Text(title)
        self.model=urwid.SimpleListWalker([])
        self.body=ListView(self.model, lambda: self._update_focus(False), max_size=max_size )
        self.input=Input(lambda: self._update_focus(True))
        foot=urwid.Pile([urwid.AttrMap(urwid.Text(command_caption), 'reversed'),
                        urwid.AttrMap(self.input,'normal')])
        urwid.Frame.__init__(self,
                             urwid.AttrWrap(self.body, 'normal'),
                             urwid.AttrWrap(self.header, 'reversed'),
                             foot)
        self.set_focus_path(['footer',1])
        self._focus=True
        urwid.connect_signal(self.input,'line_entered',self.on_line_entered)
        self._cmd=cmd_cb
        self._output_styles=[s[0] for s in self.PALLETE]
        self.eloop=None
项目:Drogo    作者:csrgxtu    | 项目源码 | 文件源码
def __init__(self, title, command_caption='Command:  (Tab to switch focus to upper frame, where you can scroll text)', cmd_cb=None, max_size=1000):
        self.header=urwid.Text(title)
        self.model=urwid.SimpleListWalker([])
        self.body=ListView(self.model, lambda: self._update_focus(False), max_size=max_size )
        self.input=Input(lambda: self._update_focus(True))
        foot=urwid.Pile([urwid.AttrMap(urwid.Text(command_caption), 'reversed'),
                        urwid.AttrMap(self.input,'normal')])
        urwid.Frame.__init__(self,
                             urwid.AttrWrap(self.body, 'normal'),
                             urwid.AttrWrap(self.header, 'reversed'),
                             foot)
        self.set_focus_path(['footer',1])
        self._focus=True
        urwid.connect_signal(self.input,'line_entered',self.on_line_entered)
        self._cmd=cmd_cb
        self._output_styles=[s[0] for s in self.PALLETE]
        self.eloop=None
项目:papis    作者:alejandrogallo    | 项目源码 | 文件源码
def __init__(self, ui, query=None):
        self.ui = ui

        self.ui.set_header("Search: " + query)

        docs = self.ui.db.search(query)
        if len(docs) == 0:
            self.ui.set_status('No documents found.')

        items = []
        for doc in docs:
            items.append(DocListItem(doc))

        self.lenitems = len(items)
        self.listwalker = urwid.SimpleListWalker(items)
        self.listbox = urwid.ListBox(self.listwalker)
        w = self.listbox

        self.__super.__init__(w)
        self.update_prompt()
项目:PyAlertMe    作者:jamesleesaunders    | 项目源码 | 文件源码
def __init__(self, title,
                 command_caption='Command:  (Tab to switch focus to upper frame, where you can scroll text)',
                 cmd_cb=None, max_size=1000):
        self.header = urwid.Text(title)
        self.model = urwid.SimpleListWalker([])
        self.body = ListView(self.model, lambda: self._update_focus(False), max_size=max_size)
        self.input = Input(lambda: self._update_focus(True))
        foot = urwid.Pile([urwid.AttrMap(urwid.Text(command_caption), 'reversed'),
                           urwid.AttrMap(self.input, 'normal')])
        urwid.Frame.__init__(self,
                             urwid.AttrWrap(self.body, 'normal'),
                             urwid.AttrWrap(self.header, 'reversed'),
                             foot)
        self.set_focus_path(['footer', 1])
        self._focus = True
        urwid.connect_signal(self.input, 'line_entered', self.on_line_entered)
        self._cmd = cmd_cb
        self._output_styles = [s[0] for s in self.PALLETE]
        self.eloop = None
项目:terminal-leetcode    作者:chishui    | 项目源码 | 文件源码
def make_failed_view(self):
        blank = urwid.Divider()
        status_header = urwid.AttrWrap(urwid.Text('Run Code Status: '), 'body')
        status = urwid.AttrWrap(urwid.Text('Wrong Answer'), 'hometag')
        columns = urwid.Columns([(17, status_header), (20, status)])
        result_header = urwid.Text('--- Run Code Result: ---', align='center')
        passed_header = urwid.Text('Passed test cases:')
        s = self.result['compare_result']
        passed = urwid.Text('%d/%d' % (s.count('1'), len(s)))
        your_input_header = urwid.Text('Your input:')
        your_input = urwid.Text(self.result['input'])
        your_answer_header = urwid.Text('Your answer:')
        your_answer = urwid.Text(self.result['code_output'])
        expected_answer_header = urwid.Text('Expected answer:')
        expected_answer = urwid.Text(self.result['expected_output'])
        list_items = [
                result_header,
                blank, columns,
                blank, passed_header, passed,
                blank, your_input_header, your_input,
                blank, your_answer_header, your_answer,
                blank, expected_answer_header, expected_answer
        ]
        self._append_stdout_if_non_empty(list_items)
        return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)
项目:terminal-leetcode    作者:chishui    | 项目源码 | 文件源码
def make_compile_error_view(self):
        blank = urwid.Divider()
        status_header = urwid.AttrWrap(urwid.Text('Run Code Status: '), 'body')
        status = urwid.AttrWrap(urwid.Text('Compile Error'), 'hometag')
        columns = urwid.Columns([(17, status_header), (20, status)])
        column_wrap = urwid.WidgetWrap(columns)
        result_header = urwid.Text('--- Run Code Result: ---', align='center')
        your_input_header = urwid.Text('Your input:')
        your_input = urwid.Text('')
        your_answer_header = urwid.Text('Your answer:')
        your_answer = urwid.Text(self.result['compile_error'])
        expected_answer_header = urwid.Text('Expected answer:')
        expected_answer = urwid.Text('Unkown Error')
        list_items = [
                result_header,
                blank, column_wrap,
                blank, your_input_header, your_input,
                blank, your_answer_header, your_answer,
                blank, expected_answer_header, expected_answer
        ]
        self._append_stdout_if_non_empty(list_items)
        return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)
项目:terminal-leetcode    作者:chishui    | 项目源码 | 文件源码
def make_runtime_error_view(self):
        blank = urwid.Divider()
        status_header = urwid.AttrWrap(urwid.Text('Run Code Status: '), 'body')
        status = urwid.AttrWrap(urwid.Text('Runtime Error'), 'hometag')
        columns = urwid.Columns([(17, status_header), (20, status)])
        column_wrap = urwid.WidgetWrap(columns)
        result_header = urwid.Text('--- Run Code Result: ---', align='center')
        error_header = urwid.Text('Runtime Error Message:')
        error_message = urwid.Text(self.result['runtime_error'])
        your_input_header = urwid.Text('Last input:')
        your_input = urwid.Text(self.result['last_testcase'])
        list_items = [
                result_header,
                blank, column_wrap,
                blank, error_header, error_message,
                blank, your_input_header, your_input,
        ]
        self._append_stdout_if_non_empty(list_items)
        return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)
项目:terminal-leetcode    作者:chishui    | 项目源码 | 文件源码
def make_unified_error_view(self, error_title):
        blank = urwid.Divider()
        status_header = urwid.AttrWrap(urwid.Text('Run Code Status: '), 'body')
        status = urwid.AttrWrap(urwid.Text(error_title), 'hometag')
        columns = urwid.Columns([(17, status_header), (30, status)])
        column_wrap = urwid.WidgetWrap(columns)
        if 'last_testcase' in self.result:
            result_header = urwid.Text('--- Run Code Result: ---', align='center')
            your_input_header = urwid.Text('Last executed input:')
            your_input = urwid.Text(self.result['last_testcase'])
            list_items = [
                result_header,
                blank, column_wrap,
                blank, your_input_header, your_input,
            ]
        else:
            list_items = [
                result_header,
                blank, column_wrap,
            ]
        self._append_stdout_if_non_empty(list_items)
        return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)
项目:GitChat    作者:shubhodeep9    | 项目源码 | 文件源码
def __init__(
            self, title, login,
            command_caption='Command: (Tab to switch focus to upper '
            'frame, where you can scroll text)\nType exit or quit '
            'to close', max_size=1000):
        self.header = urwid.Text(title)
        self.model = urwid.SimpleListWalker([])
        self.body = ListView(
            self.model, lambda: self._update_focus(False), max_size=max_size)
        self.input = Input(lambda: self._update_focus(True))
        foot = urwid.Pile([
            urwid.AttrMap(
                urwid.Text(command_caption),
                'reversed'),
            urwid.AttrMap(self.input, 'normal')])
        urwid.Frame.__init__(self,
                             urwid.AttrWrap(self.body, 'normal'),
                             urwid.AttrWrap(self.header, 'reversed'),
                             foot)
        self.set_focus_path(['footer', 1])
        self._focus = True
        urwid.connect_signal(self.input,
                             'line_entered',
                             self.on_line_entered)
        self._output_styles = [s[0] for s in self.PALLETE]
        self.eloop = None
        self.login = login
项目:mongoaudit    作者:Exploit-install    | 项目源码 | 文件源码
def __init__(self, result):
        self.result = result
        self.total = len(result)
        self.update_view('next_callback')

        walker = urwid.SimpleListWalker([urwid.Padding(self.top_columns, left=3, right=3),
                                         self.test_result])

        adapter = urwid.BoxAdapter(urwid.ListBox(walker), height=14)

        urwid.WidgetWrap.__init__(self, adapter)
项目:sshchan    作者:einchan    | 项目源码 | 文件源码
def show_help(self):
        """Create and return Frame object containing help docs."""
        # Flags are gr8 against bugs.
        self.help_flag = True

        help_header = ur.Text(("green", "SSHCHAN HELP"), "center")
        pg1 = ur.Text(
            [("bold", "sshchan "), "is a textboard environment designed \
to run on remote SSH servers with multiple anonymous users simultaneously \
browsing and posting."], "center")
        pg2 = ur.Text(("bold", "Keybindings:"))
        pg3 = ur.Text([("green", "TAB"),
                       (
                           None,
                           " - switch focus between main body and top bar")])
        pg4 = ur.Text(
            [("green", "H h"), (None, " - display this help dialog")])
        pg5 = ur.Text(
            [("green", "B b"), (None, " - view available boards")])
        pg6 = ur.Text(
            [("green", "ESC"),
             (
                 None,
                 " - go back one screen (exits on MOTD screen)")])

        back_btn = ur.AttrMap(
            ur.Button("Back", self.button_press, "back"), "red", "reverse")

        help_body = ur.Padding(ur.ListBox(ur.SimpleListWalker([
            self.div, help_header, self.div, pg1, self.div, pg2,
            pg3, pg4, pg5, pg6, self.div, back_btn])),
            "center", self.width, 0, self.margin, self.margin)

        return ur.AttrMap(ur.Frame(help_body, self.header, self.footer,
                                   "body"), "bg")
项目:Discurses    作者:topisani    | 项目源码 | 文件源码
def __init__(self, chat_widget):
        self.chat_widget = chat_widget
        self.list_walker = urwid.SimpleListWalker([])
        self.w_listbox = urwid.ListBox(self.list_walker)
        self.update_list()
        self.__super.__init__(urwid.Padding(self.w_listbox, left=2))
        keymaps.GLOBAL.add_command("redraw", self.update_list)

        def updlst(*args, **kwargs):
            self.update_list()
        self.chat_widget.discord.add_event_handler("on_member_join", updlst)
        self.chat_widget.discord.add_event_handler("on_member_remove", updlst)
        self.chat_widget.discord.add_event_handler("on_member_update", updlst)
项目:mongoaudit    作者:stampery    | 项目源码 | 文件源码
def __init__(self, result):
        self.result = result
        self.total = len(result)
        self.update_view('next_callback')

        walker = urwid.SimpleListWalker([urwid.Padding(self.top_columns, left=3, right=3),
                                         self.test_result])

        adapter = urwid.BoxAdapter(urwid.ListBox(walker), height=14)

        urwid.WidgetWrap.__init__(self, adapter)
项目:stig    作者:rndusr    | 项目源码 | 文件源码
def mk_test_subjects(self, *listbox_items):
        listbox = urwid.ListBox(
            urwid.SimpleListWalker(list(listbox_items))
        )
        return listbox
项目:stig    作者:rndusr    | 项目源码 | 文件源码
def clear(self):
        # We can't call super().clear() because it runs the more efficient
        # `self._listbox.body[:] = ()`
        # That doesn't work here because urwidtrees.TreeListWalker doesn't
        # support item assignment.
        self._listbox.body = urwid.SimpleListWalker([])
        self._listbox._invalidate()
        self._initialized = False
        self._table.clear()
        self._marked.clear()
项目:stig    作者:rndusr    | 项目源码 | 文件源码
def __init__(self, srvapi, keymap, columns=None, sort=None, title=None):
        self._srvapi = srvapi
        self._keymap = keymap

        if self.focusable_items:
            self._ListItemClass = keymap.wrap(self.ListItemClass, context=self.keymap_context)
        else:
            self._ListItemClass = self.ListItemClass

        self._items = ()
        self._marked = set()

        self._columns = columns or []
        self._sort = sort
        self._sort_orig = sort

        self._title_name = title
        self.title_updater = None

        self._table = Table(**self.tuicolumns)
        self._table.columns = self._columns

        if self.focusable_items:
            walker = urwid.SimpleFocusListWalker([])
        else:
            walker = urwid.SimpleListWalker([])
        self._listbox = keymap.wrap(urwid.ListBox, context=self.keymap_context + 'list')(walker)

        listbox_sb = urwid.AttrMap(
            ScrollBar(urwid.AttrMap(self._listbox, self.palette_name)),
            'scrollbar'
        )
        pile = urwid.Pile([
            ('pack', urwid.AttrMap(self._table.headers, self.palette_name + '.header')),
            listbox_sb
        ])
        super().__init__(pile)
项目:terminal-leetcode    作者:chishui    | 项目源码 | 文件源码
def make_success_view(self):
        blank = urwid.Divider()
        status_header = urwid.AttrWrap(urwid.Text('Run Code Status: '), 'body')
        status = urwid.AttrWrap(urwid.Text('Accepted'), 'accepted')
        columns = urwid.Columns([(20, status_header), (20, status)])
        runtime = urwid.Text('Run time: %s' % self.result['status_runtime'])
        result_header = urwid.Text('--- Run Code Result: ---', align='center')
        list_items = [
                result_header,
                blank, columns,
                blank, runtime
        ]
        self._append_stdout_if_non_empty(list_items)
        return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)
项目:stellarmagnate    作者:abadger    | 项目源码 | 文件源码
def __init__(self, pubpen):
        self.pubpen = pubpen
        self._location = None
        self._free_space = 0
        self._filled_space = 0
        self._warehouse_free = 0
        self._warehouse_used = 0
        self._cash = 0
        self._bank = 0
        self._loan = 0

        self._warehouse_sub_id = None
        #self._bank_sub_id = None
        ### FIXME: Implement bank, warehouse, bank, and loan
        header2 = urwid.Text('Ship Type:')
        self.ship_type_widget = urwid.Text('  ')
        header3 = urwid.Text('Free space:')
        self.free_space_widget = urwid.Text('  ')
        header4 = urwid.Text('Cargo:')
        self.filled_space_widget = urwid.Text('  ')
        header5 = urwid.Text('Warehouse:')
        self.warehouse_free_widget = urwid.Text('  ')
        header6 = urwid.Text('Transshipment:')
        self.warehouse_used_widget = urwid.Text('  ')
        header7 = urwid.Text('Cash:')
        self.cash_widget = urwid.Text('  ')
        header8 = urwid.Text('Bank:')
        self.bank_widget = urwid.Text('  ')
        header9 = urwid.Text('Loan:')
        self.loan_widget = urwid.Text('  ')
        info_list = urwid.SimpleListWalker([header2, self.ship_type_widget,
                                            header3, self.free_space_widget,
                                            header4, self.filled_space_widget,
                                            header5, self.warehouse_free_widget,
                                            header6, self.warehouse_used_widget,
                                            header7, self.cash_widget,
                                            header8, self.bank_widget,
                                            header9, self.loan_widget])
        info = urwid.ListBox(info_list)
        box = LineBox(info, tlcorner='?', trcorner='?', lline=' ', rline=None, bline=None)
        super().__init__(box)

        # Primary triggers: These are events that tell us we need to refresh
        # our information
        self.pubpen.subscribe('ship.moved', self.handle_new_location)
        self.pubpen.subscribe('ship.cargo.update', self.handle_cargo_update)
        self.pubpen.subscribe('ship.equip.update', self.handle_ship_update)
        self.pubpen.subscribe('user.cash.update', self.handle_cash_update)
        #self.pubpen.subscribe('user.bank.update')
        #self.pubpen.subscribe('user.loan.update')

        # Secondary triggers: These are responses to requests for information
        self.pubpen.subscribe('ship.info', self.handle_ship_info)
        self.pubpen.subscribe('user.info', self.handle_user_info)

        # Defer populating the initial values until a user has logged in
        self.pubpen.subscribe('user.login_success', self.populate_info)
项目:my_ros_tools    作者:groundmelon    | 项目源码 | 文件源码
def __init__(self, output_prefix=None):
        self.exit_message = None

        self.output_prefix = output_prefix

        text_header = (u"Command Generation for 'rosbag record' ")
        buttons = OrderedDict()
        buttons['quit'] = urwid.Button(u"Quit(ESC/q)", self.on_quit)
        buttons['save'] = dialog.PopUpButton(u"Save(F2)",
                                             self.on_save,
                                             prompt_text=u"Input file name:",
                                             default_text=u"record.sh")
        buttons['mark'] = urwid.Button(u"Mark all(F3)", self.on_mark_all)
        buttons['unmark'] = urwid.Button(u"Unmark all(F4)", self.on_unmark_all)
        buttons['refresh'] = urwid.Button(u"Refresh(F5)", self.on_refresh)
        self.buttons = buttons

        # blank = urwid.Divider()

        header = urwid.AttrWrap(urwid.Text(text_header, align='center'), 'header')

        button_bar = urwid.GridFlow(
            [urwid.AttrWrap(btn, 'buttn', 'buttnf')
             for (key, btn) in buttons.iteritems()], 18, 3, 1, 'left')
        status_bar = urwid.AttrWrap(urwid.Text(u""), 'footer')
        footer = urwid.Pile([button_bar, status_bar])

        self.listwalker = urwid.SimpleListWalker(self.create_listbox_from_ros())
        listbox = urwid.ListBox(self.listwalker)
        body = urwid.AttrWrap(listbox, 'body')

        self.frame = urwid.Frame(body=body, header=header, footer=footer)

        self.frame_focus_table = dict()
        self.frame_focus_table[body] = 'footer'
        self.frame_focus_table[footer] = 'body'

        palette = [
            ('body', 'white', 'black', 'standout'),
            ('reverse', 'light gray', 'black'),
            ('header', 'white', 'dark blue', 'bold'),
            ('footer', 'black', 'light gray'),
            ('important', 'dark blue', 'light gray', ('standout', 'underline')),
            ('editfc', 'white', 'dark blue', 'bold'),
            ('editbx', 'light gray', 'dark blue'),
            ('editcp', 'black', 'light gray', 'standout'),
            ('bright', 'dark gray', 'light gray', ('bold', 'standout')),
            ('buttn', 'black', 'light cyan'),
            ('buttnf', 'white', 'dark blue', 'bold'),
            ('popbg', 'white', 'dark gray'),
        ]

        self.show_msg = status_bar.set_text

        screen = urwid.raw_display.Screen()

        self.mainloop = urwid.MainLoop(self.frame, palette, screen,
                                       unhandled_input=self.unhandled, pop_ups=True)

    # UI functions
项目: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)
项目:selecta    作者:vindolin    | 项目源码 | 文件源码
def __init__(self, revert_order, remove_bash_prefix, remove_zsh_prefix, regexp, case_sensitive,
                 remove_duplicates, show_hits, infile):

        self.show_hits = show_hits
        self.regexp_modifier = regexp
        self.case_modifier = case_sensitive
        self.remove_bash_prefix = remove_bash_prefix

        self.list_items = []

        if revert_order:
            lines = reversed(infile.readlines())
        else:
            lines = infile

        for line in lines:
            if remove_bash_prefix:
                line = line.split(None, 1)[1].strip()

            if remove_zsh_prefix:
                line = re.split('\s+', line, maxsplit=4)[-1]

            if 'selecta <(history)' not in line:
                if not remove_duplicates or line not in self.list_items:
                    self.list_items.append(line)

        self.list_item_widgets = []

        self.line_count_display = LineCountWidget('')
        self.search_edit = SearchEdit(edit_text='')

        self.modifier_display = urwid.Text('')

        urwid.connect_signal(self.search_edit, 'done', self.edit_done)
        urwid.connect_signal(self.search_edit, 'toggle_case_modifier', self.toggle_case_modifier)
        urwid.connect_signal(self.search_edit, 'toggle_regexp_modifier', self.toggle_regexp_modifier)
        urwid.connect_signal(self.search_edit, 'change', self.edit_change)

        header = urwid.AttrMap(urwid.Columns([
            urwid.AttrMap(self.search_edit, 'input', 'input'),
            self.modifier_display,
            ('pack', self.line_count_display),
        ], dividechars=1, focus_column=0), 'head', 'head')

        self.item_list = urwid.SimpleListWalker(self.list_item_widgets)
        self.listbox = ResultList(self.item_list)

        urwid.connect_signal(self.listbox, 'resize', self.list_resize)

        self.view = urwid.Frame(body=self.listbox, header=header)

        self.loop = urwid.MainLoop(self.view, palette, unhandled_input=self.on_unhandled_input)
        self.loop.screen.set_terminal_properties(colors=256)

        self.line_count_display.update(self.listbox.last_size, len(self.item_list))

        # TODO workaround, when update_list is called directly, the linecount widget gets not updated
        self.loop.set_alarm_in(0.01, lambda *loop: self.update_list(''))

        self.loop.run()