Python urwid.ListBox() Examples

The following are 30 code examples of urwid.ListBox(). 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 build(self):
        header = urwid.Pile([
                urwid.AttrMap(urwid.Text("Edit {}".format(self.modelclass.__name__)), "formhead"),
                urwid.AttrMap(urwid.Text("Arrow keys navigate, "
                        "Enter to select form button. Tab to switch to header."
                        "Type into other fields."), "formhead"),
                AM(urwid.Button("Copy from...", on_press=self._create_copy_input), "selectable", "butfocus"),
                urwid.Divider(),
                ])
        formstack = []
        for colname in ("name", "owner"):
            colmd = self.metadata[colname]
            wid = self.build_input(colmd, getattr(self.row, colmd.colname))
            formstack.append(wid)
        colmd = self.metadata["attributes"]
        wid = self.build_attribute_input(colmd, getattr(self.row, colmd.colname))
        formstack.append(wid)
        # test equipment
        colmd = self.metadata["testequipment"]
        tewid = self.build_testequipment_input(colmd, getattr(self.row, "testequipment"))
        formstack.append(tewid)
        # common buttons
        formstack.append(self.get_form_buttons())
        listbox = urwid.ListBox(urwid.SimpleListWalker(formstack))
        return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header) 
Example #2
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 #3
Source File: TodoListWidget.py    From topydo with GNU General Public License v3.0 6 votes vote down vote up
def resolve_action(self, p_action_str, p_size=None):
        """
        Checks whether action specified in p_action_str is "built-in" or
        contains topydo command (i.e. starts with 'cmd') and forwards it to
        proper executing methods.

        p_size should be specified for some of the builtin actions like 'up' or
        'home' as they can interact with urwid.ListBox.keypress or
        urwid.ListBox.calculate_visible.
        """
        if p_action_str.startswith(('cmd ', 'cmdv ')):
            prefix, cmd = p_action_str.split(' ', 1)
            execute_signal = get_execute_signal(prefix)

            if '{}' in cmd:
                self._execute_on_selected(cmd, execute_signal)
            else:
                urwid.emit_signal(self, execute_signal, cmd)
        else:
            self.execute_builtin_action(p_action_str, p_size) 
Example #4
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 #5
Source File: main.py    From bbj with MIT License 6 votes vote down vote up
def search_prompt(self):
        if self.mode == "index":
            callback = self.search_index_callback
        elif self.mode == "thread":
            callback = self.search_thread_callback
        else:
            return

        popup = OptionsMenu(
            urwid.ListBox(
                urwid.SimpleFocusListWalker([
                    urwid.Text(("button", "Enter a query:")),
                    urwid.AttrMap(StringPrompt(callback), "opt_prompt"),
                    urwid.Text("Use a blank query to reset the {}.".format(self.mode))
                ])),
            **self.frame_theme())

        self.loop.widget = urwid.Overlay(
            popup, self.loop.widget,
            align=("relative", 50),
            valign=("relative", 25 if self.window_split else 50),
            width=("relative", 40), height=6) 
Example #6
Source File: gui.py    From certstream-python with MIT License 6 votes vote down vote up
def setup_widgets(self):
        self.intro_frame = urwid.LineBox(
            urwid.Filler(
                urwid.Text(('body_text', self.INTRO_MESSAGE.format("")), align=urwid.CENTER),
                valign=urwid.MIDDLE,
            )
        )

        self.frame = urwid.Frame(
            body=self.intro_frame,
            footer=urwid.Text(
                [self.FOOTER_START, ('heartbeat_inactive', self.HEARTBEAT_ICON)],
                align=urwid.CENTER
            )
        )

        self.loop = urwid.MainLoop(
            urwid.AttrMap(self.frame, 'body_text'),
            unhandled_input=show_or_exit,
            palette=PALETTE,
        )

        self.list_walker = urwid.SimpleListWalker(self.message_list)
        self.list_box = urwid.ListBox(self.list_walker)
        urwid.connect_signal(self.list_walker, "modified", self.item_focused) 
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: 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 #9
Source File: tabs_test.py    From stig with GNU General Public License v3.0 6 votes vote down vote up
def setUp(self):
        self.size = (80, 20)
        self.content = [
            urwid.ListBox(urwid.SimpleFocusListWalker([
                urwid.Edit('Field 1'),
                urwid.Edit('Field 2'),
            ])),

            urwid.ListBox(urwid.SimpleFocusListWalker([
                SelectableText('Row 1'),
                urwid.Edit('', 'Edit field 2'),
                SelectableText('Row 3'),
            ]))
        ]
        self.editbox = self.content[1].body[1]
        self.editbox.edit_pos = 0
        self.tabs = Tabs((urwid.Text('Edit fields'), self.content[0]),
                         (urwid.Text('empty'),),
                         (urwid.Text('Text rows'), self.content[1])) 
Example #10
Source File: spotify-restore.py    From spotify-playlists-2-deezer with MIT License 6 votes vote down vote up
def playlistitems(title):
	global listitems
	bt_sv = urwid.Button("Save")
	urwid.connect_signal(bt_sv, 'click', showmenu)
	bt_ca = urwid.Button("Cancel")
	urwid.connect_signal(bt_ca, 'click', showmenu)
	bt_sa = urwid.Button("Select all")
	urwid.connect_signal(bt_sa, 'click', select_all)
	bt_da = urwid.Button("Deselect all")
	urwid.connect_signal(bt_da, 'click', deselect_all)
	footer = urwid.Columns([bt_sv, bt_sa, bt_da, bt_ca], 1)
	items = []
	for item in playlist_names:
		items.append(urwid.CheckBox(item['name'], is_selected(item['id']), on_state_change=checkbox_callback, user_data=item['id']))
	start.original_widget = TabFrame(urwid.ListBox(urwid.SimpleListWalker(items)), header=urwid.Text("Select Playlists"), footer=footer, focus_part='body')

# main menu button handler 
Example #11
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        wlist = []
        addnew = urwid.Button("Add")
        urwid.connect_signal(addnew, 'click', self._add_new_option)
        addnew = urwid.AttrWrap(addnew, 'selectable', 'butfocus')
        wlist.append(addnew)
        for attrib in getattr(self.row, self.metadata.colname): # list-like attribute
            entry = ListEntry(urwid.Columns(
                    [(30, urwid.Text(str(attrib.type))),
                     urwid.Text(unicode(attrib.value).encode("utf-8"))]))
            entry.attrname = attrib.type.name
            urwid.connect_signal(entry, 'activate', self._edit_option)
            urwid.connect_signal(entry, 'delete', self._delete)
            wlist.append(entry)
        listbox = urwid.ListBox(urwid.SimpleFocusListWalker(wlist))
        return urwid.BoxAdapter(urwid.LineBox(listbox), max(7, len(wlist)+2)) 
Example #12
Source File: runner.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        environments = db.get_environment_names()
        reports = [None] + db.get_report_names()

        self._envsel = widgets.ListScrollSelector(environments)
        self._repsel = widgets.ListScrollSelector(reports)
        self._tclist = urwid.SimpleListWalker([])
        butcols = urwid.Columns([
                ("pack", urwid.Text("environment:")),
                AM(self._envsel, "selectable", "butfocus"),
                ("pack", urwid.Text("report:")),
                AM(self._repsel, "selectable", "butfocus"),
            ], dividechars=2)
        header = urwid.Pile([
        AM(urwid.Text("Select environment, report, and set options. Use Tab to switch to environment selector. Selected:"), "subhead"),
                urwid.BoxAdapter(urwid.ListBox(self._tclist), 2),
                butcols,
        ])
        body = self._build_test_selector(False)
        return urwid.Frame(body, header=header, focus_part="body") 
Example #13
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def _create_relation_input(self):
        choices = dict(models.get_choices(self.session, self.modelclass, self.metadata.colname, None))
        addnew = urwid.Button("Add New")
        urwid.connect_signal(addnew, 'click', self._add_new_related)
        # Cancel
        canc = urwid.Button("Cancel")
        urwid.connect_signal(canc, 'click', self._cancel)
        butcol = urwid.Columns([AM(addnew, "buttn", "buttnf"), AM(canc, "buttn", "buttnf")])
        wlist = [butcol]
        if self.metadata.nullable:
            entry = ListEntry(urwid.Text("None (remove)"))
            urwid.connect_signal(entry, 'activate', self._single_select)
            wlist.append(entry)
        for pk, cname in choices.items():
            entry = ListEntry(urwid.Text(cname))
            urwid.connect_signal(entry, 'activate', self._single_select, pk)
            wlist.append(entry)
        listbox = urwid.ListBox(urwid.SimpleListWalker(wlist))
        return urwid.BoxAdapter(urwid.LineBox(listbox), 9) 
Example #14
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        wlist = []
        addnew = urwid.Button("Add")
        urwid.connect_signal(addnew, 'click', self._add_new_attribute)
        addnew = urwid.AttrWrap(addnew, 'selectable', 'butfocus')
        wlist.append(addnew)
        for attrib in getattr(self.row, self.metadata.colname): # list-like attribute
            entry = ListEntry(urwid.Columns(
                    [(30, urwid.Text(str(attrib.type))),
                     urwid.Text(unicode(attrib.value).encode("utf-8"))]))
            entry.attrname = attrib.type.name
            urwid.connect_signal(entry, 'activate', self._edit_attribute)
            urwid.connect_signal(entry, 'delete', self._delete)
            wlist.append(entry)
        listbox = urwid.ListBox(urwid.SimpleFocusListWalker(wlist))
        return urwid.BoxAdapter(urwid.LineBox(listbox), max(7, len(wlist)+2))

    # edit attrib 
Example #15
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def _delete_ok(self, dlg, listentry):
        listbox = self._w.contents[1][0].base_widget
        assert type(listbox) is urwid.ListBox
        listbox.body.remove(listentry)
        urwid.disconnect_signal(dlg, 'ok', self._delete_ok, listentry)
        urwid.disconnect_signal(dlg, 'cancel', self._delete_cancel, listentry)
        del self._oldw
        try:
            self.session.delete(listentry.testequipment)
            self.session.commit()
        except:
            ex, val, tb = sys.exc_info()
            self.session.rollback()
            DEBUG(ex.__name__, val)
            self._emit("message", "{}: {}".format(ex.__name__, val))
        listentry.testequipment = None
        urwid.disconnect_signal(listentry, 'activate', self._edit_testequipment)
        urwid.disconnect_signal(listentry, 'delete', self._delete_testequipment) 
Example #16
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        header = urwid.Pile([
                urwid.AttrMap(urwid.Text("Edit Test Case"), "formhead"),
                urwid.AttrMap(urwid.Text("Arrow keys navigate, Enter to select form button. Type into other fields."), "formhead"),
                urwid.Divider(),
                ])
        formstack = []
        for groupname, group in [
                (None, ("name", "purpose", "passcriteria")),
                ("Details", ("startcondition", "endcondition", "procedure", "prerequisites")),
                ("Management", ("valid", "automated", "interactive", "functionalarea", "testimplementation", "time_estimate", "bugid")),
                ("Requirement", ("reference", "cycle", "priority")),
                ("Status", ("status",)),
                ("Comments", ("comments",)),
                ]:
            if groupname:
                formstack.append(self.build_divider(groupname))
            for colname in group:
                colmd = self.metadata[colname]
                wid = self.build_input(colmd, getattr(self.row, colmd.colname))
                formstack.append(wid)
        data = self.get_default_data(["lastchange"])
        formstack.append(self.get_form_buttons(data))
        listbox = urwid.ListBox(urwid.SimpleListWalker(formstack))
        return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header) 
Example #17
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def _delete_ok(self, dlg, listentry):
        urwid.disconnect_signal(dlg, 'ok', self._delete_ok, listentry)
        urwid.disconnect_signal(dlg, 'cancel', self._delete_cancel, listentry)
        del self._oldw
        self.session.delete(listentry.interface)
        try:
            self.session.commit()
        except:
            ex, val, tb = sys.exc_info()
            self.session.rollback()
            DEBUG(ex.__name__, val)
            self._emit("message", "{}: {}".format(ex.__name__, val))
        else:
            listbox = self._w.contents[1][0].base_widget
            assert type(listbox) is urwid.ListBox
            listbox.body.remove(listentry)
            listentry.interface = None
            urwid.disconnect_signal(listentry, 'activate', self._edit_interface)
            urwid.disconnect_signal(listentry, 'delete', self._delete_interface) 
Example #18
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def _add_complete(self, form, pkval=None):
        urwid.disconnect_signal(form, 'popform', self._add_complete)
        if pkval is not None:
            intf = self.session.query(models.Interface).get(pkval)
            if intf.name in self.equipmentrow.interfaces:
                self._emit("message", "Interface with that name already exists. Not adding.")
            else:
                self.equipmentrow.interfaces.set(intf)
                try:
                    self.session.commit()
                except:
                    ex, val, tb = sys.exc_info()
                    self.session.rollback()
                    DEBUG(ex.__name__, val)
                    self._emit("message", "{}: {}".format(ex.__name__, val))
                else:
                    listbox = self._w.contents[1][0].base_widget
                    assert type(listbox) is urwid.ListBox
                    entry = self._get_intf_entry(intf)
                    listbox.body.append(entry)
        form._emit("popform") 
Example #19
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 #20
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 #21
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        header = urwid.Pile([
                urwid.AttrMap(urwid.Text("Edit Interface"), "formhead"),
                urwid.AttrMap(urwid.Text("Arrow keys navigate, Enter to select form button. Type into other fields."), "formhead"),
                urwid.Divider(),
                ])
        formstack = []
        for groupname, group in [
                (None, ("name", "alias", "ifindex", "description")),
                ("Network Address", ("ipaddr",)),
                ("Media Access Address", ("macaddr", "vlan")),
                ("Extra Info", ("interface_type", "mtu", "speed")),
                ("Administrative", ("status",)),
                ("Associations", ("network", "equipment", "parent", "subinterfaces")),
                ]:
            if groupname:
                formstack.append(self.build_divider(groupname))
            for colname in group:
                colmd = self.metadata[colname]
                wid = self.build_input(colmd, getattr(self.row, colmd.colname))
                formstack.append(wid)
        formstack.append(self.get_form_buttons())
        listbox = urwid.ListBox(urwid.SimpleListWalker(formstack))
        return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header) 
Example #22
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def _build_list(self):
        choices = get_related_choices(self.session, self.modelclass, self.metadata, None)

        #listbox.body.remove(listentry)

        #choices.update(self.currentvalue)
        wlist = []
#        current = self.currentvalue
#        for pk, cobj in choices.items():
#            if pk in current:
#                but = urwid.CheckBox(str(cobj), state=True)
#            else:
#                but = urwid.CheckBox(str(cobj), state=False)
#            urwid.connect_signal(but, 'change', self._multi_select, (pk, cobj))
#            wlist.append(but)
#        return urwid.ListBox(urwid.SimpleListWalker(wlist)) 
Example #23
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 #24
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        header = urwid.Pile([
                urwid.AttrMap(urwid.Text("Create Interface"), "formhead"),
                urwid.AttrMap(urwid.Text("Arrow keys navigate, Enter to select form button. Type into other fields."), "formhead"),
                urwid.Divider(),
                ])
        formstack = []
        for groupname, group in [
                (None, ("name", "alias", "ifindex", "description")),
                ("Network Address", ("ipaddr",)),
                ("Media Access Address", ("macaddr", "vlan")),
                ("Extra Info", ("interface_type", "mtu", "speed")),
                ("Administrative", ("status",)),
                ("Associations", ("network", "parent")),
                ]:
            if groupname:
                formstack.append(self.build_divider(groupname))
            for colname in group:
                colmd = self.metadata[colname]
                wid = self.build_input(colmd)
                formstack.append(wid)
        formstack.append(self.get_form_buttons(create=True))
        listbox = urwid.ListBox(urwid.SimpleListWalker(formstack))
        return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header) 
Example #25
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        header = urwid.Pile([
                urwid.AttrMap(urwid.Text("Create Corporation"), "formhead"),
                urwid.AttrMap(urwid.Text(
                        "Arrow keys navigate,"
                        "Owner is optional, it serves as a lock on the environment. "
                        "Usually you should leave it as None."), "formhead"),
                urwid.Divider(),
                ])
        formstack = []
        for colname in ("name", "address", "country", "contact", "notes"):
            colmd = self.metadata[colname]
            wid = self.build_input(colmd)
            formstack.append(wid)
        formstack.append(self.get_form_buttons(create=True))
        listbox = urwid.ListBox(urwid.SimpleListWalker(formstack))
        return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header) 
Example #26
Source File: widgets.py    From pycopia with Apache License 2.0 6 votes vote down vote up
def build(self):
        header = urwid.Pile([
                urwid.AttrMap(urwid.Text("Create Equipment"), "formhead"),
                urwid.AttrMap(urwid.Text("Arrow keys navigate, Enter to select form button. Type into other fields."), "formhead"),
                urwid.Divider(),
                ])
        formstack = []
        for groupname, group in [
                (None, ("model", "name", "serno")),
                ("Localization", ("language",)),
                ("Asset management", ("owner", "location", "sublocation", "vendor")),
                ("Automation", ("account",)),
                ("structural relationship", ('parent',)),
                ("Addtional Info", ("comments",)),
                ]:
            if groupname:
                formstack.append(self.build_divider(groupname))
            for colname in group:
                colmd = self.metadata[colname]
                wid = self.build_input(colmd)
                formstack.append(wid)
        data = self.get_default_data(["active", "addeddate"])
        formstack.append(self.get_form_buttons(data, create=True))
        listbox = urwid.ListBox(urwid.SimpleListWalker(formstack))
        return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header) 
Example #27
Source File: complex_bar_graph.py    From s-tui with GNU General Public License v2.0 6 votes vote down vote up
def set_y_label(self, y_label):
        if not y_label:
            text = urwid.Text("1")
            pile = urwid.Pile([urwid.ListBox([text])])
            self.y_label = ('fixed', 1, pile)
            return

        str_y_label = [str(i) for i in y_label]
        y_label_nums = str_y_label[1:]
        y_list_walker = [(1, urwid.ListBox([urwid.Text(str_y_label[0])]))]

        for num in y_label_nums:
            y_list_walker = [urwid.ListBox([urwid.Text(num)])] + y_list_walker

        y_list_walker = urwid.Pile(y_list_walker, focus_item=0)
        y_scale_len = len(max(str_y_label, key=len))

        self.y_label = ('fixed', y_scale_len, y_list_walker) 
Example #28
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 #29
Source File: widgets.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def build(self):
        header = urwid.Pile([
                urwid.AttrMap(urwid.Text("Create TestCase"), "formhead"),
                urwid.AttrMap(urwid.Text("Arrow keys navigate, Enter to select "
                "form button. Type into other fields."), "formhead"),

                urwid.Divider(),
                ])
        formstack = []
        for groupname, group in [
                (None, ("name", "purpose", "passcriteria")),
                ("Details", ("startcondition", "endcondition", "procedure")),
                ("Management", ("automated", "interactive", "testimplementation", "time_estimate")),
                ("Requirement", ("reference", "cycle", "priority")),
                ("Comments", ("comments",)),
                ]:
            if groupname:
                formstack.append(self.build_divider(groupname))
            for colname in group:
                colmd = self.metadata[colname]
                wid = self.build_input(colmd)
                formstack.append(wid)
        data = self.get_default_data(["lastchange", "valid", "status"])
        formstack.append(self.get_form_buttons(data, create=True))
        listbox = urwid.ListBox(urwid.SimpleListWalker(formstack))
        return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header) 
Example #30
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  '))