我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用urwid.Pile()。
def __init__(self, initial_buttons): self.list_stack = [initial_buttons] self.all_styled_buttons = [urwid.AttrMap(b, None, 'reveal focus') for b in initial_buttons.items] self.list_walker = ChooseFromListWalker(self.all_styled_buttons, self) list_box = ChooseFromListBox(self.list_walker) column_array = convert_details_to_columns( initial_buttons.items[0].retrieve_important_details()) self.cols = urwid.Columns( [('weight', 1, column_array[0]), ('weight', 4, column_array[1])], ) self.detail_view = False self.base_title_text = self.list_stack[-1].items_title self.title = urwid.AttrMap(urwid.Text(self.base_title_text + " " + self.EMPTY_FILTER_TEXT), 'title') self.cols_title = urwid.AttrMap(urwid.Text(u'Attributes'), 'title') self.body = urwid.Pile([(2, urwid.Filler(self.title, valign='top')), list_box, ( 2, urwid.Filler(self.cols_title, valign='top')), self.cols]) self.before_detail = None self.filter_string = ""
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)
def email_prompt(self, result, title, urn): header = urwid.Text(('text bold', 'Send detailed results report via email')) subtitle = urwid.Text([ ('text', 'The email report contains detailed results of each of the runned tests, ' 'as well as links to guides on how to fix the found issues.\n\n'), ('text italic', 'You will be included into a MongoDB critical security bugs ' 'newsletter. We will never SPAM you, we promise!') ]) content = urwid.Pile([header, DIV, subtitle]) card = FormCard( {"content": content, "app": self.app}, ['Email'], 'Send report', { 'next': lambda form, email: self.send_email(email.strip(), result, title, urn) \ if validate_email(email) else form.set_message("Invalid email address", True), 'back': lambda _: self.display_overview(result, title, urn) }) self.app.render(card)
def __init__(self): self.game = Game() self._statusbar = urwid.Text(u'Ready') self.current_selection = Selection(None, None) self._tableau_columns = urwid.Columns([EmptyCardWidget() for _ in range(7)]) self._top_columns = urwid.Columns([ EmptyCardWidget(), EmptyCardWidget(), SpacerWidget(), EmptyCardWidget(), EmptyCardWidget(), EmptyCardWidget(), EmptyCardWidget(), ]) self._update_stock_and_waste() self._update_foundations() self._update_tableaus() self.main_layout = urwid.Pile([ self._top_columns, urwid.Divider(), self._tableau_columns, urwid.Divider(), self._statusbar, ])
def init_main_screen(self): self.w_filter_edit = urwid.Edit('Filter ') aw_filter_edit = urwid.AttrMap(self.w_filter_edit, 'edit', 'edit_focus') self.w_status_line = urwid.AttrMap(StatusLine(self.store.get_test_stats), 'statusline', '') urwid.connect_signal(self.w_filter_edit, 'change', self.on_filter_change) self.init_test_listbox() self.w_main = urwid.Padding( urwid.Pile([ ('pack', urwid.Text(u'Python Urwid Test Runner', align='center')), ('pack', urwid.Divider()), ('pack', aw_filter_edit), ('pack', urwid.Divider()), self.w_test_listbox, ('pack', urwid.Divider()), ('pack', self.w_status_line), ]), left=2, right=2 )
def __init__(self, Telegram_ui): self.Telegram_ui = Telegram_ui self.updateLockedauto = False self.username_list = [] self.buffer_writing_text = {} # handeling navigation in history self.history_own_message = {} self.history_pos = 0 self.cur_text = "" self.status_bar = urwid.Text(('status_bar', ' '), align='left') self.attr = urwid.AttrMap(self.status_bar, 'status_bar') self.widgetEdit = urwid.Edit(TEXT_CAPTION, "", multiline=False) self.pile = urwid.Pile([self.attr, self.widgetEdit]) super().__init__(self.pile) self.update_send_widget()
def __init__(self, app, title, prompt, button, text, ring=None): self.app = app save_button = FixedButton(button) cancel_button = FixedButton('Cancel') urwid.connect_signal(save_button, 'click', lambda button:self._emit('save')) urwid.connect_signal(cancel_button, 'click', lambda button:self._emit('cancel')) button_widgets = [('pack', save_button), ('pack', cancel_button)] button_columns = urwid.Columns(button_widgets, dividechars=2) rows = [] self.entry = MyEdit(edit_text=text, multiline=True, ring=ring) rows.append(urwid.Text(prompt)) rows.append(self.entry) rows.append(urwid.Divider()) rows.append(button_columns) pile = urwid.Pile(rows) fill = urwid.Filler(pile, valign='top') super(TextEditDialog, self).__init__(urwid.LineBox(fill, title))
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, title, topics): button_widgets = [] ok_button = mywid.FixedButton('OK') cancel_button = mywid.FixedButton('Cancel') urwid.connect_signal(ok_button, 'click', lambda button:self._emit('ok')) urwid.connect_signal(cancel_button, 'click', lambda button:self._emit('cancel')) button_widgets.append(('pack', ok_button)) button_widgets.append(('pack', cancel_button)) button_columns = urwid.Columns(button_widgets, dividechars=2) self.topic_buttons = [] self.topic_keys = {} rows = [] for key, name in topics: button = mywid.FixedRadioButton(self.topic_buttons, name) self.topic_keys[button] = key rows.append(button) rows.append(urwid.Divider()) rows.append(button_columns) pile = urwid.Pile(rows) fill = urwid.Filler(pile, valign='top') super(TopicSelectDialog, self).__init__(urwid.LineBox(fill, title))
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, discord_client, channels, send_channel, name=""): self.discord = discord_client self.ui = self.discord.ui self.channels = channels self.send_channel = send_channel self.name = name self._selectable = False self.channel_names = discurses.processing.shorten_channel_names( channels, 14) self.w_channel_cols = SendChannelSelector(self) self.message_list = MessageListWidget(self.discord, self) self.edit_message = MessageEditWidget(self.discord, self) self.frame = urwid.Pile([('weight', 1, self.message_list), ('pack', self.edit_message)], 1) HasModal.__init__(self, self.frame) self.__super.__init__(self.w_placeholder) if len(channels) == 0: self.popup_server_tree()
def test_focusable_widget_gets_keypress_only_if_visible(self): w = Scrollable( urwid.Pile([urwid.Text('t1'), urwid.Text('t2'), urwid.Edit('', 'e3')]) ) size = (5, 2) def press_keys(): for key in ('backspace', 'backspace', 'f', 'o', 'o'): w.keypress(size, key) self.check(w, size, text=('t1'.ljust(size[0]), 't2'.ljust(size[0]))) press_keys() self.check(w, size, text=('t1'.ljust(size[0]), 't2'.ljust(size[0]))) w.set_scrollpos(1) self.check(w, size, text=('t2'.ljust(size[0]), 'e3'.ljust(size[0]))) press_keys() self.check(w, size, text=('t2'.ljust(size[0]), 'foo'.ljust(size[0])))
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, num_cores, max_mem): self.cpu_utilbar = urwid.ProgressBar('resource_bar_empty', 'resource_bar', done=num_cores) self.mem_utilbar = urwid.ProgressBar('resource_bar_empty', 'resource_bar', done=max_mem) super(ResourceMonitor, self).__init__(urwid.Pile([ urwid.Columns([ urwid.Text("CPU Util", align="right"), self.cpu_utilbar, urwid.Divider(), urwid.Text("Memory Capacity", align="right"), self.mem_utilbar ]), # urwid.Columns([ # urwid.Text("CPU Sched Latency"), # urwid.ProgressBar('resource_bar_empty', 'resource_bar'), # urwid.Divider(), # urwid.Text("Memory Paging"), # urwid.ProgressBar('resource_bar_empty', 'resource_bar'), # ]) ]))
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 test_focus_path(self): # big tree of containers t = urwid.Text(u'x') e = urwid.Edit(u'?') c = urwid.Columns([t, e, t, t]) p = urwid.Pile([t, t, c, t]) a = urwid.AttrMap(p, 'gets ignored') s = urwid.SolidFill(u'/') o = urwid.Overlay(e, s, 'center', 'pack', 'middle', 'pack') lb = urwid.ListBox(urwid.SimpleFocusListWalker([t, a, o, t])) lb.focus_position = 1 g = urwid.GridFlow([t, t, t, t, e, t], 10, 0, 0, 'left') g.focus_position = 4 f = urwid.Frame(lb, header=t, footer=g) self.assertEqual(f.get_focus_path(), ['body', 1, 2, 1]) f.set_focus_path(['footer']) # same as f.focus_position = 'footer' self.assertEqual(f.get_focus_path(), ['footer', 4]) f.set_focus_path(['body', 1, 2, 2]) self.assertEqual(f.get_focus_path(), ['body', 1, 2, 2]) self.assertRaises(IndexError, lambda: f.set_focus_path([0, 1, 2])) self.assertRaises(IndexError, lambda: f.set_focus_path(['body', 2, 2])) f.set_focus_path(['body', 2]) # focus the overlay self.assertEqual(f.get_focus_path(), ['body', 2, 1])
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, label=None, delegate=None): self.delegate = delegate pile = urwid.Pile([]) if isinstance(label, list): for item in label: element = urwid.Text(('bold-heading', item), align="center") pile.contents.append((element, pile.options())) else: if label is not None: label = urwid.Text(('bold-heading', label), align="center") pile.contents.append((label, pile.options())) filler = urwid.Filler(pile, 'middle') super(EmptyFrame, self).__init__(filler, "background")
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 set_y_label(self, y_label): if len(y_label) == 0: 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)) y_notation = [('fixed', y_scale_len, y_list_walker), ('weight', 1, self.bar_graph)] self.y_label.original_widget = urwid.Columns(y_notation, dividechars=1)
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)
def get_content(text): return urwid.Pile([urwid.SelectableIcon( s, 0) if i == 0 else urwid.Text(s) for i, s in enumerate(text)])
def __init__(self, text, vertical_padding=True): content = [urwid.Padding(self.get_content(text), left=3, right=3)] if vertical_padding: content = [DIV] + content + [DIV] lbox = urwid.LineBox(urwid.Pile(content)) self.__super.__init__(urwid.AttrMap(urwid.Pile( [lbox]), 'image button', 'image button focus'))
def __init__(self, pic, text): content = self.get_content(text) lbox = urwid.LineBox(urwid.Pile([DIV, urwid.Padding( urwid.Columns([(8, pic), content], 4), left=3, right=3), DIV])) self.__super.__init__(urwid.AttrMap(urwid.Pile( [lbox]), 'image button', 'image button focus'))
def uri_prompt(self, title, label, uri_example, tests): """ Args: title (str): Title for the test page label (str): label for the input field uri_example (str): example of a valid URI tests (Test[]): test to pass as argument to run_test """ intro = urwid.Pile([ urwid.Text(('text bold', title + ' test suite')), DIV, urwid.Text([label + ' (', ('text italic', uri_example), ')']) ]) def _next(form, uri): form.set_message("validating URI") cred = validate_uri(uri) if cred: form.set_message("Checking MongoDB connection...") tester = Tester(cred, tests) if tester.info: self.run_test(cred, title, tester, tests) else: form.set_message("Couldn't find a MongoDB server", True) else: form.set_message("Invalid domain", True) form = FormCard( {"content": intro, "app": self.app}, ['URI'], 'Run ' + title.lower() + ' test suite', {'next': _next, 'back': self.choose_test}) self.app.render(form)
def send_email(self, email, result, title, urn): email_result = [{"name": val["name"], "value": val["result"], "data": val["extra_data"]} for val in result] response = send_result(email, email_result, title, urn) header = urwid.Text(('text bold', 'Send detailed results report via email')) subtitle = urwid.Text( ('text', response)) content = urwid.Pile([header, DIV, subtitle]) footer = self.get_footer('< Back to results overview', lambda _: self.display_overview(result, title, urn)) card = Card(content, footer=footer) self.app.render(card)
def read(filename, align='left'): def line_process(line): return urwid.AttrMap(urwid.Text(map(pixel_process, line), wrap='clip', align=align), 'pic') path = getattr(sys, '_MEIPASS', None) if path: path = os.path.join(path, 'data/%s' % filename) else: path = pkg_resources.resource_filename(__name__, 'data/%s' % filename) with open(path, 'r') as file_to_read: bytes_read = file_to_read.read() img_size = {"width":ord(bytes_read[18]), "height":ord(bytes_read[22])} bmp = {"complete": len(bytes_read), "content": img_size["width"] * img_size["height"] * 3, "line_size": img_size["width"] * 3} pic = [] for i in range(bmp["complete"] - bmp["content"], bmp["complete"], bmp["line_size"]): raw_line = bytes_read[i:i + bmp["line_size"]] row = [] for j in range(0, bmp["line_size"], 3): raw_pixel = raw_line[j:j + 3][::-1] color = '#' + ''.join(map(round_compo, raw_pixel)) row.append(color) pic.append(row) return urwid.Pile(map(line_process, pic[::-1]))
def __init__(self, cards, onclick=None, index=0, on_double_click=None): self.cards = cards self.onclick = onclick self.on_double_click = on_double_click self.pile = urwid.Pile([]) self._update_pile() self.index = index super(CardPileWidget, self).__init__(self.pile)
def __init__(self): self.top_string = urwid.Text('') self.bottom_string = urwid.Text('') self.small_blinks = urwid.Filler(self.top_string, 'top') self.large_blinks = ('weight', 10, urwid.Filler(self.bottom_string, 'top')) self.default_widget = urwid.LineBox( urwid.Pile([ self.large_blinks ]), title='Websockets' )
def __init__(self, *args, **kwargs): self.start = urwid.Edit('Start: ') self.end = urwid.Edit('End: ') self.server = kwargs["server"] self.calendar = kwargs["calendar"] del(kwargs['server']) del(kwargs["calendar"]) print (self.server, self.calendar) div = urwid.Divider() self.msg = urwid.Edit(caption="Event message: ", edit_text='', multiline=True) button_save = urwid.Button('save') urwid.connect_signal(button_save, 'click', self.on_save) self.pile = urwid.Pile([self.start, self.end, div, self.msg, div, button_save]) super(EventWidget, self).__init__(self.pile, *args, **kwargs)
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, pubpen): self.pubpen = pubpen username_label = urwid.Text('Username: ', align='right') password_label = urwid.Text('Password: ', align='right') self.username = urwid.Edit() self.password = urwid.Edit() login_button = urwid.Button('Login') decorated_login_button = urwid.AttrMap(login_button, None, focus_map='reversed') quit_button = urwid.Button('Quit') decorated_quit_button = urwid.AttrMap(quit_button, None, focus_map='reversed') buttons = urwid.Columns(( (len('Login') + 4, decorated_login_button), (len('Quit') + 4, decorated_quit_button), ), focus_column=1) labels = urwid.Pile([username_label, password_label]) self.fields = urwid.Pile([self.username, self.password, buttons], focus_item=0) entry_box = urwid.Columns([labels, self.fields]) self.status_message = urwid.Text(' ', align='center') entry_with_status = urwid.Pile([entry_box, self.status_message]) padded_entry_with_status = urwid.Padding(entry_with_status, align='center') self.display = urwid.Filler(padded_entry_with_status, valign='middle') decorate = urwid.LineBox(self.display) super().__init__(decorate) self.focusable_widgets = (w for w in itertools.cycle(( ((self.fields, 1),), ((self.fields, 2), (buttons, 0)), ((self.fields, 2), (buttons, 1)), ((self.fields, 0),) ))) urwid.connect_signal(login_button, 'click', self.attempt_login) urwid.connect_signal(quit_button, 'click', self.quit) self.pubpen.subscribe('user.login_success', self.handle_login_success) self.pubpen.subscribe('user.login_failure', self.handle_login_failure)
def __init__(self, pubpen): self.pubpen = pubpen # # Always displayed widgets # self.menu_bar_window = MenuBarWindow(self.pubpen) self.info_window = InfoWindow(self.pubpen) self.main_window = MainWindow(self.pubpen) self.msg_window = MessageWindow(self.pubpen) pile = urwid.Pile((self.main_window, (self.msg_window.height, self.msg_window), )) cols = urwid.Columns((pile, (15, self.info_window))) layout = urwid.Pile(( ('pack', self.menu_bar_window), ('weight', 1, cols), )) self.top = urwid.Frame(layout) super().__init__(self.top) tline = self.tline_widget[0] self.status_bar = StatusBar(self.pubpen, spacer=tline.div_char) self.tline_widget.contents.clear() self.tline_widget.contents.extend(( (tline, self.tline_widget.options('given', 1, False)), (self.status_bar, self.tline_widget.options('weight', 1, False)), (tline, self.tline_widget.options('given', 1, False)), ))
def __init__(self, app, title, current_key, values): self.app = app rows = [] self.key = None self.value = None for key, value in values(): button = SearchSelectInnerButton(key, value) urwid.connect_signal(button, 'click', lambda b:self.onSelected(b)) rows.append(button) pile = urwid.Pile(rows) fill = urwid.Filler(pile, valign='top') super(SearchSelectDialog, self).__init__(urwid.LineBox(fill, title))
def __init__(self, app): self.app = app save_button = mywid.FixedButton(u'Save') cancel_button = mywid.FixedButton(u'Cancel') urwid.connect_signal(save_button, 'click', lambda button:self._emit('save')) urwid.connect_signal(cancel_button, 'click', lambda button:self._emit('cancel')) rows = [] buttons = [('pack', save_button), ('pack', cancel_button)] buttons = urwid.Columns(buttons, dividechars=2) self.project_button = ProjectButton(self.app) self.status_button = StatusButton(self.app) self.assignee_button = AssigneeButton(self.app) self.title_field = mywid.MyEdit(u'', edit_text=u'', ring=app.ring) for (label, w) in [ (u'Project:', ('pack', self.project_button)), (u'Title:', self.title_field), (u'Status:', ('pack', self.status_button)), (u'Assignee:', ('pack', self.assignee_button)), ]: row = urwid.Columns([(12, urwid.Text(label)), w]) rows.append(row) rows.append(urwid.Divider()) rows.append(buttons) pile = urwid.Pile(rows) fill = urwid.Filler(pile, valign='top') super(NewTaskDialog, self).__init__(urwid.LineBox(fill, 'New Task'))
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, app, board_key): super(BoardView, self).__init__(urwid.Pile([])) self.log = logging.getLogger('boartty.view.board') self.searchInit() self.app = app self.board_key = board_key self.worklist_keys = set() self.title_label = urwid.Text(u'', wrap='clip') self.description_label = urwid.Text(u'') board_info = [] board_info_map={'story-data': 'focused-story-data'} for l, v in [("Title", self.title_label), ("Description", self.description_label), ]: row = urwid.Columns([(12, urwid.Text(('story-header', l), wrap='clip')), v]) board_info.append(row) board_info = urwid.Pile(board_info) self.listbox = urwid.ListBox(urwid.SimpleFocusListWalker([])) self._w.contents.append((self.app.header, ('pack', 1))) self._w.contents.append((urwid.Divider(), ('pack', 1))) self._w.contents.append((self.listbox, ('weight', 1))) self._w.set_focus(2) self.listbox.body.append(board_info) self.listbox.body.append(urwid.Divider()) self.listbox_board_start = len(self.listbox.body) lane_columns = urwid.Columns([], dividechars=1) self.listbox.body.append(lane_columns) self.lane_manager = mywid.ListUpdateManager(lane_columns) self.refresh() self.listbox.set_focus(1)
def makeFrame(self, data): """ Returns a new frame that is formatted correctly with respect to the window's dimensions. :param data: tuple of (answers, question_title, question_desc, question_stats, question_url) :return: a new urwid.Frame object """ answers, question_title, question_desc, question_stats, question_url = data self.data = data self.question_desc = question_desc self.url = question_url self.answer_text = AnswerText(answers) self.screenHeight, screenWidth = subprocess.check_output(['stty', 'size']).split() self.question_text = urwid.BoxAdapter(QuestionDescription(question_desc), int(max(1, (int(self.screenHeight) - 9) / 2))) answer_frame = urwid.Frame( header= urwid.Pile( [ header_for_display, QuestionTitle(question_title), self.question_text, QuestionStats(question_stats), urwid.Divider('-') ]), body=self.answer_text, footer= urwid.Pile([ QuestionURL(question_url), UnicodeText(u'\u2191: previous answer, \u2193: next answer, o: open in browser, \u2190: back') ]) ) return answer_frame
def set_answer(self): """ We must use a box adapter to get the text to scroll when this widget is already in a Pile from the main question page. Scrolling is necessary for long answers which are longer than the length of the terminal. """ self.content = [('less-important', 'Answer: ')] + self.answers[self.index].split("\n") self._w = ScrollableTextBox(self.content)
def set_description(self): """ We must use a box adapter to get the text to scroll when this widget is already in a Pile from the main question page. Scrolling is necessary for long questions which are longer than the length of the terminal. """ self.content = self.description.strip("\n").split("\n") self._w = ScrollableTextBox(self.content)
def __init__(self, discord_client, chat_widget): self.discord = discord_client self.ui = self.discord.ui self.chat_widget = chat_widget self.editing = None self.edit = urwid.Edit(multiline=True, allow_tab=True) self.edit.keypress = self._edit_keypress self.w_lb = urwid.LineBox(urwid.Padding(self.edit, left=1, right=1)) self.w_text = urwid.Text("") self.w_typing = TypingList(self) self.pile = urwid.Pile([]) self.hide_channel_selector() self.__super.__init__(self.pile)