Python urwid.SimpleFocusListWalker() Examples

The following are 30 code examples of urwid.SimpleFocusListWalker(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module urwid , or try the search function .
Example #1
Source File: main.py    From bbj with MIT License 6 votes vote down vote up
def quote_view_action(self, button, message):
        """
        Callback function to view a quote from the message object menu.
        """
        widget = OptionsMenu(
            ActionBox(urwid.SimpleFocusListWalker(self.make_message_body(message))),
            **self.frame_theme(">>%d" % message["post_id"])
        )

        self.loop.widget = urwid.Overlay(
            widget, self.loop.widget,
            align=("relative", 50),
            valign=("relative", 50),
            width=("relative", 98),
            height=("relative", 60)
        ) 
Example #2
Source File: __main__.py    From hangups with MIT License 6 votes vote down vote up
def __init__(self, coroutine_queue, conversation, on_cancel, on_save,
                 keybindings):
        self._coroutine_queue = coroutine_queue
        self._conversation = conversation
        edit = urwid.Edit(edit_text=get_conv_name(conversation))
        items = [
            urwid.Text('Rename conversation:'),
            edit,
            urwid.Button(
                'Save',
                on_press=lambda _: self._rename(edit.edit_text, on_save)
            ),
            urwid.Button('Cancel', on_press=lambda _: on_cancel()),
        ]
        list_walker = urwid.SimpleFocusListWalker(items)
        list_box = ListBox(keybindings, list_walker)
        super().__init__(list_box) 
Example #3
Source File: ui.py    From yTermPlayer with GNU General Public License v3.0 6 votes vote down vote up
def start_screen(self):
        #Ovrlay top screen at start
        txt1_1=urwid.Button("New playlist [Enter URL]")
        urwid.connect_signal(txt1_1, 'click', self.input_screen)
        txt1 = urwid.AttrMap(txt1_1,None,focus_map='reversed')
        txt2_2=urwid.Button("Load saved playlist")
        urwid.connect_signal(txt2_2, 'click', self.load_list_screen)
        txt2 = urwid.AttrMap(txt2_2,None,focus_map='reversed')
        start_list=urwid.SimpleFocusListWalker([txt1,txt2])
        box=urwid.ListBox(start_list)
        selection=urwid.LineBox(
                                box, title='', title_align='center',
                                tlcorner='┌', tline='─', lline='│',
                                trcorner='┐', blcorner='└', rline='│',
                                bline='─', brcorner='┘'
                                )
        selection_with_padding=urwid.Padding(selection,left=2,right=2)
        return selection_with_padding 
Example #4
Source File: keymap_test.py    From stig with GNU General Public License v3.0 6 votes vote down vote up
def test_evaluated_key_does_not_replace_original_key(self):
        # Create a list of widgets that translate 'j' to 'down' in their
        # keypress() methods.
        lst_contents = [self.mk_widget(urwid.Text, str(i), context='item')
                        for i in range(1, 10)]
        self.keymap.bind('j', context='item', action=Key('down'))

        # Create ListBox with separate key context.  If the ListBox gets to
        # handle 'j', it just checks a mark we can look for.
        lst_widget = self.mk_widget(urwid.ListBox, urwid.SimpleFocusListWalker(lst_contents), context='list')
        lst_got_j = FakeAction()
        self.keymap.bind('j', context='list', action=lst_got_j)

        # Make sure everything works regularly
        size = (3, 3)
        self.assert_lines(lst_widget, size, exp_lines=('1  ', '2  ', '3  '), exp_focus_pos=0)
        lst_widget.keypress(size, 'down')
        self.assert_lines(lst_widget, size, exp_lines=('1  ', '2  ', '3  '), exp_focus_pos=1)

        # Do the actual test: Pressing 'j' should pass 'j' to the focused item,
        # which evaluates it to 'down'.  But the list widget must get 'j'.
        lst_widget.keypress(size, 'j')
        self.assert_lines(lst_widget, size, exp_lines=('1  ', '2  ', '3  '), exp_focus_pos=1)
        self.assertEqual(lst_got_j.callnum, 1) 
Example #5
Source File: ui.py    From yTermPlayer with GNU General Public License v3.0 6 votes vote down vote up
def load_list_screen(self,button):
        #overlay second screen after start case2
        txt=urwid.Text("Choose from the following:- ")
        _list=self.player_object.get_saved_lists()
        saved_list=[]
        for every_list in _list:
            b=urwid.Button(str(every_list).rstrip(),user_data=None)
            urwid.connect_signal(b, 'click', self.list_load)
            saved_list.append(urwid.AttrMap(b,None,focus_map='reversed'))
        box=urwid.ListBox(urwid.SimpleFocusListWalker(saved_list))
        list_box=urwid.LineBox(
                                box, title='', title_align='center',
                                tlcorner='┌', tline='─', lline='│',
                                trcorner='┐', blcorner='└', rline='│',
                                bline='─', brcorner='┘'
                                )
        list_box_padding=urwid.Padding(list_box,right=0,left=0)
        self.top.original_widget=list_box_padding 
Example #6
Source File: main.py    From bbj with MIT License 6 votes vote down vote up
def formatting_help(self, *_):
        """
        Pops a help window for formatting directives.
        """
        # we can "recycle" the server's formatting abilities to
        # use the same syntax for the help text itself
        message = network.fake_message(
            "\n\n".join(format_help), format="sequential")

        widget = OptionsMenu(
            urwid.ListBox(urwid.SimpleFocusListWalker(app.make_message_body(message, True))),
            **self.frame_theme("Formatting Help")
        )

        va = 5 if self.window_split else 50
        vh = 45 if self.window_split else 75
        app.loop.widget = urwid.Overlay(
            widget, app.loop.widget,
            align=("relative", 50),
            valign=("relative", va),
            width=self.prefs["max_text_width"],
            height=("relative", vh)
        ) 
Example #7
Source File: main.py    From bbj with MIT License 6 votes vote down vote up
def set_escape_key(self, button, args):
        mode = args[0]
        widget = OptionsMenu(
            urwid.ListBox(urwid.SimpleFocusListWalker([
                urwid.Text("Press Enter when done"),
                urwid.AttrMap(KeyPrompt(
                    self.prefs["edit_escapes"][mode],
                    self.save_escape_key,
                    [mode]
                ), "opt_prompt")])),
            **self.frame_theme("Set key for " + mode)
        )

        app.loop.widget = urwid.Overlay(
            urwid.AttrMap(widget, "30"),
            app.loop.widget,
            align=("relative", 50),
            valign=("relative", 50),
            width=25, height=5
        ) 
Example #8
Source File: main.py    From wikicurses with MIT License 6 votes vote down vote up
def __init__(self):
        def selectButton(radio_button, new_state, parameter):
            if new_state:
                closeOverlay()
                self._select(parameter)

        super().__init__(urwid.SimpleFocusListWalker([]))
        buttons = []
        for i, item in enumerate(self._items()):
            if isinstance(item, urwid.Widget):
                self.body.append(item)
                continue
            elif isinstance(item, tuple):
                name, selected, parameter = item
            else:
                parameter = name = item
                selected = False
            self.body.append(urwid.RadioButton(buttons, name, selected,
                                               selectButton, parameter))
            if selected:
                self.set_focus(i) 
Example #9
Source File: overlays.py    From toot with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, status):
        yes = SelectableText("Yes, send it to heck")
        no = SelectableText("No, I'll spare it for now")

        urwid.connect_signal(yes, "click", lambda *args: self._emit("delete"))
        urwid.connect_signal(no, "click", lambda *args: self._emit("close"))

        walker = urwid.SimpleFocusListWalker([
            urwid.AttrWrap(yes, "", "blue_selected"),
            urwid.AttrWrap(no, "", "blue_selected"),
        ])
        super().__init__(walker) 
Example #10
Source File: ui.py    From tuijam with MIT License 5 votes vote down vote up
def __init__(self, app):
        self.app = app
        self.walker = urwid.SimpleFocusListWalker([])
        self.search_history = []
        self.search_results = self.SearchResults([])
        self.line_box = None
        self.viewing_previous_songs = False
        self.no_limit = False

        super().__init__(self.walker)

        self.walker.append(urwid.Text(WELCOME, align="center")) 
Example #11
Source File: __main__.py    From hangups with MIT License 5 votes vote down vote up
def __init__(self, coroutine_queue, conversation, close_callback,
                 keybindings):
        rename_dialog = RenameConversationDialog(
            coroutine_queue, conversation,
            lambda: frame.contents.__setitem__('body', (list_box, None)),
            close_callback, keybindings
        )
        items = [
            urwid.Text(
                'Conversation name: {}'.format(get_conv_name(conversation))
            ),
            urwid.Button(
                'Change Conversation Name',
                on_press=lambda _: frame.contents.__setitem__(
                    'body', (rename_dialog, None)
                )
            ),
            urwid.Divider('-'),
            urwid.Button('Back', on_press=lambda _: close_callback()),
        ]
        list_walker = urwid.SimpleFocusListWalker(items)
        list_box = ListBox(keybindings, list_walker)
        frame = urwid.Frame(list_box)
        padding = urwid.Padding(frame, left=1, right=1)
        line_box = urwid.LineBox(padding, title='Conversation Menu')
        super().__init__(line_box) 
Example #12
Source File: overlays.py    From toot with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, user_timelines):
        self.hash_edit = EditBox(caption="Hashtag: ")

        actions = list(self.generate_actions(user_timelines))
        walker = urwid.SimpleFocusListWalker(actions)
        super().__init__(walker) 
Example #13
Source File: keymap_test.py    From stig with GNU General Public License v3.0 5 votes vote down vote up
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  ')) 
Example #14
Source File: overlays.py    From toot with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, ex):
        lines = traceback.format_exception(etype=type(ex), value=ex, tb=ex.__traceback__)
        walker = urwid.SimpleFocusListWalker([
            urwid.Text(line) for line in lines
        ])
        super().__init__(walker) 
Example #15
Source File: overlays.py    From toot with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, links):

        def widget(url, title):
            return Button(title or url, on_press=lambda btn: webbrowser.open(url))

        walker = urwid.SimpleFocusListWalker(
            [widget(url, title) for url, title in links]
        )
        super().__init__(walker) 
Example #16
Source File: overlays.py    From toot with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, status):
        source = json.dumps(status.data, indent=4)
        lines = source.splitlines()
        walker = urwid.SimpleFocusListWalker([
            urwid.Text(line) for line in lines
        ])
        super().__init__(walker) 
Example #17
Source File: cui.py    From hypermax with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self):
        self.content = []

        self.listWalker = urwid.SimpleFocusListWalker(self.content)
        self.listbox = urwid.ListBox(self.listWalker)


        super(ScrollableTextArea, self).__init__(self.listbox) 
Example #18
Source File: ui.py    From tuijam with MIT License 5 votes vote down vote up
def __init__(self, app):

        self.app = app
        self.walker = urwid.SimpleFocusListWalker([])
        self.queue = []
        super().__init__(self.walker) 
Example #19
Source File: leftBox.py    From TWchat with MIT License 5 votes vote down vote up
def __init__(self,userName,contact_click_fn,chat_click_fn,contactList,is_contact_list=False):
        self.contactList=contactList 
        self.chatList={}
        self.chat_name_dic={}
        self.owner=userName
        self.contact_click_fn = contact_click_fn
        self.chat_click_fn = chat_click_fn
        self.is_contact_list=is_contact_list
        self.body = urwid.SimpleFocusListWalker([])
        if self.is_contact_list:
            self.show_contact()
        else:
            self.show_chat()
        super(ChatListBox,self).__init__(self.body) 
Example #20
Source File: components.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, messages=(), event_loop=None):
        self.body = urwid.SimpleFocusListWalker(messages)
        super(ChatBoxMessages, self).__init__(self.body)
        self.auto_scroll = True
        self.last_keypress = (0, None, 0)
        self.event_loop = event_loop 
Example #21
Source File: keymap_test.py    From stig with GNU General Public License v3.0 5 votes vote down vote up
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,)) 
Example #22
Source File: keymap_test.py    From stig with GNU General Public License v3.0 5 votes vote down vote up
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  ')) 
Example #23
Source File: base.py    From stig with GNU General Public License v3.0 5 votes vote down vote up
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._data_dict = None
        self._marked = set()

        self._existing_widgets = set()
        self._hidden_widgets = set()

        self._sort = sort
        self._sort_orig = sort

        self._title_name = title
        self.title_updater = None

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

        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)),
            self.palette_name + '.scrollbar'
        )
        pile = urwid.Pile([
            ('pack', urwid.AttrMap(self._table.headers, self.palette_name + '.header')),
            listbox_sb
        ])
        super().__init__(pile) 
Example #24
Source File: ui.py    From tildemush with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, state, config):
        self.config = config
        self.game_walker = urwid.SimpleFocusListWalker([
            ColorText('{yellow}you have reconstituted into tildemush'),
            ColorText("")
            ])
        self.game_area = urwid.ListBox(self.game_walker)
        self.here_text = urwid.Pile(self.here_info(state))
        self.user_text = urwid.Pile(self.user_info(state))
        self.minimap_grid = urwid.Pile(self.generate_minimap(state))
        self.panel_layout = config.get("panel_layout",
                ["here", "minimap", "user"])

        self.body = urwid.Columns([self.game_area])
        if len(self.panel_layout) > 0:
            self.body.contents.append((urwid.Pile(
                self.generate_panel_display(self.panel_layout)),
                self.body.options()))
        self.banner = ColorText('====welcome 2 tildemush, u are jacked in====')
        self.prompt = GamePrompt()
        self.view = urwid.Frame(header=self.banner,
                body=self.body, footer=self.prompt)
        self.view.focus_position = 'footer'

        super().__init__(self.view,
                TabHeader("F1 MAIN", position='first',
                    selected=True), self.prompt) 
Example #25
Source File: ui.py    From tildemush with GNU General Public License v3.0 5 votes vote down vote up
def menu(title, choices):
    if type(title) is str:
        title = urwid.Text(title)
    body = [title, urwid.Divider()]
    body.extend(choices)
    return urwid.ListBox(urwid.SimpleFocusListWalker(body)) 
Example #26
Source File: complex_bar_graph.py    From s-tui with GNU General Public License v2.0 5 votes vote down vote up
def set_title(self, title):
        if not title:
            return
        title_text_w = urwid.Text(title, align="center")
        list_w = urwid.SimpleFocusListWalker([title_text_w])
        self.title.original_widget = urwid.ListBox(list_w) 
Example #27
Source File: complex_bar_graph.py    From s-tui with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self,
                 title,
                 sub_title_list,
                 y_label,
                 bar_graph_vector,
                 visible_graph_list):
        for bar_graph in bar_graph_vector:
            if not isinstance(bar_graph, ScalableBarGraph):
                raise Exception(
                    'graph vector items must be ScalableBarGraph')
        if not self.check_label(y_label):
            raise Exception(
                'Y label must be a valid label')

        self.visible_graph_list = visible_graph_list
        self.bar_graph_vector = []
        self.set_graph(bar_graph_vector)

        self.y_label_and_graphs = urwid.WidgetPlaceholder(urwid.Columns([]))
        self.y_label = []
        self.set_y_label(y_label)

        list_w = urwid.ListBox(urwid.SimpleFocusListWalker([]))
        self.title = urwid.WidgetPlaceholder(list_w)
        self.sub_title_list = sub_title_list
        self.set_title(title)

        super(LabeledBarGraphVector, self).__init__(urwid.Pile([]))
        self.set_visible_graphs(visible_graph_list) 
Example #28
Source File: set_snooze.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, items):
        self.body = urwid.SimpleFocusListWalker(items)
        super(SetSnoozeWidgetList, self).__init__(self.body) 
Example #29
Source File: components.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, profile, channels=(), dms=(), stars=(), title=''):
        self.profile = profile
        self.channels = channels
        self.stars = stars
        self.dms = dms
        self.groups = ()
        self.last_time_clicked = None

        # Subscribe to receive message from channels to select them
        for channel in self.channels:
            urwid.connect_signal(channel, 'go_to_channel', self.go_to_channel)
        header = TextDivider(title)
        footer = urwid.Divider('─')
        stack = [
            profile,
            TextDivider('Starred')
        ]
        stack.extend(stars)
        stack.append(TextDivider('Channels'))
        stack.extend(self.channels)
        stack.append(TextDivider('Direct Messages'))
        stack.extend(dms)

        self.walker = urwid.SimpleFocusListWalker(stack)
        self.listbox = urwid.ListBox(self.walker)
        super(SideBar, self).__init__(self.listbox, header=header, footer=footer) 
Example #30
Source File: quick_switcher.py    From sclack with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, items):
        self.body = urwid.SimpleFocusListWalker(items)
        super(QuickSwitcherList, self).__init__(self.body)