Python urwid 模块,WidgetWrap() 实例源码

我们从Python开源项目中,提取了以下32个代码示例,用于说明如何使用urwid.WidgetWrap()

项目:mongoaudit    作者:Exploit-install    | 项目源码 | 文件源码
def __init__(self, data, field_labels, btn_label, callbacks):
        self.app = data["app"]
        self.error = False
        self.fields, self.callbacks = [], callbacks
        for label in field_labels:
            self.fields.append(InputField(label, next_callback=self.next))
        input_fields = urwid.Pile(self.fields)
        self.message_field = urwid.Text('')
        error_row = urwid.Columns([(17, urwid.Text('')), self.message_field])
        buttons = [TextButton(btn_label, on_press=self.next)]

        if callbacks['back']:
            buttons.insert(0, TextButton('< Back', align='left', on_press=callbacks['back']))
        footer = urwid.AttrMap(urwid.Columns(buttons), 'button')

        card = Card(urwid.Pile(
            [data["content"], input_fields, error_row]), footer=footer)
        urwid.WidgetWrap.__init__(self, card)
项目:mongoaudit    作者:Exploit-install    | 项目源码 | 文件源码
def __init__(self, title, cred, tests, data):
        self.app = None
        self.tester = data["tester"]
        urn = cred["nodelist"][0][0] + ":" + str(cred["nodelist"][0][1]) + (
            "/" + (cred["database"]) if bool(cred["database"]) else "")

        self.data = {"title": title, "callback": data["callback"],
                     "urn": urn, "num_tests": len(tests)}

        self.progress_text = urwid.Text(
            ('progress', '0/' + str(self.data["num_tests"])))
        running_display = urwid.Columns(
            [(14, urwid.Text(('text', 'Running test'))), self.progress_text])
        self.progress_bar = CustomProgressBar(
            'progress', 'remaining', 0, self.data["num_tests"])
        self.text_running = urwid.Text(('text', ''))
        box = urwid.BoxAdapter(urwid.Filler(
            self.text_running, valign='top'), 2)
        pile = urwid.Pile([running_display, self.progress_bar, DIV, box])
        urwid.WidgetWrap.__init__(self, pile)
项目:mongoaudit    作者:stampery    | 项目源码 | 文件源码
def __init__(self, data, field_labels, btn_label, callbacks):
        self.app = data["app"]
        self.error = False
        self.fields, self.callbacks = [], callbacks
        for label in field_labels:
            self.fields.append(InputField(label, next_callback=self.next))
        input_fields = urwid.Pile(self.fields)
        self.message_field = urwid.Text('')
        error_row = urwid.Columns([(17, urwid.Text('')), self.message_field])
        buttons = [TextButton(btn_label, on_press=self.next)]

        if callbacks['back']:
            buttons.insert(0, TextButton('< Back', align='left', on_press=callbacks['back']))
        footer = urwid.AttrMap(urwid.Columns(buttons), 'button')

        card = Card(urwid.Pile(
            [data["content"], input_fields, error_row]), footer=footer)
        urwid.WidgetWrap.__init__(self, card)
项目:mongoaudit    作者:stampery    | 项目源码 | 文件源码
def __init__(self, title, cred, tests, data):
        self.app = None
        self.tester = data["tester"]
        urn = cred["nodelist"][0][0] + ":" + str(cred["nodelist"][0][1]) + (
            "/" + (cred["database"]) if bool(cred["database"]) else "")

        self.data = {"title": title, "callback": data["callback"],
                     "urn": urn, "num_tests": len(tests)}

        self.progress_text = urwid.Text(
            ('progress', '0/' + str(self.data["num_tests"])))
        running_display = urwid.Columns(
            [(14, urwid.Text(('text', 'Running test'))), self.progress_text])
        self.progress_bar = CustomProgressBar(
            'progress', 'remaining', 0, self.data["num_tests"])
        self.text_running = urwid.Text(('text', ''))
        box = urwid.BoxAdapter(urwid.Filler(
            self.text_running, valign='top'), 2)
        pile = urwid.Pile([running_display, self.progress_bar, DIV, box])
        urwid.WidgetWrap.__init__(self, pile)
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def __init__(self):
        self.options = []
        unsure = urwid.RadioButton(self.options, u"Unsure")
        yes = urwid.RadioButton(self.options, u"Yes")
        no = urwid.RadioButton(self.options, u"No")
        display_widget = urwid.GridFlow([unsure, yes, no], 15, 3, 1, 'left')
        urwid.WidgetWrap.__init__(self, display_widget)
项目:selecta    作者:vindolin    | 项目源码 | 文件源码
def __init__(self, list_item, show_hits, match=None):
        self.list_item = list_item

        if match is not None and match is not '' and show_hits is True:
            # highlight the matches
            hits = re.split('({match})'.format(match=re.escape(match)), self.list_item)
            parts = []
            for part in hits:
                if part == match:
                    parts.append(('pattern', part))
                else:
                    parts.append(part)

            text = urwid.AttrMap(
                urwid.Text(parts),
                'line',
                {'pattern': 'pattern_focus', None: 'line_focus'}
            )

        else:
            text = urwid.AttrMap(urwid.Text(self.list_item), 'line', 'line_focus')

        urwid.WidgetWrap.__init__(self, text)
项目:terminal-leetcode    作者:chishui    | 项目源码 | 文件源码
def make_compile_error_view(self):
        blank = urwid.Divider()
        status_header = urwid.AttrWrap(urwid.Text('Run Code Status: '), 'body')
        status = urwid.AttrWrap(urwid.Text('Compile Error'), 'hometag')
        columns = urwid.Columns([(17, status_header), (20, status)])
        column_wrap = urwid.WidgetWrap(columns)
        result_header = urwid.Text('--- Run Code Result: ---', align='center')
        your_input_header = urwid.Text('Your input:')
        your_input = urwid.Text('')
        your_answer_header = urwid.Text('Your answer:')
        your_answer = urwid.Text(self.result['compile_error'])
        expected_answer_header = urwid.Text('Expected answer:')
        expected_answer = urwid.Text('Unkown Error')
        list_items = [
                result_header,
                blank, column_wrap,
                blank, your_input_header, your_input,
                blank, your_answer_header, your_answer,
                blank, expected_answer_header, expected_answer
        ]
        self._append_stdout_if_non_empty(list_items)
        return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)
项目:terminal-leetcode    作者:chishui    | 项目源码 | 文件源码
def make_runtime_error_view(self):
        blank = urwid.Divider()
        status_header = urwid.AttrWrap(urwid.Text('Run Code Status: '), 'body')
        status = urwid.AttrWrap(urwid.Text('Runtime Error'), 'hometag')
        columns = urwid.Columns([(17, status_header), (20, status)])
        column_wrap = urwid.WidgetWrap(columns)
        result_header = urwid.Text('--- Run Code Result: ---', align='center')
        error_header = urwid.Text('Runtime Error Message:')
        error_message = urwid.Text(self.result['runtime_error'])
        your_input_header = urwid.Text('Last input:')
        your_input = urwid.Text(self.result['last_testcase'])
        list_items = [
                result_header,
                blank, column_wrap,
                blank, error_header, error_message,
                blank, your_input_header, your_input,
        ]
        self._append_stdout_if_non_empty(list_items)
        return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)
项目:terminal-leetcode    作者:chishui    | 项目源码 | 文件源码
def make_unified_error_view(self, error_title):
        blank = urwid.Divider()
        status_header = urwid.AttrWrap(urwid.Text('Run Code Status: '), 'body')
        status = urwid.AttrWrap(urwid.Text(error_title), 'hometag')
        columns = urwid.Columns([(17, status_header), (30, status)])
        column_wrap = urwid.WidgetWrap(columns)
        if 'last_testcase' in self.result:
            result_header = urwid.Text('--- Run Code Result: ---', align='center')
            your_input_header = urwid.Text('Last executed input:')
            your_input = urwid.Text(self.result['last_testcase'])
            list_items = [
                result_header,
                blank, column_wrap,
                blank, your_input_header, your_input,
            ]
        else:
            list_items = [
                result_header,
                blank, column_wrap,
            ]
        self._append_stdout_if_non_empty(list_items)
        return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)
项目:terminal-leetcode    作者:chishui    | 项目源码 | 文件源码
def __init__(self, data, marks, sel=True):
        self.sel = sel
        self.id = data.id
        self.data = data
        lockbody = 'body' if not self.data.locked else 'lock'
        pass_symbol = u''
        if self.data.submission_status == 'ac':
            pass_symbol = u'\u2714'
        elif self.data.submission_status == 'notac':
            pass_symbol = u'\u2718'
        text = str(self.data.id)
        mark = make_mark(marks, self.data.id)
        self.item = [
            (4, urwid.AttrWrap(urwid.Text(text), lockbody, 'focus')),
            (2, urwid.AttrWrap(urwid.Text(pass_symbol), lockbody, 'focus')),
            (10, urwid.AttrWrap(urwid.Text(mark), 'hometag', 'focus')),
            urwid.AttrWrap(urwid.Text('%s' % data.title), lockbody, 'focus'),
            (15, urwid.AttrWrap(urwid.Text('%s' % data.acceptance), lockbody, 'focus')),
            (15, urwid.AttrWrap(urwid.Text('%s' % data.difficulty), lockbody, 'focus')),
        ]
        w = urwid.Columns(self.item)
        urwid.WidgetWrap.__init__(self, w)
项目:mongoaudit    作者:Exploit-install    | 项目源码 | 文件源码
def __init__(self, content, header=None, footer=None):
        wlist = []
        if header:
            wlist.append(header)
        wlist.extend([DIV, pad(content)])
        if footer:
            wlist.extend([HR, DIV, pad(footer)])
        wlist.append(DIV)
        card = urwid.AttrMap(urwid.Pile(wlist), 'card')
        urwid.WidgetWrap.__init__(self, card)
项目:mongoaudit    作者:Exploit-install    | 项目源码 | 文件源码
def __init__(self, label="", label_width=15, next_callback=False):
        self.label, self.next_callback = label, next_callback
        self.edit = urwid.Padding(urwid.Edit(), left=1, right=1)
        label = urwid.LineBox(
            urwid.Text(label),
            tlcorner=' ',
            tline=' ',
            lline=' ',
            trcorner=' ',
            blcorner=' ',
            rline=' ',
            brcorner=' ',
            bline=' ')
        lbox = urwid.AttrMap(
            urwid.LineBox(
                self.edit,
                tlcorner=' ',
                tline=' ',
                lline=' ',
                trcorner=' ',
                blcorner=' ',
                rline=' ',
                brcorner=' '),
            'input',
            'input focus')
        cols = urwid.Columns([(label_width, label), lbox])
        urwid.WidgetWrap.__init__(self, cols)
项目:mongoaudit    作者:Exploit-install    | 项目源码 | 文件源码
def __init__(self, result):
        self.result = result
        self.total = len(result)
        self.update_view('next_callback')

        walker = urwid.SimpleListWalker([urwid.Padding(self.top_columns, left=3, right=3),
                                         self.test_result])

        adapter = urwid.BoxAdapter(urwid.ListBox(walker), height=14)

        urwid.WidgetWrap.__init__(self, adapter)
项目:socli    作者:gautamkrishnar    | 项目源码 | 文件源码
def __init__(self, data):
        """
        Construct the Question Page.
        :param data: tuple of (answers, question_title, question_desc, question_stats, question_url)
        """
        answer_frame = self.makeFrame(data)
        urwid.WidgetWrap.__init__(self, answer_frame)
项目:socli    作者:gautamkrishnar    | 项目源码 | 文件源码
def keypress(self, size, key):
        if key in {'down', 'n', 'N'}:
            self.answer_text.next_ans()
        elif key in {'up', 'b', 'B'}:
            self.answer_text.prev_ans()
        elif key in {'o', 'O'}:
            import webbrowser
            if sys.platform.startswith('darwin'):
                browser = webbrowser.get('safari')
            else:
                browser = webbrowser.get()
            print_warning("Opening in your browser...")
            browser.open(self.url)
        elif key == 'left':
            global question_post
            global question_page
            question_post = None
            if question_page is None:
                sys.exit(0)
            else:
                LOOP.widget = question_page
        elif key == 'window resize':
            screenHeight, screenWidth = subprocess.check_output(['stty', 'size']).split()
            if self.screenHeight != screenHeight:
                self._invalidate()
                answer_frame = self.makeFrame(self.data)
                urwid.WidgetWrap.__init__(self, answer_frame)
项目:socli    作者:gautamkrishnar    | 项目源码 | 文件源码
def __init__(self, answers):
        urwid.WidgetWrap.__init__(self, UnicodeText(''))
        self._selectable = True  # so that we receive keyboard input
        self.answers = answers
        self.index = 0
        self.set_answer()
项目:socli    作者:gautamkrishnar    | 项目源码 | 文件源码
def __init__(self, description):
        urwid.WidgetWrap.__init__(self, UnicodeText(''))
        self.description = description
        self.set_description()
项目:Discurses    作者:topisani    | 项目源码 | 文件源码
def __init__(self, node):
        self._node = node
        self._innerwidget = None
        self.is_leaf = False
        self.expanded = False
        widget = self.get_indented_widget()
        urwid.WidgetWrap.__init__(self, widget)
项目:mongoaudit    作者:stampery    | 项目源码 | 文件源码
def __init__(self, content, header=None, footer=None):
        wlist = []
        if header:
            wlist.append(header)
        wlist.extend([DIV, pad(content)])
        if footer:
            wlist.extend([HR, DIV, pad(footer)])
        wlist.append(DIV)
        card = urwid.AttrMap(urwid.Pile(wlist), 'card')
        urwid.WidgetWrap.__init__(self, card)
项目:mongoaudit    作者:stampery    | 项目源码 | 文件源码
def __init__(self, label="", label_width=15, next_callback=False):
        self.label, self.next_callback = label, next_callback
        self.edit = urwid.Padding(urwid.Edit(), left=1, right=1)
        label = urwid.LineBox(
            urwid.Text(label),
            tlcorner=' ',
            tline=' ',
            lline=' ',
            trcorner=' ',
            blcorner=' ',
            rline=' ',
            brcorner=' ',
            bline=' ')
        lbox = urwid.AttrMap(
            urwid.LineBox(
                self.edit,
                tlcorner=' ',
                tline=' ',
                lline=' ',
                trcorner=' ',
                blcorner=' ',
                rline=' ',
                brcorner=' '),
            'input',
            'input focus')
        cols = urwid.Columns([(label_width, label), lbox])
        urwid.WidgetWrap.__init__(self, cols)
项目:mongoaudit    作者:stampery    | 项目源码 | 文件源码
def __init__(self, result):
        self.result = result
        self.total = len(result)
        self.update_view('next_callback')

        walker = urwid.SimpleListWalker([urwid.Padding(self.top_columns, left=3, right=3),
                                         self.test_result])

        adapter = urwid.BoxAdapter(urwid.ListBox(walker), height=14)

        urwid.WidgetWrap.__init__(self, adapter)
项目:stig    作者:rndusr    | 项目源码 | 文件源码
def mksection(title, width, items):
    # Setting class variable 'title = title' below produces "NameError: name
    # 'title' is not defined"
    title_, width_ = title, width
    class Section(urwid.WidgetWrap):
        title = title_
        width = width_

        def __init__(self):
            value_widgets = {}
            needed_keys = set()
            rows = []
            label_width = max(len(item.label) for item in items)
            for item in items:
                label_w = urwid.Text(item.label.rjust(label_width))
                value_w = urwid.Text('')
                value_widgets[item] = value_w
                rows.append(urwid.Columns([('pack', label_w),
                                           ('pack', urwid.Text(': ')),
                                           value_w]))
                needed_keys.update(item.needed_keys)
            self._value_widgets = value_widgets
            self.needed_keys = needed_keys
            super().__init__(urwid.Pile(rows))

        def update(self, torrent):
            for item,value_w in self._value_widgets.items():
                value_w.set_text(item.human_readable(torrent))

    return Section
项目:stig    作者:rndusr    | 项目源码 | 文件源码
def __init__(self, item, cells):
        self._item = item    # Info of torrent/tracker/file/peer/...
        self._cells = cells  # Group instance that combines widgets horizontally

        # Create focusable or unfocusable item widget
        if self.columns_focus_map is not NotImplemented:
            itemw = urwid.AttrMap(urwid.AttrMap(cells, attr_map=None, focus_map=self.columns_focus_map),
                                  self.palette_unfocused, self.palette_focused)
        else:
            itemw = urwid.AttrMap(cells, self.palette_unfocused)
        urwid.WidgetWrap.__init__(self, itemw)

        # Initialize cell widgets
        self.update(item)
项目:douban-movie    作者:chishui    | 项目源码 | 文件源码
def __init__(self, movie):
        self.data = movie
        item = [
            ('pack', urwid.AttrWrap(urwid.Text(movie.title), 'body', 'focus')),
            (5, urwid.AttrWrap(urwid.Text(' ' + str(movie.year)), 'gray', 'focus')),
        ]
        w = urwid.Columns(item)
        blank = urwid.Divider()
        p = urwid.Pile([w, urwid.AttrWrap(urwid.Text(movie.sub_title), 'gray', 'focus'), blank])
        urwid.WidgetWrap.__init__(self, p)
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def __init__(self, controller):
        self.controller = controller
        self.started = True
        self.start_time = None
        self.offset = 0
        self.last_offset = None
        urwid.WidgetWrap.__init__(self, self.main_window())
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main_window(self):
        self.graph = self.bar_graph()
        self.graph_wrap = urwid.WidgetWrap( self.graph )
        vline = urwid.AttrWrap( urwid.SolidFill(u'\u2502'), 'line')
        c = self.graph_controls()
        w = urwid.Columns([('weight',2,self.graph_wrap),
            ('fixed',1,vline), c],
            dividechars=1, focus_column=2)
        w = urwid.Padding(w,('fixed left',1),('fixed right',0))
        w = urwid.AttrWrap(w,'body')
        w = urwid.LineBox(w)
        w = urwid.AttrWrap(w,'line')
        w = self.main_shadow(w)
        return w
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def __init__(self, letter):
        self.walker = CellWalker([Cell(None)])
        self.content = self.walker.content
        self.listbox = urwid.ListBox( self.walker )
        self.set_letter( letter )
        urwid.WidgetWrap.__init__(self, self.frame)
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def main_window(self):
        self.graph = self.bar_graph()
        self.graph_wrap = urwid.WidgetWrap( self.graph )
        vline = urwid.AttrWrap( urwid.SolidFill(u'\u2502'), 'line')
        c = self.graph_controls()
        w = urwid.Columns([('weight',2,self.graph_wrap),
            ('fixed',1,vline), c],
            dividechars=1, focus_column=2)
        w = urwid.Padding(w,('fixed left',1),('fixed right',0))
        w = urwid.AttrWrap(w,'body')
        w = urwid.LineBox(w)
        w = urwid.AttrWrap(w,'line')
        w = self.main_shadow(w)
        return w
项目:oandapyV20-examples    作者:hootnot    | 项目源码 | 文件源码
def __init__(self, txt):
        self.t = urwid.Text(txt)
        w = urwid.AttrMap(self.t, 'body', 'focus')
        urwid.WidgetWrap.__init__(self, w)
项目:oandapyV20-examples    作者:hootnot    | 项目源码 | 文件源码
def __init__(self, t):
        self.t = t
        w = urwid.AttrMap(self.t, 'body', 'focus')
        urwid.WidgetWrap.__init__(self, w)

        if not self.MENU:
            self.MENU = [u'{instrument} Cmds: ',
                         ('close button', u'C'), u') close position ',
                         ('quit button', u'Q'), u') to quit.']
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def graph_controls(self):
        modes = self.controller.get_modes()
        # setup mode radio buttons
        self.mode_buttons = []
        group = []
        for m in modes:
            rb = self.radio_button( group, m, self.on_mode_button )
            self.mode_buttons.append( rb )
        # setup animate button
        self.animate_button = self.button( "", self.on_animate_button)
        self.on_animate_button( self.animate_button )
        self.offset = 0
        self.animate_progress = self.progress_bar()
        animate_controls = urwid.GridFlow( [
            self.animate_button,
            self.button("Reset", self.on_reset_button),
            ], 9, 2, 0, 'center')

        if urwid.get_encoding_mode() == "utf8":
            unicode_checkbox = urwid.CheckBox(
                "Enable Unicode Graphics",
                on_state_change=self.on_unicode_checkbox)
        else:
            unicode_checkbox = urwid.Text(
                "UTF-8 encoding not detected")

        self.animate_progress_wrap = urwid.WidgetWrap(
            self.animate_progress)

        l = [    urwid.Text("Mode",align="center"),
            ] + self.mode_buttons + [
            urwid.Divider(),
            urwid.Text("Animation",align="center"),
            animate_controls,
            self.animate_progress_wrap,
            urwid.Divider(),
            urwid.LineBox( unicode_checkbox ),
            urwid.Divider(),
            self.button("Quit", self.exit_program ),
            ]
        w = urwid.ListBox(urwid.SimpleListWalker(l))
        return w
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def graph_controls(self):
        modes = self.controller.get_modes()
        # setup mode radio buttons
        self.mode_buttons = []
        group = []
        for m in modes:
            rb = self.radio_button( group, m, self.on_mode_button )
            self.mode_buttons.append( rb )
        # setup animate button
        self.animate_button = self.button( "", self.on_animate_button)
        self.on_animate_button( self.animate_button )
        self.offset = 0
        self.animate_progress = self.progress_bar()
        animate_controls = urwid.GridFlow( [
            self.animate_button,
            self.button("Reset", self.on_reset_button),
            ], 9, 2, 0, 'center')

        if urwid.get_encoding_mode() == "utf8":
            unicode_checkbox = urwid.CheckBox(
                "Enable Unicode Graphics",
                on_state_change=self.on_unicode_checkbox)
        else:
            unicode_checkbox = urwid.Text(
                "UTF-8 encoding not detected")

        self.animate_progress_wrap = urwid.WidgetWrap(
            self.animate_progress)

        l = [    urwid.Text("Mode",align="center"),
            ] + self.mode_buttons + [
            urwid.Divider(),
            urwid.Text("Animation",align="center"),
            animate_controls,
            self.animate_progress_wrap,
            urwid.Divider(),
            urwid.LineBox( unicode_checkbox ),
            urwid.Divider(),
            self.button("Quit", self.exit_program ),
            ]
        w = urwid.ListBox(urwid.SimpleListWalker(l))
        return w