Python urwid.Pile() Examples

The following are 30 code examples of urwid.Pile(). 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: logger.py    From stig with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, height=10, autohide_delay=0):
        self._height = height
        self._autohide_delay = autohide_delay
        self._autohide_handle = None
        self._pile = urwid.Pile([])
        self._pile_options = self._pile.options('pack', None)
        self._scrollable = Scrollable(self._pile)
        pile_sb = urwid.AttrMap(
            ScrollBar(urwid.AttrMap(self._scrollable, 'log')),
            'log.scrollbar'
        )
        super().__init__(pile_sb)

        self._root_logger = logging.getLogger()
        self._orig_handlers = []
        self._handler = UILogRecordHandler(self)

        # Copy formatter first handler (there should be only one formatter anyway)
        handlers = self._root_logger.handlers
        self._handler.setFormatter(handlers[0].formatter)

        # Don't log debugging messages if we're already logging to a file
        for h in handlers:
            if isinstance(h, logging.FileHandler):
                self._handler.setLevel(logging.INFO) 
Example #3
Source File: text.py    From stig with GNU General Public License v3.0 6 votes vote down vote up
def _find_match_indexes(self, size):
        phrase = self._search_phrase
        case_sensitive = self._case_sensitive

        def row_matches(row):
            for _,_,text in row:
                text_dec = text.decode()
                if case_sensitive and phrase in text_dec:
                    return True
                elif not case_sensitive and phrase in text_dec.casefold():
                    return True
            return False

        # Render the full Pile canvas because long lines can cause line breaks
        # and so we can't just get indexes from self._lines.
        full_canv = self._w.base_widget.render((size[0],), False)
        indexes = []
        for i,row in enumerate(full_canv.content()):
            if row_matches(row):
                indexes.append(i)
        self._match_indexes = indexes 
Example #4
Source File: statcode.py    From statcode with MIT License 6 votes vote down vote up
def generate_content(status_code):
    try:
        code_descriptions, num, status_code = get_yaml_dictionary(status_code)
        content = code_descriptions[status_code]
        pile = urwid.Pile([
            urwid.Text("STATCODE: The Manual for HTTP Status Codes and Headers\n", align="center"),
            urwid.Text(("title", "STATUS MESSAGE" if num else "HEADER INFO")),
            urwid.Padding(
                urwid.Text(''.join([str(status_code), ": " if num else ", Example= ", content["message"], '\n'])),
                left=5),
            urwid.Text(("title", "CATEGORY")),
            urwid.Padding(urwid.Text(''.join([content["category"], '\n'])), left=5),
            urwid.Text(("title", "DESCRIPTION")),
            urwid.Padding(urwid.Text(''.join([content["description"], '\n'])), left=5),
            urwid.Text(("title", "COPYRIGHT")),
            urwid.Padding(urwid.Text(''.join([__load_file_data(num), '\n'])), left=5),
        ])
        padding = urwid.Padding(Scrollable(pile), left=1, right=1)

        return padding
    except KeyError:  # None is used to print "not recognized", so KeyError. Other errors have nothing to do with it
        return None 
Example #5
Source File: main.py    From wikicurses with MIT License 6 votes vote down vote up
def edit(title):
    try:
        text, verify = wiki.init_edit(title)
        wiki.login()

        newtext = runEditor(text)
        if newtext == text:
            ex.notify('Edit Canceled: No Change')
            return

        def submit(button):
            closeOverlay()
            wiki.commit_edit(newtext, summary.edit_text,
                             minor.get_state(), verify)
            openPage(title)
        def cancel(button):
            closeOverlay()
        summary = urwid.Edit('Summary: ')
        minor = urwid.CheckBox('Minor Edit')
        cancel_button = urwid.Button('Cancel', cancel)
        submit_button = urwid.Button('Submit', submit)
        pile = urwid.Pile([summary, minor, cancel_button, submit_button])
        openOverlay(pile, 'Edit', 'pack')
    except WikiError as e:
        ex.notify('Error: ' + str(e)) 
Example #6
Source File: ui_elements.py    From vpngate-with-proxy with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, key=None, value=('', '')):
        self.trigger = key
        self.yn = value[0]
        self.yn_but = MyButton([('attention', 'Use proxy: '), self.yn], self.on_change)
        self.input_addr = urwid.Edit(('attention', u' \N{BULLET} Address  : '), edit_text=value[1], wrap='clip')
        self.input_port = urwid.IntEdit(('attention', u' \N{BULLET} Port     : '), default=value[2])
        self.input_port.set_wrap_mode('clip')
        exit_but = urwid.Padding(urwid.Button('OKay'.center(8), self.item_callback), 'center', 12)

        widgets = [self.yn_but] \
                  + [urwid.AttrMap(wid, None, 'popbgs') for wid in (self.input_addr, self.input_port, exit_but)]

        self.pile = urwid.Pile(widgets)
        fill = urwid.LineBox(urwid.Filler(self.pile))
        self.__super.__init__(urwid.AttrWrap(fill, 'popbg'))

        self.chosen = value 
Example #7
Source File: shutdown.py    From conjure-up with MIT License 6 votes vote down vote up
def __init__(self, exit_code):
        self.exit_code = exit_code
        self.message = Text('Do you want to quit?', align='center')
        super().__init__(LineBox(Pile([
            Padding.line_break(""),
            self.message,
            Padding.line_break(""),
            Columns([
                Text(""),
                SubmitButton('Yes', lambda _: self.confirm()),
                Text(""),
                SubmitButton('No', lambda _: self.cancel()),
                Text(""),
            ]),
            Padding.line_break(""),
        ])))
        if events.Error.is_set():
            self.confirm() 
Example #8
Source File: destroy_confirm.py    From conjure-up with MIT License 6 votes vote down vote up
def _build_footer(self):
        no = menu_btn(on_press=self.cancel,
                      label="\n  NO\n")
        yes = menu_btn(on_press=self.submit,
                       label="\n  YES\n")
        self.buttons = Columns([
            ('fixed', 2, Text("")),
            ('fixed', 11, Color.menu_button(
                no,
                focus_map='button_primary focus')),
            Text(""),
            ('fixed', 11, Color.menu_button(
                yes,
                focus_map='button_primary focus')),
            ('fixed', 2, Text(""))
        ])

        self.footer = Pile([
            Padding.line_break(""),
            self.buttons
        ])
        return Color.frame_footer(self.footer) 
Example #9
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 #10
Source File: __main__.py    From mlbstreamer with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, provider, date):

        self.game_date = date

        self.toolbar = Toolbar()
        urwid.connect_signal(
            self.toolbar, "provider_change",
            lambda w, p: self.set_provider(p)
        )

        self.table_placeholder = urwid.WidgetPlaceholder(urwid.Text(""))

        self.datebar = DateBar(self.game_date)
        # self.table = GamesDataTable(self.toolbar.sport_id, self.game_date) # preseason
        self.pile  = urwid.Pile([
            (1, self.toolbar),
            (1, self.datebar),
            ("weight", 1, self.table_placeholder)
        ])
        self.pile.focus_position = 2

        super(ScheduleView, self).__init__(self.pile)
        self.set_provider(provider) 
Example #11
Source File: steps.py    From conjure-up with MIT License 6 votes vote down vote up
def build_widget(self):
        self.widgets = {}
        rows = [
            Columns([
                ('fixed', 3, Text('')),
                ('weight', 0.1, Text('Application')),
                ('weight', 0.4, Text('Result'))
            ], dividechars=5),
            HR(),
        ]
        for step in app.all_steps:
            if not step.has_after_deploy:
                continue
            widget = StepResult(step)
            self.widgets[step.name] = widget
            rows.extend([
                widget,
                HR(),
            ])
        self.pile = Pile(rows)
        return self.pile 
Example #12
Source File: components.py    From sclack with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, user, typing=None, is_read_only=False):
        self.read_only_widget = urwid.Text('You have no power here!', align='center')
        if typing != None:
            top_separator = TextDivider(('is_typing', '{} {} is typing...'.format(
                get_icon('keyboard'),
                typing
            )))
        else:
            top_separator = urwid.Divider('─')
        self.prompt_widget = MessagePrompt(user)
        middle = urwid.WidgetPlaceholder(self.read_only_widget if is_read_only else self.prompt_widget)
        self.body = urwid.Pile([
            urwid.WidgetPlaceholder(top_separator),
            middle,
            urwid.Divider('─')
        ])
        self._typing = typing
        super(MessageBox, self).__init__(self.body, None, {'prompt': 'active_prompt'}) 
Example #13
Source File: message.py    From sclack with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, ts, channel_id, user, text, indicators, reactions=(), attachments=()):
        self.ts = ts
        self.channel_id = channel_id
        self.user_id = user.id
        self.markdown_text = text
        self.original_text = text.original_text
        self.text_widget = urwid.WidgetPlaceholder(text)
        main_column = [urwid.Columns([('pack', user), self.text_widget])]
        main_column.extend(attachments)
        self._file_index = len(main_column)
        if reactions:
            main_column.append(urwid.Columns([
                ('pack', reaction) for reaction in reactions
            ]))
        self.main_column = urwid.Pile(main_column)
        columns = [
            ('fixed', 7, Time(ts)),
            self.main_column,
            ('fixed', indicators.size, indicators)
        ]
        self.contents = urwid.Columns(columns)
        super(Message, self).__init__(self.contents, None, {
            None: 'active_message',
            'message': 'active_message'
        }) 
Example #14
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 #15
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 Environment"), "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", "owner"):
            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 #16
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 #17
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 #18
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 #19
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 #20
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. Type into other fields."), "formhead"),
                urwid.Divider(),
                ])
        formstack = []
        for colname in ("name", "address", "country", "contact", "notes"):
            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)
        # common buttons
        formstack.append(self.get_form_buttons())
        listbox = urwid.ListBox(urwid.SimpleListWalker(formstack))
        return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header) 
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 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 #22
Source File: components.py    From sclack with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, name, status=None, timezone=None, phone=None, email=None, skype=None):
        line = urwid.Divider('─')
        header = urwid.Pile([
            line,
            urwid.Text([' ', name]),
            line
        ])
        contents = []
        if status:
            contents.append(self.format_row('status', status))
        if timezone:
            contents.append(self.format_row('timezone', timezone))
        if phone:
            contents.append(self.format_row('phone', phone))
        if email:
            contents.append(self.format_row('email', email))
        if skype:
            contents.append(self.format_row('skype', skype))
        self.pile = urwid.Pile(contents)
        body = urwid.Frame(urwid.Filler(self.pile, valign='top'), header, line)
        super(ProfileSideBar, self).__init__(body, 'profile') 
Example #23
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 #24
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("Edit 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", ("active", "owner", "location", "sublocation", "vendor", "software")),
                ("Automation", ("account",)),
                ("structural relationship", ('parent', 'subcomponents')),
                ("Addtional Info", ("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)
        for colname in ('attributes',):# TODO ('capabilities', 'attributes'):
            colmd = self.metadata[colname]
            wid = self.build_attribute_input(colmd, getattr(self.row, colmd.colname))
            formstack.append(wid)
        formstack.insert(3, self.build_interface_input())
        formstack.append(self.get_form_buttons())
        listbox = urwid.ListBox(urwid.SimpleListWalker(formstack))
        return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header) 
Example #25
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) 
Example #26
Source File: miscwidgets.py    From stig with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        self._pile = urwid.Pile([])
        super().__init__(urwid.AttrMap(self._pile, 'keychains')) 
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 set_visible_graphs(self, visible_graph_list=None):
        """Show a column of the graph selected for display"""
        if visible_graph_list is None:
            visible_graph_list = self.visible_graph_list

        vline = urwid.AttrWrap(urwid.SolidFill(u'|'), 'line')

        graph_vector_column_list = []
        for state, graph, sub_title in zip(visible_graph_list,
                                           self.bar_graph_vector,
                                           self.sub_title_list):
            if state:
                text_w = urwid.Text(sub_title, align='center')
                sub_title_widget = urwid.ListBox([text_w])
                graph_a = [('fixed', 1, sub_title_widget),
                           ('weight', 1, graph)]
                graph_and_title = urwid.Pile(graph_a)
                graph_vector_column_list.append(('weight', 1, graph_and_title))
                graph_vector_column_list.append(('fixed', 1, vline))

        # if all sub graph are disabled
        if not graph_vector_column_list:
            self.visible_graph_list = visible_graph_list
            self.original_widget = urwid.Pile([])
            return

        # remove the last vertical line separator
        graph_vector_column_list.pop()

        y_label_a = ('weight', 1, urwid.Columns(graph_vector_column_list))
        y_label_and_graphs = [self.y_label,
                              y_label_a]
        column_w = urwid.Columns(y_label_and_graphs, dividechars=1)
        y_label_and_graphs_widget = urwid.WidgetPlaceholder(column_w)

        init_widget = urwid.Pile([('fixed', 1, self.title),
                                  ('weight', 1, y_label_and_graphs_widget)])

        self.visible_graph_list = visible_graph_list
        self.original_widget = init_widget 
Example #28
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 {}".format(self.modelclass.__name__)), "formhead"),
                urwid.AttrMap(urwid.Text("Use arrow keys to navigate, "
                        "Press Enter to select form buttons. Type directly into other fields."
                        "Select and press Enter in the OK button when done. Or Cancel, if you change your mind."), "formhead"),
                urwid.Divider(),
                ])
        formstack = [] # list of all form widgets to display
        doinput, _ = sort_inputs(self.modelclass)
        for key in doinput:
            md = self.metadata[key]
            if md.coltype == "RelationshipProperty":
                # only show columns that don't need our primary key (which wont exist yet)
                if not md.uselist:
                    wid = RelationshipInput(self.session, self.modelclass, md, md.default)
                    urwid.connect_signal(wid, "pushform", self._subform)
                    wid.colname = md.colname
                    formstack.append(wid)
                    self.formwidgets.append(wid)
                continue
            typewidget = _TYPE_CREATE_WIDGETS.get(md.coltype, UnknownInput)
            if typewidget is not None:
                wid = typewidget(self.modelclass, md, md.default)
                wid.colname = md.colname
                formstack.append(wid)
                self.formwidgets.append(wid)
            else:
                formstack.append(NotImplementedInput(self.modelclass, md, None))
        formstack.append(self.get_form_buttons())
        listbox = urwid.ListBox(urwid.SimpleListWalker(formstack))
        return urwid.Frame(urwid.AttrMap(listbox, 'body'), header=header) 
Example #29
Source File: details.py    From stig with GNU General Public License v3.0 5 votes vote down vote up
def _handle_error(self, *errors):
        self._torrent = {'name': None, 'id': None}
        pile = urwid.Pile(urwid.Text(('torrentdetails.error', str(e))) for e in errors)
        self._content.original_widget = pile 
Example #30
Source File: text.py    From stig with GNU General Public License v3.0 5 votes vote down vote up
def _make_content(self, text_widgets):
        return Scrollable(urwid.Pile(text_widgets))