python类ListBox()的实例源码

socli.py 文件源码 项目:socli 作者: gautamkrishnar 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self, content):
        """
        :param content: text string to be displayed
        """
        lines = [UnicodeText(line) for line in content]
        body = urwid.SimpleFocusListWalker(lines)
        urwid.ListBox.__init__(self, body)
message_list.py 文件源码 项目:Discurses 作者: topisani 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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)
urwidpatches_test.py 文件源码 项目:stig 作者: rndusr 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def mk_test_subjects(self, *listbox_items):
        listbox = urwid.ListBox(
            urwid.SimpleListWalker(list(listbox_items))
        )
        return listbox
keymap_test.py 文件源码 项目:stig 作者: rndusr 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_hardcoded_keys_keep_working(self):
        list_contents = [urwid.Text(str(i)) for i in range(1, 10)]
        widget = self.mk_widget(urwid.ListBox, urwid.SimpleFocusListWalker(list_contents),
                                context='list')
        size = (3, 3)
        self.assert_lines(widget, size, exp_lines=('1  ', '2  ', '3  '))
        widget.keypress(size, 'down')
        self.assert_lines(widget, size, exp_lines=('2  ', '3  ', '4  '))
        widget.keypress(size, 'page down')
        self.assert_lines(widget, size, exp_lines=('5  ', '6  ', '7  '))
        widget.keypress(size, 'up')
        self.assert_lines(widget, size, exp_lines=('4  ', '5  ', '6  '))
        widget.keypress(size, 'page up')
        self.assert_lines(widget, size, exp_lines=('1  ', '2  ', '3  '))
keymap_test.py 文件源码 项目:stig 作者: rndusr 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_non_hardcoded_keys_are_evaluated(self):
        list_contents = [urwid.Text(str(i)) for i in range(1, 10)]
        widget = self.mk_widget(urwid.ListBox, urwid.SimpleFocusListWalker(list_contents),
                                context='list')
        action = FakeAction()
        self.keymap.bind('a', context='list', action=action)
        size = (3, 3)
        self.assert_lines(widget, size, exp_lines=('1  ', '2  ', '3  '))
        widget.keypress(size, 'a')
        self.assert_lines(widget, size, exp_lines=('1  ', '2  ', '3  '))
        self.assertEqual(action.callnum, 1)
        self.assertEqual(action.args, (widget,))
keymap_test.py 文件源码 项目:stig 作者: rndusr 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_evaluated_keys_are_offered_to_parent_again(self):
        list_contents = [urwid.Text(str(i)) for i in range(1, 10)]
        action = FakeAction()
        widget = self.mk_widget(urwid.ListBox, urwid.SimpleFocusListWalker(list_contents),
                                context='list', callback=action)
        self.keymap.bind('j', context='list', action=Key('down'))
        size = (3, 3)
        self.assert_lines(widget, size, exp_lines=('1  ', '2  ', '3  '))
        widget.keypress(size, 'j')
        self.assertEqual(action.callnum, 0)
        self.assert_lines(widget, size, exp_lines=('2  ', '3  ', '4  '))
keymap_test.py 文件源码 项目:stig 作者: rndusr 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_key_translation_to_builtin_key(self):
        class SelectableText(urwid.Text):
            def selectable(self): return True
            def keypress(self, size, key): return key
        list_contents = [SelectableText(str(i)) for i in range(1, 10)]
        listw = self.km.wrap(urwid.ListBox, context='list')(urwid.SimpleFocusListWalker(list_contents))
        self.km.bind(key='j', action=Key('down'))
        self.assertEqual(listw.focus_position, 0)
        listw.keypress((3, 3), 'j')
        self.assertEqual(listw.focus_position, 1)
_handle_urwidpatches.py 文件源码 项目:stig 作者: rndusr 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def setUpModule():
    # Monkey-patch stuff in the urwid module in-place
    if 'stig.tui.urwidpatches' not in sys.modules:
        import stig.tui.urwidpatches
    else:
        import stig.tui.urwidpatches
        importlib.reload(stig.tui.urwidpatches)
    import urwid
    assert hasattr(urwid.ListBox, 'get_scrollpos')
    assert ' ' not in urwid.command_map._command
_handle_urwidpatches.py 文件源码 项目:stig 作者: rndusr 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def tearDownModule(self):
    # Remove monkey patches
    import urwid
    urwid.command_map.restore_defaults()
    importlib.reload(urwid)
    assert not hasattr(urwid.ListBox, 'get_scrollpos')
    assert ' ' in urwid.command_map._command
__init__.py 文件源码 项目:stig 作者: rndusr 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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)
view.py 文件源码 项目:douban-movie 作者: chishui 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, movies):
        footer=urwid.AttrWrap(urwid.Text('Press q to exit, use up and down arrow to navigate, press Enter to select'), 'footer')
        items = self.make_items(movies)
        self.listbox = urwid.ListBox(urwid.SimpleListWalker(items))
        top = urwid.Overlay(self.listbox, urwid.SolidFill(' '),
            align='center', width=('relative', 60),
            valign='middle', height=('relative', 60),
            min_width=20, min_height=9)
        urwid.Frame.__init__(self, urwid.AttrWrap(top, 'body'), footer=footer)
UI.py 文件源码 项目:Drogo 作者: csrgxtu 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, model, got_focus, max_size=None):
        urwid.ListBox.__init__(self,model)
        self._got_focus=got_focus
        self.max_size=max_size
        self._lock=threading.Lock()
UI.py 文件源码 项目:Drogo 作者: csrgxtu 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, model, got_focus, max_size=None):
        urwid.ListBox.__init__(self,model)
        self._got_focus=got_focus
        self.max_size=max_size
        self._lock=threading.Lock()
WrappingPopUpViewer.py 文件源码 项目:memsql-top 作者: memsql 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self, message):
        listbox = urwid.ListBox(urwid.SimpleListWalker([
            urwid.Text(line) for line in message.split("\n")
        ]))
        footer = urwid.Pile([
            urwid.Divider(),
            urwid.Text("<close>")
        ])
        self.box = urwid.LineBox(urwid.Frame(listbox, footer=footer))
        super(PopUpDialog, self).__init__(urwid.AttrMap(self.box, 'popup'))
main.py 文件源码 项目:bbj 作者: desvox 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def quote_view_menu(self, button, post_ids):
        """
        Receives a list of quote ids and makes a frilly menu to pick one to view.
        It retrieves messages objects from the thread and attaches them to a
        callback to `quote_view_action`
        """
        buttons = []
        for pid in post_ids:
            try:
                message = self.thread["messages"][pid]
                if len(post_ids) == 1:
                    return self.quote_view_action(button, message)
                author = self.usermap[message["author"]]
                label = [
                    ("button", ">>%d " % pid),
                    "(",
                    (str(author["color"]),
                     author["user_name"]),
                    ")"
                ]
                buttons.append(cute_button(label, self.quote_view_action, message))
            except IndexError:
                continue # users can submit >>29384234 garbage references

        widget = OptionsMenu(
            urwid.ListBox(urwid.SimpleFocusListWalker(buttons)),
            title="View a Quote", **frame_theme()
        )

        self.loop.widget = urwid.Overlay(
            widget, self.loop.widget,
            align=("relative", 50),
            valign=("relative", 50),
            height=len(buttons) + 3,
            width=30
        )
main.py 文件源码 项目:bbj 作者: desvox 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def deletion_dialog(self, button, message):
        """
        Prompts the user to confirm deletion of an item.
        This can delete either a thread or a post.
        """
        op = message["post_id"] == 0
        buttons = [
            urwid.Text(("bold", "Delete this %s?" % ("whole thread" if op else "post"))),
            urwid.Divider(),
            cute_button(("10" , ">> Yes"), lambda _: [
                network.message_delete(message["thread_id"], message["post_id"]),
                self.remove_overlays(),
                self.index() if op else self.refresh()
            ]),
            cute_button(("30", "<< No"), self.remove_overlays)
        ]

        # TODO: create a central routine for creating popups. this is getting really ridiculous
        popup = OptionsMenu(
            urwid.ListBox(urwid.SimpleFocusListWalker(buttons)),
            **frame_theme())

        self.loop.widget = urwid.Overlay(
            popup, self.loop.widget,
            align=("relative", 50),
            valign=("relative", 50),
            width=30, height=6)
main.py 文件源码 项目:bbj 作者: desvox 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def back(self, terminate=False):
        if app.mode == "index" and terminate:
            frilly_exit()

        elif self.overlay_p():
            self.loop.widget = self.loop.widget[0]

        elif self.window_split:
            # display a confirmation dialog before killing off an in-progress post
            buttons = [
                urwid.Text(("bold", "Discard current post?")),
                urwid.Divider(),
                cute_button(("10" , ">> Yes"), lambda _: [
                    self.remove_overlays(),
                    self.index()
                ]),
                cute_button(("30", "<< No"), self.remove_overlays)
            ]

            # TODO: create a central routine for creating popups. this is getting really ridiculous
            popup = OptionsMenu(
                urwid.ListBox(urwid.SimpleFocusListWalker(buttons)),
                **frame_theme())

            self.loop.widget = urwid.Overlay(
                popup, self.loop.widget,
                align=("relative", 50),
                valign=("relative", 25),
                width=30, height=6)

        else:
            mark()
            self.index()
main.py 文件源码 项目:bbj 作者: desvox 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def general_help(self):
        """
        Show a general help dialog. In all honestly, its not
        very useful and will only help people who have never
        really used terminal software before =)
        """
        widget = OptionsMenu(
            urwid.ListBox(
                urwid.SimpleFocusListWalker([
                    urwid_rainbows(
                        "This is BBJ, a client/server textboard made for tilde.town!",
                        True),
                    urwid.Text(("dim", "...by ~desvox")),
                    urwid.Divider("-"),
                    urwid.Button("Post Formatting Help", self.formatting_help),
                    urwid.Divider("-"),
                    urwid.Text(general_help)
                ])),
            title="?????",
            **frame_theme()
        )

        app.loop.widget = urwid.Overlay(
            widget, app.loop.widget,
            align=("relative", 50),
            valign=("relative", 50),
            width=30,
            height=("relative", 60)
        )
commander.py 文件源码 项目:PyAlertMe 作者: jamesleesaunders 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, model, got_focus, max_size=None):
        urwid.ListBox.__init__(self, model)
        self._got_focus = got_focus
        self.max_size = max_size
        self._lock = threading.Lock()
adventure.py 文件源码 项目:Adwear 作者: Uberi 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self):
        self.log = urwid.SimpleFocusListWalker([])
        self.top = urwid.ListBox(self.log)
        self.inventory = set()
        self.update_place(map_top)


问题


面经


文章

微信
公众号

扫码关注公众号