我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用urwid.AttrWrap()。
def __init__(self, app): super(BoardListView, self).__init__(urwid.Pile([])) self.log = logging.getLogger('boartty.view.board_list') self.searchInit() self.app = app self.active = True self.subscribed = False #True self.board_rows = {} self.listbox = urwid.ListBox(urwid.SimpleFocusListWalker([])) self.header = BoardListHeader() self.refresh() self._w.contents.append((app.header, ('pack', 1))) self._w.contents.append((urwid.Divider(),('pack', 1))) self._w.contents.append((urwid.AttrWrap(self.header, 'table-header'), ('pack', 1))) self._w.contents.append((self.listbox, ('weight', 1))) self._w.set_focus(3)
def __init__(self, app): super(ProjectListView, self).__init__(urwid.Pile([])) self.log = logging.getLogger('boartty.view.project_list') self.searchInit() self.app = app self.active = True self.subscribed = True self.project_rows = {} self.topic_rows = {} self.open_topics = set() self.listbox = urwid.ListBox(urwid.SimpleFocusListWalker([])) self.header = ProjectListHeader() self.refresh() self._w.contents.append((app.header, ('pack', 1))) self._w.contents.append((urwid.Divider(),('pack', 1))) self._w.contents.append((urwid.AttrWrap(self.header, 'table-header'), ('pack', 1))) self._w.contents.append((self.listbox, ('weight', 1))) self._w.set_focus(3)
def __init__(self, title, command_caption='Command: (Tab to switch focus to upper frame, where you can scroll text)', cmd_cb=None, max_size=1000): self.header=urwid.Text(title) self.model=urwid.SimpleListWalker([]) self.body=ListView(self.model, lambda: self._update_focus(False), max_size=max_size ) self.input=Input(lambda: self._update_focus(True)) foot=urwid.Pile([urwid.AttrMap(urwid.Text(command_caption), 'reversed'), urwid.AttrMap(self.input,'normal')]) urwid.Frame.__init__(self, urwid.AttrWrap(self.body, 'normal'), urwid.AttrWrap(self.header, 'reversed'), foot) self.set_focus_path(['footer',1]) self._focus=True urwid.connect_signal(self.input,'line_entered',self.on_line_entered) self._cmd=cmd_cb self._output_styles=[s[0] for s in self.PALLETE] self.eloop=None
def __init__(self, title, command_caption='Command: (Tab to switch focus to upper frame, where you can scroll text)', cmd_cb=None, max_size=1000): self.header = urwid.Text(title) self.model = urwid.SimpleListWalker([]) self.body = ListView(self.model, lambda: self._update_focus(False), max_size=max_size) self.input = Input(lambda: self._update_focus(True)) foot = urwid.Pile([urwid.AttrMap(urwid.Text(command_caption), 'reversed'), urwid.AttrMap(self.input, 'normal')]) urwid.Frame.__init__(self, urwid.AttrWrap(self.body, 'normal'), urwid.AttrWrap(self.header, 'reversed'), foot) self.set_focus_path(['footer', 1]) self._focus = True urwid.connect_signal(self.input, 'line_entered', self.on_line_entered) self._cmd = cmd_cb self._output_styles = [s[0] for s in self.PALLETE] self.eloop = None
def __init__(self, prompt_text=u"Input:", default_text=u""): close_button = urwid.Button("OK") prompt = urwid.Text(prompt_text) edit_field = CustomEdit(caption=u'', edit_text=default_text, multiline=False, align='left', wrap='space', allow_tab=False, edit_pos=None, layout=None, mask=None) prompt_wrap = urwid.AttrMap(prompt, 'header') close_button_wrap = urwid.AttrMap(close_button, 'buttn', 'buttnf') edit_field_wrap = urwid.AttrMap(edit_field, 'editcp') urwid.connect_signal(close_button, 'click', edit_field.on_finish) urwid.connect_signal(edit_field, 'done', self.on_close) pile = urwid.Pile([prompt_wrap, edit_field_wrap, urwid.Padding(close_button_wrap, 'center', 6)]) fill = urwid.Filler(urwid.Padding(pile, 'center', left=1, right=1)) self.__super.__init__(urwid.AttrWrap(fill, 'popbg'))
def make_failed_view(self): blank = urwid.Divider() status_header = urwid.AttrWrap(urwid.Text('Run Code Status: '), 'body') status = urwid.AttrWrap(urwid.Text('Wrong Answer'), 'hometag') columns = urwid.Columns([(17, status_header), (20, status)]) result_header = urwid.Text('--- Run Code Result: ---', align='center') passed_header = urwid.Text('Passed test cases:') s = self.result['compare_result'] passed = urwid.Text('%d/%d' % (s.count('1'), len(s))) your_input_header = urwid.Text('Your input:') your_input = urwid.Text(self.result['input']) your_answer_header = urwid.Text('Your answer:') your_answer = urwid.Text(self.result['code_output']) expected_answer_header = urwid.Text('Expected answer:') expected_answer = urwid.Text(self.result['expected_output']) list_items = [ result_header, blank, columns, blank, passed_header, passed, 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)
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)
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)
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)
def __init__(self, data, header): title = [ (4, urwid.AttrWrap(urwid.Text('#'), 'body', 'focus')), (2, urwid.AttrWrap(urwid.Text(''), 'body', 'focus')), (10, urwid.AttrWrap(urwid.Text('Tag'), 'body', 'focus')), urwid.AttrWrap(urwid.Text('Title'), 'body', 'focus'), (15, urwid.AttrWrap(urwid.Text('Acceptance'), 'body', 'focus')), (15, urwid.AttrWrap(urwid.Text('Difficulty'), 'body', 'focus')), ] title_column = urwid.Columns(title) self.marks = load_marks() items = make_itemwidgets(data, self.marks) self.listbox = urwid.ListBox(urwid.SimpleListWalker(items)) header_pile = urwid.Pile([header, title_column]) urwid.Frame.__init__(self, urwid.AttrWrap(self.listbox, 'body'), header=header_pile) self.last_sort = {'attr': 'id', 'reverse': True} self.last_search_text = None
def __init__( self, title, login, command_caption='Command: (Tab to switch focus to upper ' 'frame, where you can scroll text)\nType exit or quit ' 'to close', max_size=1000): self.header = urwid.Text(title) self.model = urwid.SimpleListWalker([]) self.body = ListView( self.model, lambda: self._update_focus(False), max_size=max_size) self.input = Input(lambda: self._update_focus(True)) foot = urwid.Pile([ urwid.AttrMap( urwid.Text(command_caption), 'reversed'), urwid.AttrMap(self.input, 'normal')]) urwid.Frame.__init__(self, urwid.AttrWrap(self.body, 'normal'), urwid.AttrWrap(self.header, 'reversed'), foot) self.set_focus_path(['footer', 1]) self._focus = True urwid.connect_signal(self.input, 'line_entered', self.on_line_entered) self._output_styles = [s[0] for s in self.PALLETE] self.eloop = None self.login = login
def __init__(self): close_button = urwid.Button("that's pretty cool") urwid.connect_signal(close_button, 'click', lambda button:self._emit("close")) pile = urwid.Pile([urwid.Text( "^^ I'm attached to the widget that opened me. " "Try resizing the window!\n"), close_button]) fill = urwid.Filler(pile) self.__super.__init__(urwid.AttrWrap(fill, 'popbg'))
def __init__(self, node, display): self.__super.__init__(node) self.display= display # insert an extra AttrWrap for our own use self._w = urwid.AttrWrap(self._w, None) self.flagged = False self.update_w()
def update_line_numbers(self, cfrom=None): if self.show_lnums: focus_pos = self.listbox.focus_position lnums = self.line_nums lnums.set_focus(focus_pos, coming_from=cfrom) foc = lnums.numbers[focus_pos] prev = lnums.numbers[lnums.previous] lnums.numbers[lnums.previous] = urwid.Text(prev.text, align='right') lnums.numbers[focus_pos] = urwid.AttrWrap(foc, 'key') lnums.previous = focus_pos
def __init__(self, app, query, query_desc=None, project_key=None, active=False, sort_by=None, reverse=None): super(StoryListView, self).__init__(urwid.Pile([])) self.log = logging.getLogger('boartty.view.story_list') self.searchInit() self.app = app self.query = query self.query_desc = query_desc or query self.active = active self.story_rows = {} self.enabled_columns = set() for colinfo in COLUMNS: if (colinfo.name in self.required_columns or colinfo.name not in self.optional_columns): self.enabled_columns.add(colinfo.name) self.disabled_columns = set() self.listbox = urwid.ListBox(urwid.SimpleFocusListWalker([])) self.project_key = project_key if 'Project' not in self.required_columns and project_key is not None: self.enabled_columns.discard('Project') self.disabled_columns.add('Project') #storyboard: creator if 'Owner' not in self.required_columns and 'owner:' in query: # This could be or'd with something else, but probably # not. self.enabled_columns.discard('Owner') self.disabled_columns.add('Owner') self.sort_by = sort_by or app.config.story_list_options['sort-by'] if reverse is not None: self.reverse = reverse else: self.reverse = app.config.story_list_options['reverse'] self.header = StoryListHeader(self.enabled_columns) self.refresh() self._w.contents.append((app.header, ('pack', 1))) self._w.contents.append((urwid.Divider(), ('pack', 1))) self._w.contents.append((urwid.AttrWrap(self.header, 'table-header'), ('pack', 1))) self._w.contents.append((self.listbox, ('weight', 1))) self._w.set_focus(3)
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)
def __init__(self, movies): footer=urwid.AttrWrap(urwid.Text('Press q to exit, use up and down arrow to navigate, press Enter to select'), 'footer') items = self.make_items(movies) self.listbox = urwid.ListBox(urwid.SimpleListWalker(items)) top = urwid.Overlay(self.listbox, urwid.SolidFill(' '), align='center', width=('relative', 60), valign='middle', height=('relative', 60), min_width=20, min_height=9) urwid.Frame.__init__(self, urwid.AttrWrap(top, 'body'), footer=footer)
def create_radio_button(self, g, name, font, fn): w = urwid.RadioButton(g, name, False, on_state_change=fn) w.font = font w = urwid.AttrWrap(w, 'button normal', 'button select') return w
def create_disabled_radio_button(self, name): w = urwid.Text(" " + name + " (UTF-8 mode required)") w = urwid.AttrWrap(w, 'button disabled') return w
def create_edit(self, label, text, fn): w = urwid.Edit(label, text) urwid.connect_signal(w, 'change', fn) fn(w, text) w = urwid.AttrWrap(w, 'edit') return w
def __init__(self): cwd = os.getcwd() store_initial_cwd(cwd) self.header = urwid.Text("") self.listbox = urwid.TreeListBox(urwid.TreeWalker(DirectoryNode(cwd))) self.listbox.offset_rows = 1 self.footer = urwid.AttrWrap(urwid.Text(self.footer_text), 'foot') self.view = urwid.Frame( urwid.AttrWrap(self.listbox, 'body'), header=urwid.AttrWrap(self.header, 'head'), footer=self.footer)
def main_shadow(self, w): """Wrap a shadow and background around widget w.""" bg = urwid.AttrWrap(urwid.SolidFill(u"\u2592"), 'screen edge') shadow = urwid.AttrWrap(urwid.SolidFill(u" "), 'main shadow') bg = urwid.Overlay( shadow, bg, ('fixed left', 3), ('fixed right', 1), ('fixed top', 2), ('fixed bottom', 1)) w = urwid.Overlay( w, bg, ('fixed left', 2), ('fixed right', 3), ('fixed top', 1), ('fixed bottom', 2)) return w
def button(self, t, fn): w = urwid.Button(t, fn) w = urwid.AttrWrap(w, 'button normal', 'button select') return w
def radio_button(self, g, l, fn): w = urwid.RadioButton(g, l, False, on_state_change=fn) w = urwid.AttrWrap(w, 'button normal', 'button select') return w
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
def __init__(self, name): self.save_name = name self.walker = LineWalker(name) self.listbox = urwid.ListBox(self.walker) self.footer = urwid.AttrWrap(urwid.Text(self.footer_text), "foot") self.view = urwid.Frame(urwid.AttrWrap(self.listbox, 'body'), footer=self.footer)
def widget(self): """Return a widget containing event information""" text = urwid.Text( self.message, 'center' ) return urwid.AttrWrap( text, self.attr )
def _get_at_pos(self, pos): i, sub = pos assert sub in (0,1,2) if i < 0 or i >= len(self.content): return None, None if sub == 0: edit = self.content[i].edit return urwid.AttrWrap(edit, 'edit', 'editfocus'), pos elif sub == 1: return self.div, pos else: return self.content[i].result, pos
def set_letter(self, letter): """Set the column header with letter.""" self.letter = letter header = urwid.AttrWrap( urwid.Text( ["Column ",('key',letter)], layout = CALC_LAYOUT), 'colhead' ) self.frame = urwid.Frame( self.listbox, header )
def __init__(self): self.head = urwid.AttrWrap( urwid.Text(["Help Column ", ('key',"?")], layout = CALC_LAYOUT), 'help') self.foot = urwid.AttrWrap( urwid.Text(["[text continues.. press ", ('key',"?"), " then scroll]"]), 'helpnote' ) self.items = [urwid.Text(x) for x in self.help_text] self.listbox = urwid.ListBox(urwid.SimpleListWalker(self.items)) self.body = urwid.AttrWrap( self.listbox, 'help' ) self.frame = urwid.Frame( self.body, header=self.head)
def __init__(self, node): self.__super.__init__(node) # insert an extra AttrWrap for our own use self._w = urwid.AttrWrap(self._w, None) self.flagged = False self.update_w()
def __init__(self, data=None): self.topnode = ExampleParentNode(data) self.listbox = urwid.TreeListBox(urwid.TreeWalker(self.topnode)) self.listbox.offset_rows = 1 self.header = urwid.Text( "" ) self.footer = urwid.AttrWrap( urwid.Text( self.footer_text ), 'foot') self.view = urwid.Frame( urwid.AttrWrap( self.listbox, 'body' ), header=urwid.AttrWrap(self.header, 'head' ), footer=self.footer )
def __init__(self, text, height, width, body=None): width = int(width) if width <= 0: width = ('relative', 80) height = int(height) if height <= 0: height = ('relative', 80) self.body = body if body is None: # fill space with nothing body = urwid.Filler(urwid.Divider(),'top') self.frame = urwid.Frame( body, focus_part='footer') if text is not None: self.frame.header = urwid.Pile( [urwid.Text(text), urwid.Divider()] ) w = self.frame # pad area around listbox w = urwid.Padding(w, ('fixed left',2), ('fixed right',2)) w = urwid.Filler(w, ('fixed top',1), ('fixed bottom',1)) w = urwid.AttrWrap(w, 'body') # "shadow" effect w = urwid.Columns( [w,('fixed', 2, urwid.AttrWrap( urwid.Filler(urwid.Text(('border',' ')), "top") ,'shadow'))]) w = urwid.Frame( w, footer = urwid.AttrWrap(urwid.Text(('border',' ')),'shadow')) # outermost border area w = urwid.Padding(w, 'center', width ) w = urwid.Filler(w, 'middle', height ) w = urwid.AttrWrap( w, 'border' ) self.view = w
def add_buttons(self, buttons): l = [] for name, exitcode in buttons: b = urwid.Button( name, self.button_press ) b.exitcode = exitcode b = urwid.AttrWrap( b, 'selectable','focus' ) l.append( b ) self.buttons = urwid.GridFlow(l, 10, 3, 1, 'center') self.frame.footer = urwid.Pile( [ urwid.Divider(), self.buttons ], focus_item = 1)
def __init__(self, text, height, width): self.edit = urwid.Edit() body = urwid.ListBox([self.edit]) body = urwid.AttrWrap(body, 'selectable','focustext') DialogDisplay.__init__(self, text, height, width, body) self.frame.set_focus('body')
def __init__(self, file, height, width): l = [] # read the whole file (being slow, not lazy this time) for line in open(file).readlines(): l.append( urwid.Text( line.rstrip() )) body = urwid.ListBox(l) body = urwid.AttrWrap(body, 'selectable','focustext') DialogDisplay.__init__(self, None, height, width, body)
def make_header(self): if self.leetcode.is_login: columns = [ ('fixed', 15, urwid.Padding(urwid.AttrWrap( urwid.Text('%s' % config.username), 'head', ''))), urwid.AttrWrap(urwid.Text('You have solved %d / %d problems. ' % (len(self.leetcode.solved), len(self.leetcode.quizzes))), 'head', ''), ] return urwid.Columns(columns) else: text = urwid.AttrWrap(urwid.Text('Not login'), 'head') return text
def make_success_view(self): blank = urwid.Divider() status_header = urwid.AttrWrap(urwid.Text('Run Code Status: '), 'body') status = urwid.AttrWrap(urwid.Text('Accepted'), 'accepted') columns = urwid.Columns([(20, status_header), (20, status)]) runtime = urwid.Text('Run time: %s' % self.result['status_runtime']) result_header = urwid.Text('--- Run Code Result: ---', align='center') list_items = [ result_header, blank, columns, blank, runtime ] self._append_stdout_if_non_empty(list_items) return urwid.Padding(urwid.ListBox(urwid.SimpleListWalker(list_items)), left=2, right=2)
def __init__(self): title = urwid.AttrWrap(urwid.Text('Help'), 'body') body = urwid.Text(HelpView.__doc__) pile = urwid.Pile([title, body]) filler = urwid.Filler(pile) urwid.Frame.__init__(self, filler)
def __init__(self, quiz, loop = None): self.quiz = quiz self.loop = loop self.logger = logging.getLogger(__name__) blank = urwid.Divider() view_title = urwid.AttrWrap(urwid.Text(self.quiz.title), 'body') view_text = self.make_body_widgets() view_code_title = urwid.Text('\n --- Sample Code ---\n') view_code = urwid.Text(self.quiz.sample_code) listitems = [blank, view_title, blank] + view_text + \ [blank, view_code_title, blank, view_code, blank] self.listbox = urwid.ListBox(urwid.SimpleListWalker(listitems)) urwid.Frame.__init__(self, self.listbox)
def radio_button(g, l, fn): """ Inheriting radio button of urwid """ w = urwid.RadioButton(g, l, False, on_state_change=fn) w = urwid.AttrWrap(w, 'button normal', 'button select') return w