Python urwid.GridFlow() Examples

The following are 30 code examples of urwid.GridFlow(). 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: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def get_form_buttons(self, defaultdata=None, create=False):
        ok = urwid.Button("OK")
        urwid.connect_signal(ok, 'click', self._ok, defaultdata)
        ok = AM(ok, 'selectable', 'butfocus')
        cancel = urwid.Button("Cancel")
        urwid.connect_signal(cancel, 'click', self._cancel)
        cancel = AM(cancel, 'selectable', 'butfocus')
        l = [ok, cancel]
        if create:
            ok_edit = urwid.Button("OK and Edit")
            urwid.connect_signal(ok_edit, 'click', self._ok_and_edit, defaultdata)
            ok_edit = AM(ok_edit, 'selectable', 'butfocus')
            l = [ok, ok_edit, cancel]
        else:
            l = [ok, cancel]
        butgrid = urwid.GridFlow(l, 15, 3, 1, 'center')
        return urwid.Pile([urwid.Divider(), butgrid ], focus_item=1) 
Example #2
Source File: storyFrame.py    From TerminusBrowser with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def buildFrame(self, board):
        '''returns the board widget'''

        threadButtonList = []

        for title, l, s, c, t  in self.titles.items():
            if self.uFilter:
                if re.search(self.uFilter.lower(), title.lower()):
                    threadButton = urwid.Button(str(l), self.changeFrameThread)
                    threadInfo = urwid.Text(self.info_text.format(str(s),str(c)))
                    threadList = [threadButton, urwid.Divider('-'), urwid.Divider(), urwid.Text(title), urwid.Divider(), urwid.Divider('-'), threadInfo]
                    threadButtonList.append(urwid.LineBox(urwid.Pile(threadList)))
            else:
                threadButton = urwid.Button(str(l), self.changeFrameThread)
                threadInfo = urwid.Text(self.info_text.format(str(s),str(c)))
                threadList = [threadButton, urwid.Divider('-'), urwid.Divider(), urwid.Text(title), urwid.Divider(), urwid.Divider('-'), threadInfo]
                threadButtonList.append(urwid.LineBox(urwid.Pile(threadList)))

        self.parsedItems = len(threadButtonList)
        catalogueButtons = urwid.GridFlow(threadButtonList, 30, 2, 2, 'center')
        listbox = urwid.ListBox(urwid.SimpleListWalker([catalogueButtons]))

        self.uvm.itemCount = len(threadButtonList)
        return [listbox] 
Example #3
Source File: views.py    From zulip-terminal with Apache License 2.0 6 votes vote down vote up
def __init__(self, controller: Any, question: Any,
                 success_callback: Callable[[], bool]):
        self.controller = controller
        self.success_callback = success_callback
        yes = urwid.Button('Yes', self.exit_popup_yes)
        no = urwid.Button('No', self.exit_popup_no)
        yes._w = urwid.AttrMap(urwid.SelectableIcon(
            'Yes', 4), None, 'selected')
        no._w = urwid.AttrMap(urwid.SelectableIcon(
            'No', 4), None, 'selected')
        display_widget = urwid.GridFlow([yes, no], 3, 5, 1, 'center')
        wrapped_widget = urwid.WidgetWrap(display_widget)
        prompt = urwid.LineBox(
            urwid.ListBox(
                urwid.SimpleFocusListWalker(
                    [question, urwid.Divider(), wrapped_widget]
                )))
        urwid.Overlay.__init__(self, prompt, self.controller.view,
                               align="left", valign="top",
                               width=self.controller.view.LEFT_WIDTH + 1,
                               height=8) 
Example #4
Source File: indexFrame.py    From TerminusBrowser with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def buildFrame(self):
        boardButtons = []
        for subreddit in self.subredditList:
            subreddit = '/r/' + subreddit if not subreddit.startswith('/r/') else subreddit
            if self.uFilter:
                if self.uFilter.lower() in subreddit.lower():
                    boardButtons.append(urwid.LineBox(urwid.AttrWrap(urwid.Button(subreddit, self.changeFrameBoard), 'center')))
            else:
                boardButtons.append(urwid.LineBox(urwid.AttrWrap(urwid.Button(subreddit, self.changeFrameBoard), 'center')))

        self.parsedItems = len(boardButtons)
        width = len(max(self.subredditList, key=len))
        buttonGrid = urwid.GridFlow(boardButtons, width + 9, 2, 2, 'center') # add 9 to width to account for widget padding
        listbox_content = [buttonGrid]

        return urwid.ListBox(urwid.SimpleListWalker(listbox_content)) 
Example #5
Source File: chanBoardBuilder.py    From TerminusBrowser with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def buildFrame(self, board):
        '''returns the board widget'''

        threadButtonList = []

        for threadNumber, threadInfo in self.threadsDict.items():
            title = str(threadInfo[0]).replace('-', ' ')
            if self.uFilter:
                if re.search(self.uFilter.lower(), title.lower()):
                    threadButton = urwid.Button(str(threadNumber), self.changeFrameThread)
                    threadInfo = urwid.Text(self.info_text.format(str(threadInfo[1]),str(threadInfo[2])))
                    threadList = [threadButton, urwid.Divider('-'), urwid.Divider(), urwid.Text(title), urwid.Divider(), urwid.Divider('-'), threadInfo]
                    threadButtonList.append(urwid.LineBox(urwid.Pile(threadList)))
            else:
                threadButton = urwid.Button(str(threadNumber), self.changeFrameThread)
                threadInfo = urwid.Text(self.info_text.format(str(threadInfo[1]), str(threadInfo[2])))
                threadList = [threadButton, urwid.Divider('-'), urwid.Divider(), urwid.Text(title), urwid.Divider(), urwid.Divider('-'), threadInfo]
                threadButtonList.append(urwid.LineBox(urwid.Pile(threadList)))

        self.parsedItems = len(threadButtonList)
        catalogueButtons = urwid.GridFlow(threadButtonList, 30, 2, 2, 'center')
        listbox = urwid.ListBox(urwid.SimpleListWalker([catalogueButtons]))

        self.uvm.itemCount = len(threadButtonList)
        return urwid.Pile([listbox]) 
Example #6
Source File: footer.py    From redial with GNU General Public License v3.0 6 votes vote down vote up
def init_footer(listbox):
    connect_button = FooterButton(u"\u23ce", "Connect", "enter", lambda button: button.on_click(listbox.get_focus()))
    sshkey_button = FooterButton("F3", "Copy SSH Key", "f3", lambda button: button.on_click(listbox.get_focus()))
    mc_button = FooterButton("F5", "Browse", "f5", lambda button: button.on_click(listbox.get_focus()))
    add_folder_button = FooterButton("F6", "New Folder", "f6", lambda button: button.on_click(listbox.get_focus()))
    add_button = FooterButton("F7", "New Conn.", "f7", lambda button: button.on_click(listbox.get_focus()))
    delete_button = FooterButton("F8", "Remove", "f8", lambda button: button.on_click(listbox.get_focus()))
    edit_button = FooterButton("F9", "Edit", "f9", lambda button: button.on_click(listbox.get_focus()))
    quit_button = FooterButton("Q", "Quit", "q", lambda button: button.on_click(listbox.get_focus()))
    # TODO keys that dont depend on selected node should be handled differently

    return urwid.GridFlow([connect_button,
                           sshkey_button,
                           mc_button,
                           # TODO join add buttons to one
                           add_folder_button,
                           add_button,
                           delete_button,
                           edit_button,
                           quit_button], 18, 1, 0, 'center') 
Example #7
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        menulist = []
        # big title
        bt = urwid.BigText("Storage Editor", urwid.HalfBlock5x4Font())
        bt = urwid.Padding(bt, "center", None)
        # primary tables for editing
        self.primlist = [TableItemWidget(s) for s in self._PRIMARY_TABLES]
        for b in self.primlist:
            urwid.connect_signal(b, 'activate', self._select)
        pmenu = urwid.GridFlow(self.primlist, 20, 2, 1, "left")
        # heading blurbs
        subhead = urwid.AttrMap(urwid.Text("Select an object type to view or edit."), "subhead")
        supportsubhead = urwid.AttrMap(urwid.Text("Select a supporting object to view or edit."), "subhead")
        # secondary/support tables
        self.seclist = [TableItemWidget(s) for s in self._SUPPORT_TABLES]
        for b in self.seclist:
            urwid.connect_signal(b, 'activate', self._select)
        smenu = urwid.GridFlow(self.seclist, 25, 1, 0, "left")
        divider = urwid.Divider("-", top=1, bottom=1)
        menulist = [bt, divider, subhead, pmenu, divider, supportsubhead, smenu]
        listbox = urwid.ListBox(urwid.SimpleListWalker(menulist))
        return urwid.Frame(listbox) 
Example #8
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        # buttons
        done = urwid.Button("Done")
        urwid.connect_signal(done, 'click', self._done_multiselect)
        done = urwid.AttrWrap(done, 'selectable', 'butfocus')
        add = urwid.Button("Add New")
        urwid.connect_signal(add, 'click', self._add_new)
        add = urwid.AttrWrap(add, 'selectable', 'butfocus')
        cancel = urwid.Button("Cancel")
        urwid.connect_signal(cancel, 'click', self._cancel)
        cancel = urwid.AttrWrap(cancel, 'selectable', 'butfocus')
        # footer and header
        header = urwid.GridFlow([done, add, cancel], 15, 3, 1, 'center')
        footer = urwid.Padding(urwid.Text(
            ("popup", "Tab to button box to select buttons. Arrow keys transfer selection.")))
        body = self._build_body()
        return urwid.Frame(body, header=header, footer=footer, focus_part="body") 
Example #9
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        showeq = urwid.Text(self._testequipment.equipment.name)
        maxlen = 0
        uutcb = urwid.CheckBox("DUT/UUT", state=self._testequipment.UUT)
        urwid.connect_signal(uutcb, 'change', self._uut_select)
        blist = [AM(uutcb, "important")]
        for role in self._roles:
            label = str(role)
            maxlen = max(len(label), maxlen)
            state = role in self._testequipment.roles
            but = urwid.CheckBox(str(role), state=state)
            urwid.connect_signal(but, 'change', self._multi_select, role)
            blist.append(but)
        roleboxes = urwid.Padding(urwid.GridFlow(blist, maxlen+4, 1, 0, "left"))
    #    # buttons
        ok, cancel = self.get_form_buttons()
        buts = urwid.Columns([(10, ok), (10, cancel)], dividechars=1, focus_column=0)
        div = urwid.Divider()
        return urwid.ListBox(urwid.SimpleListWalker([AM(showeq, "flagged"), div, roleboxes, div, buts])) 
Example #10
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        self._showeq = urwid.Text("")
        eqi = self._create_equipment_input()
        maxlen = 0
        uutcb = urwid.CheckBox("DUT/UUT", state=False)
        urwid.connect_signal(uutcb, 'change', self._uut_select)
        blist = [AM(uutcb, "important")]
        for role in self._roles:
            label = str(role)
            maxlen = max(len(label), maxlen)
            but = urwid.CheckBox(str(role), state=False)
            urwid.connect_signal(but, 'change', self._multi_select, role)
            blist.append(but)
        roleboxes = urwid.Padding(urwid.GridFlow(blist, maxlen+4, 1, 0, "left"))
        # buttons
        ok, cancel = self.get_form_buttons()
        buts = urwid.Columns([(10, ok), (10, cancel)], dividechars=1, focus_column=0)
        return urwid.ListBox(urwid.SimpleListWalker([eqi, AM(self._showeq, "flagged"), roleboxes, buts])) 
Example #11
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def __init__(self, model, metadata, value, legend=None):
        blist = []
        glist = []
        maxl = 0
        enumtype = getattr(types, metadata.coltype)
        if value is None:
            value = enumtype.get_default()
        for num, name in enumtype.get_choices():
            maxl = max(maxl, len(name))
            b = urwid.RadioButton(blist, name, False, user_data=num)
            b.value = num
            glist.append(AM(b, 'enumbuttn','buttnf'))
        # set the right value
        for b in blist:
            if b.value == value:
                b.state = True
        self.wid = urwid.GridFlow(glist, maxl+4, 1, 0, 'left')
        self.blist = blist
        self.__super.__init__(self._col_creator(metadata, self.wid, legend)) 
Example #12
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def __init__(self, model, metadata, value, legend=None):
        blist = []
        glist = []
        maxl = 0
        for num, name in types.ValueType.get_choices():
            maxl = max(maxl, len(name))
            b = urwid.RadioButton(blist, name, False, user_data=num)
            b.value = num
            glist.append(AM(b, 'enumbuttn','buttnf'))
        # set the right value
        for b in blist:
            if b.value == value:
                b.state = True
        self.wid = urwid.GridFlow(glist, maxl+4, 1, 0, 'left')
        self.blist = blist
        self.__super.__init__(self._col_creator(metadata, self.wid, legend)) 
Example #13
Source File: test_container.py    From anyMesh-Python with MIT License 6 votes vote down vote up
def test_focus_path(self):
        # big tree of containers
        t = urwid.Text(u'x')
        e = urwid.Edit(u'?')
        c = urwid.Columns([t, e, t, t])
        p = urwid.Pile([t, t, c, t])
        a = urwid.AttrMap(p, 'gets ignored')
        s = urwid.SolidFill(u'/')
        o = urwid.Overlay(e, s, 'center', 'pack', 'middle', 'pack')
        lb = urwid.ListBox(urwid.SimpleFocusListWalker([t, a, o, t]))
        lb.focus_position = 1
        g = urwid.GridFlow([t, t, t, t, e, t], 10, 0, 0, 'left')
        g.focus_position = 4
        f = urwid.Frame(lb, header=t, footer=g)

        self.assertEqual(f.get_focus_path(), ['body', 1, 2, 1])
        f.set_focus_path(['footer']) # same as f.focus_position = 'footer'
        self.assertEqual(f.get_focus_path(), ['footer', 4])
        f.set_focus_path(['body', 1, 2, 2])
        self.assertEqual(f.get_focus_path(), ['body', 1, 2, 2])
        self.assertRaises(IndexError, lambda: f.set_focus_path([0, 1, 2]))
        self.assertRaises(IndexError, lambda: f.set_focus_path(['body', 2, 2]))
        f.set_focus_path(['body', 2]) # focus the overlay
        self.assertEqual(f.get_focus_path(), ['body', 2, 1]) 
Example #14
Source File: dialog.py    From redial with GNU General Public License v3.0 5 votes vote down vote up
def show(self, loop):
        # Header
        header_text = urwid.Text('Select Public SSH Key to Copy', align='center')
        header = urwid.AttrMap(header_text, 'dialog')

        cancel_btn = urwid.Button('Cancel', self.on_cancel)
        cancel_btn = urwid.AttrWrap(cancel_btn, 'dialog_button', 'dialog_button_focus')

        footer = urwid.GridFlow([cancel_btn], 12, 1, 1, 'center')

        list_box = urwid.BoxAdapter(SSHListBox(on_enter=self.on_copy, body=self.ssh_keys_walker), 5)

        body = urwid.Filler(
            urwid.Pile([list_box, footer])
        )

        # Layout
        layout = urwid.Frame(
            body=body,
            header=header)

        layout = urwid.AttrWrap(layout, 'dialog')

        w = DialogOverlay(
            on_close=lambda: self.on_close(),
            on_enter=self.on_copy,
            top_w=urwid.AttrMap(urwid.LineBox(layout), "dialog"),
            bottom_w=loop.widget,
            align='center',
            width=40,
            valign='middle',
            height=10
        )

        loop.widget = w 
Example #15
Source File: base.py    From ceph-ansible-copilot with GNU Lesser General Public License v2.1 5 votes vote down vote up
def button_row(button_list, align='right'):

    buttons = []                            # list of tuples - label, callback
    for button in button_list:
        buttons.append(urwid.AttrMap(
                         MyButton(label=button[0], on_press=button[1]),
                       'buttn', 'buttnf'))

    return urwid.Padding(urwid.GridFlow(buttons, 12, 4, 0, align=align),
                         left=2, right=2) 
Example #16
Source File: base.py    From ceph-ansible-copilot with GNU Lesser General Public License v2.1 5 votes vote down vote up
def ui_button(label='Next', align='right', callback=None):
    btn_size = len(label) + 4
    return urwid.Padding(
             urwid.GridFlow([
               urwid.AttrMap(
                 MyButton(label=label, on_press=callback),
                 'buttn', 'buttnf')],
               btn_size, 4, 0, align=align),
             left=2, right=2) 
Example #17
Source File: chanThreadBuilder.py    From TerminusBrowser with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def buildThread(self):
        self.postWidgetDict = {}

        for p in self.comments:
            self.postReplyDict[str(p.userIden)] = []

            commentWidget = self.notBrainletCommentTagParser(p)

            if self.uFilter:
                if self.uFilter.lower() in p.content.lower():
                    self.postWidgetDict[p.userIden] = commentWidget
            else:
                self.postWidgetDict[p.userIden] = commentWidget

        postWidgetList = []
        for pNum, pWidget in self.postWidgetDict.items():
            if pNum in self.postReplyDict:
                buttonReplyList = [urwid.AttrWrap(QuoteButton(str(r), self.uvm), 'quote') for r in self.postReplyDict[pNum]]
                pWidget.append(urwid.Text('Replies: '))
                pWidget.append(urwid.GridFlow(buttonReplyList, len(str(pNum)) + 4, 0, 0, 'left'))
                # pWidget.append(urwid.Text('Replies: ' + str(self.postReplyDict[pNum])))
            postWidgetList.append(urwid.LineBox(urwid.Pile(pWidget)))

        self.parsedItems = len(self.comments)


        listbox_content = postWidgetList
        listbox = urwid.ListBox(urwid.SimpleListWalker(listbox_content))

        return listbox 
Example #18
Source File: test_container.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def test_cell_width(self):
        gf = urwid.GridFlow([], 5, 0, 0, 'left')
        self.assertEqual(gf.cell_width, 5) 
Example #19
Source File: test_container.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def test_basics(self):
        repr(urwid.GridFlow([], 5, 0, 0, 'left')) # should not fail 
Example #20
Source File: test_container.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def test_v_sep(self):
        gf = urwid.GridFlow([urwid.Text("test")], 10, 3, 1, "center")
        self.assertEqual(gf.rows((40,), False), 1) 
Example #21
Source File: test_container.py    From anyMesh-Python with MIT License 5 votes vote down vote up
def test_grid_flow(self):
        gf = urwid.GridFlow([], 5, 1, 0, 'left')
        self.assertEqual(gf.focus, None)
        self.assertEqual(gf.contents, [])
        self.assertRaises(IndexError, lambda: getattr(gf, 'focus_position'))
        self.assertRaises(IndexError, lambda: setattr(gf, 'focus_position',
            None))
        self.assertRaises(IndexError, lambda: setattr(gf, 'focus_position', 0))
        self.assertEqual(gf.options(), ('given', 5))
        self.assertEqual(gf.options(width_amount=9), ('given', 9))
        self.assertRaises(urwid.GridFlowError, lambda: gf.options(
            'pack', None))

        t1 = urwid.Text(u'one')
        t2 = urwid.Text(u'two')
        gf = urwid.GridFlow([t1, t2], 5, 1, 0, 'left')
        self.assertEqual(gf.focus, t1)
        self.assertEqual(gf.focus_position, 0)
        self.assertEqual(gf.contents, [(t1, ('given', 5)), (t2, ('given', 5))])
        gf.focus_position = 1
        self.assertEqual(gf.focus, t2)
        self.assertEqual(gf.focus_position, 1)
        gf.contents.insert(0, (t2, ('given', 5)))
        self.assertEqual(gf.focus_position, 2)
        self.assertRaises(urwid.GridFlowError, lambda: gf.contents.append(()))
        self.assertRaises(urwid.GridFlowError, lambda: gf.contents.insert(1,
            (t1, ('pack', None))))
        gf.focus_position = 0
        self.assertRaises(IndexError, lambda: setattr(gf, 'focus_position', -1))
        self.assertRaises(IndexError, lambda: setattr(gf, 'focus_position', 3))
        # old methods:
        gf.set_focus(0)
        self.assertRaises(IndexError, lambda: gf.set_focus(-1))
        self.assertRaises(IndexError, lambda: gf.set_focus(3))
        gf.set_focus(t1)
        self.assertEqual(gf.focus_position, 1)
        self.assertRaises(ValueError, lambda: gf.set_focus('nonexistant')) 
Example #22
Source File: subredditFrame.py    From TerminusBrowser with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def buildFrame(self, board):
        '''returns the board widget'''

        threadButtonList = []

        for title, threadInfo in self.titles.items():
            if title == 'Next':
                if not self.uFilter:
                    subButton = urwid.Button(str(threadInfo[0]), self.changeSubPage)
                    threadButtonList.append(urwid.LineBox(urwid.Pile([subButton, urwid.Divider('-'), urwid.Text(threadInfo[1])])))
                continue
            title = title.replace('-', ' ')
            if self.uFilter:
                if re.search(self.uFilter.lower(), title.lower()):
                    threadButton = urwid.Button(str(threadInfo[0]), self.changeFrameThread)
                    threadInfo = urwid.Text(self.info_text.format(str(threadInfo[1]),str(threadInfo[2])))
                    threadList = [threadButton, urwid.Divider('-'), urwid.Divider(), urwid.Text(title), urwid.Divider(), urwid.Divider('-'), threadInfo]
                    threadButtonList.append(urwid.LineBox(urwid.Pile(threadList)))
            else:
                threadButton = urwid.Button(str(threadInfo[0]), self.changeFrameThread)
                threadInfo = urwid.Text(self.info_text.format(str(threadInfo[1]), str(threadInfo[2])))
                threadList = [threadButton, urwid.Divider('-'), urwid.Divider(), urwid.Text(title), urwid.Divider(), urwid.Divider('-'), threadInfo]
                threadButtonList.append(urwid.LineBox(urwid.Pile(threadList)))

        self.parsedItems = len(threadButtonList)
        catalogueButtons = urwid.GridFlow(threadButtonList, 30, 2, 2, 'center')
        listbox = urwid.ListBox(urwid.SimpleListWalker([catalogueButtons]))

        self.uvm.itemCount = len(threadButtonList)
        return [listbox] 
Example #23
Source File: indexFrame.py    From TerminusBrowser with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def buildFrame(self):
        boardButtons = []
        for story in self.storyList:
            if self.uFilter:
                if self.uFilter.lower() in story.lower():
                    boardButtons.append(urwid.LineBox(urwid.AttrWrap(urwid.Button(story, self.changeFrameBoard), 'center')))
            else:
                boardButtons.append(urwid.LineBox(urwid.AttrWrap(urwid.Button(story, self.changeFrameBoard), 'center')))

        self.parsedItems = len(boardButtons)
        width = len(max(self.storyList, key=len))
        buttonGrid = urwid.GridFlow(boardButtons, width + 9, 2, 2, 'center') # add 9 to width to account for widget padding
        listbox_content = [buttonGrid]

        return urwid.ListBox(urwid.SimpleListWalker(listbox_content)) 
Example #24
Source File: indexFrame.py    From TerminusBrowser with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def buildFrame(self):
        boardButtons = []
        for story in self.storyList:
            if self.uFilter:
                if self.uFilter.lower() in story.lower():
                    boardButtons.append(urwid.LineBox(urwid.AttrWrap(urwid.Button(story, self.changeFrameBoard), 'center')))
            else:
                boardButtons.append(urwid.LineBox(urwid.AttrWrap(urwid.Button(story, self.changeFrameBoard), 'center')))

        self.parsedItems = len(boardButtons)
        width = len(max(self.storyList, key=len))
        buttonGrid = urwid.GridFlow(boardButtons, width + 9, 2, 2, 'center') # add 9 to width to account for widget padding
        listbox_content = [buttonGrid]

        return urwid.ListBox(urwid.SimpleListWalker(listbox_content)) 
Example #25
Source File: indexFrame.py    From TerminusBrowser with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def buildFrame(self):
        boardButtons = []
        for board in self.boardList:
            if self.uFilter:
                if self.uFilter.lower() in board.lower():
                    boardButtons.append(urwid.LineBox(urwid.AttrWrap(urwid.Button(board, self.changeFrameBoard), 'center')))
            else:
                boardButtons.append(urwid.LineBox(urwid.AttrWrap(urwid.Button(board, self.changeFrameBoard), 'center')))

        self.parsedItems = len(boardButtons)
        buttonGrid = urwid.GridFlow(boardButtons, 12, 2, 2, 'center')
        listbox_content = [buttonGrid]

        return urwid.ListBox(urwid.SimpleListWalker(listbox_content)) 
Example #26
Source File: indexFrame.py    From TerminusBrowser with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def buildFrame(self):
        boardButtons = []
        for board in self.boardList:
            if self.uFilter:
                if self.uFilter.lower() in board.lower():
                    boardButtons.append(urwid.LineBox(urwid.AttrWrap(urwid.Button(board, self.changeFrameBoard), 'center')))
            else:
                boardButtons.append(urwid.LineBox(urwid.AttrWrap(urwid.Button(board, self.changeFrameBoard), 'center')))

        self.parsedItems = len(boardButtons)
        buttonGrid = urwid.GridFlow(boardButtons, 12, 2, 2, 'center')
        listbox_content = [buttonGrid]

        return urwid.ListBox(urwid.SimpleListWalker(listbox_content)) 
Example #27
Source File: dialog.py    From redial with GNU General Public License v3.0 5 votes vote down vote up
def show(self, loop):
        # Header
        header_text = urwid.Text(self.title, align='center')
        header = urwid.AttrMap(header_text, 'dialog')

        # Footer
        ok_btn = urwid.Button('Ok', self.on_ok)
        ok_btn = urwid.AttrWrap(ok_btn, 'dialog_button', 'dialog_button_focus')

        footer = urwid.GridFlow([ok_btn], 12, 1, 1, 'center')

        body = urwid.Filler(
            urwid.Pile([
                urwid.Text(self.message),
                urwid.Text(""),
                footer
            ])
        )

        # Layout
        layout = urwid.Frame(
            body,
            header=header
        )

        w = DialogOverlay(
            on_close=self.on_close,
            on_enter=self.on_ok,
            top_w=urwid.AttrMap(urwid.LineBox(layout), "dialog"),
            bottom_w=loop.widget,
            align='center',
            width=40,
            valign='middle',
            height=10
        )

        loop.widget = w 
Example #28
Source File: dialog.py    From redial with GNU General Public License v3.0 5 votes vote down vote up
def show(self, loop):
        # Header
        header_text = urwid.Text('Edit Folder' if self.target.name else "Add Folder", align='center')
        header = urwid.AttrMap(header_text, 'dialog')

        # Footer
        save_btn = urwid.Button('Save', self.on_save)
        save_btn = urwid.AttrWrap(save_btn, 'dialog_button', 'dialog_button_focus')

        cancel_btn = urwid.Button('Cancel', self.on_cancel)
        cancel_btn = urwid.AttrWrap(cancel_btn, 'dialog_button', 'dialog_button_focus')

        footer = urwid.GridFlow([save_btn, cancel_btn], 12, 1, 1, 'center')

        body = urwid.Filler(
            urwid.Pile([self.folder_name, footer])
        )

        # Layout
        layout = urwid.Frame(
            body,
            header=header)

        w = DialogOverlay(
            on_close=lambda: self.on_close(self.target),
            on_enter=self.on_save,
            top_w=urwid.AttrMap(urwid.LineBox(layout), "dialog"),
            bottom_w=loop.widget,
            align='center',
            width=40,
            valign='middle',
            height=10
        )

        loop.widget = w 
Example #29
Source File: dialog.py    From redial with GNU General Public License v3.0 5 votes vote down vote up
def show(self, loop):
        # Header
        header_text = urwid.Text('Remove Connection: ' + self.target.name, align='center')
        header = urwid.AttrMap(header_text, 'dialog')

        # Footer
        ok_btn = urwid.Button('Ok', self.on_ok)
        ok_btn = urwid.AttrWrap(ok_btn, 'dialog_button', 'dialog_button_focus')

        cancel_btn = urwid.Button('Cancel', self.on_cancel)
        cancel_btn = urwid.AttrWrap(cancel_btn, 'dialog_button', 'dialog_button_focus')

        footer = urwid.GridFlow([ok_btn, cancel_btn], 12, 1, 1, 'center')

        body = urwid.Filler(
            urwid.Pile([
                urwid.Text("Are you sure?"),
                urwid.Text(""),
                footer
            ])
        )

        # Layout
        layout = urwid.Frame(
            body,
            header=header
        )

        w = DialogOverlay(
            on_close=lambda: self.on_close(self.target),
            on_enter=lambda: self.on_ok(None),
            top_w=urwid.AttrMap(urwid.LineBox(layout), "dialog"),
            bottom_w=loop.widget,
            align='center',
            width=40,
            valign='middle',
            height=10
        )

        loop.widget = w 
Example #30
Source File: details.py    From stig with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, tid, title=None):
        self._title = title
        self._torrent = {}

        sections = []
        self._sections = {}
        for section_cls in _sections:
            section = section_cls()
            sections.append(section)
            self._sections[section.title] = section

        def add_title(title, section):
            header = urwid.Columns([('pack', urwid.Text('──┤ %s ├' % title)),
                                    urwid.Divider('─')])
            return urwid.Pile([('pack', header), section])

        grid = urwid.GridFlow([], cell_width=1, h_sep=3, v_sep=1, align='left')
        for section in sections:
            opts = grid.options('given', section.width)
            section_wrapped = add_title(section.title, section)
            grid.contents.append((section_wrapped, opts))
        self._grid = grid
        self._content = Scrollable(grid)

        super().__init__(urwid.AttrMap(
            ScrollBar(urwid.AttrMap(self._content, 'torrentdetails')),
            'torrentdetails.scrollbar'
        ))

        # Register new request in request pool
        keys = set(('name',)).union(key for w in sections for key in w.needed_keys)
        self._poller = objects.srvapi.create_poller(objects.srvapi.torrent.torrents, (tid,), keys=keys)
        self._poller.on_response(self._handle_response)
        self._poller.on_error(self._handle_error)