def __init__(self, original_widget, title=''): self.color = 'header' if int(urwid_version[0]) == 1: utf8decode = lambda string: string def use_attr(a, t): if a: t = AttrMap(t, a) return t # top line tline = None tline_attr = Columns([ ('fixed', 2, Divider(utf8decode("─"))), ('fixed', len(title), AttrMap(Text(title), self.color)), Divider(utf8decode("─")), ]) tline = use_attr(tline, tline_attr) # bottom line bline = None bline = use_attr(bline, Divider(utf8decode("─"))) # left line lline = None lline = use_attr(lline, SolidFill(utf8decode("│"))) # right line rline = None rline = use_attr(rline, SolidFill(utf8decode("│"))) # top left corner tlcorner = None tlcorner = use_attr(tlcorner, Text(utf8decode("┌"))) # top right corner trcorner = None trcorner = use_attr(trcorner, Text(utf8decode("┐"))) # bottom left corner blcorner = None blcorner = use_attr(blcorner, Text(utf8decode("└"))) # bottom right corner brcorner = None brcorner = use_attr(brcorner, Text(utf8decode("┘"))) # top top = Columns([ ('fixed', 1, tlcorner), tline, ('fixed', 1, trcorner), ]) # middle middle = Columns([('fixed', 1, lline), original_widget, ('fixed', 1, rline)], box_columns=[0, 2], focus_column=1) # bottom bottom = Columns([('fixed', 1, blcorner), bline, ('fixed', 1, brcorner)]) # widget decoration pile = Pile([('flow', top), middle, ('flow', bottom)], focus_item=1) WidgetDecoration.__init__(self, original_widget) WidgetWrap.__init__(self, pile)
def __init__(self, original_widget, title="", tlcorner=u'┌', tline=u'─', lline=u'│', trcorner=u'┐', blcorner=u'└', rline=u'│', bline=u'─', brcorner=u'┘'): """ Use 'title' to set an initial title text with will be centered on top of the box. You can also override the widgets used for the lines/corners: tline: top line bline: bottom line lline: left line rline: right line tlcorner: top left corner trcorner: top right corner blcorner: bottom left corner brcorner: bottom right corner """ tline, bline = Divider(tline), Divider(bline) lline, rline = SolidFill(lline), SolidFill(rline) tlcorner, trcorner = Text(tlcorner), Text(trcorner) blcorner, brcorner = Text(blcorner), Text(brcorner) title_widget = ('fixed', len(title), AttrMap(Text(title), 'header')) top = Columns([ ('fixed', 1, tlcorner), title_widget, tline, ('fixed', 1, trcorner) ]) middle = Columns([('fixed', 1, lline), original_widget, ('fixed', 1, rline)], box_columns=[0, 2], focus_column=1) bottom = Columns([('fixed', 1, blcorner), bline, ('fixed', 1, brcorner)]) pile = Pile([('flow', top), middle, ('flow', bottom)], focus_item=1) # super? WidgetDecoration.__init__(self, original_widget) WidgetWrap.__init__(self, pile)
def menu(): hello = Text( "Приветствую! Для продолжения настройте параметры лабиринта.\n" + "Если карта лабиринта будет некорректно отображаться, " + "попробуйте уменьшить значение ширины или развернуть окно.") height_enter = IntEdit("Высота лабиринта: ", 30) width_enter = IntEdit("Ширина лабиринта: ", 45) done = Button("Готово") done_pad = Padding(done, align="center", width=10) back = AttrMap(SolidFill("\u25E6"), "blueprint") pile = Pile( [hello, Divider("\u2500"), height_enter, width_enter, done_pad]) menu = Filler(LineBox(pile)) main_widget = Overlay(menu, back, align="center", width=35, height=12, valign="middle") loop = MainLoop(main_widget, palette) connect_signal(done, 'click', start_game) loop.run() return MazeGame(height_enter.value(), width_enter.value())
def _construct_line(self, pos): """ builds a list element for given position in the tree. It consists of the original widget taken from the TreeWalker and some decoration columns depending on the existence of parent and sibling positions. The result is a urwid.Culumns widget. """ void = SolidFill(' ') line = None if pos is not None: cols = [] depth = self._walker.depth(pos) # add spacer filling all but the last indent if depth > 0: cols.append( (depth * self._indent, urwid.SolidFill(' '))), # spacer # construct last indent iwidth, icon = self._construct_collapse_icon(pos) available_space = self._indent firstindent_width = self._icon_offset + iwidth # stop if indent is too small for this decoration if firstindent_width > available_space: raise TreeDecorationError(NO_SPACE_MSG) # add icon only for non-leafs if self._walker.first_child_position(pos) is not None: if icon is not None: # space to the left cols.append( (available_space - firstindent_width, SolidFill(' '))) # icon icon_pile = urwid.Pile([('pack', icon), void]) cols.append((iwidth, icon_pile)) # spacer until original widget available_space = self._icon_offset cols.append((available_space, SolidFill(' '))) else: # otherwise just add another spacer cols.append((self._indent, SolidFill(' '))) cols.append(self._walker[pos]) # original widget ] # construct a Columns, defining all spacer as Box widgets line = urwid.Columns(cols, box_columns=range(len(cols))[:-1]) return line
def __init__(self, title, right_icon): if isinstance(title, str): title = Text(title) title = HeaderColumns([ Text(""), title, right_icon, Text(""), ]) super().__init__( Pile([ (1, Color.frame_header_fringe(SolidFill("\N{lower half block}"))), Color.frame_header(title), (1, Color.frame_header_fringe(SolidFill("\N{upper half block}"))), ]))
def start(config): """Start the application and handle user input. Blocks until the application exits.""" def item_chosen(button, server): global choice choice = server response = Text( [u'Connecting to: ', server.connection_string(), u'\n']) done = Button(u'Ok') urwid.connect_signal(done, 'click', exit_program) main.original_widget = Filler( Pile([response, AttrMap(done, None, focus_map='reversed')])) def exit_program(button): raise urwid.ExitMainLoop() def unhandled(key): vim_map = {'h': 'left', 'j': 'down', 'k': 'up', 'l': 'right'} if key in vim_map.keys(): list_box.keypress((0, 1), vim_map[key]) elif key in ['left', 'right']: pass elif key in ['esc', 'q']: raise ExitMainLoop() body = [urwid.Text(u'\nServers'), Divider(u'-')] for server in config.get_servers(): button = Button(server.name) urwid.connect_signal(button, 'click', item_chosen, server) body.append(AttrMap(button, None, focus_map='reversed')) list_box = ListBox(urwid.SimpleFocusListWalker(body)) main = Padding(list_box, left=2, right=2) overlay = Overlay(main, SolidFill(u'\N{MEDIUM SHADE}'), align='center', width=('relative', 60), valign='middle', height=('relative', 60), min_width=20, min_height=9) header = AttrMap(Text(u' ssh-menu'), 'header') footer = AttrMap(Text(u'this is the footer'), 'footer') frame = Frame(overlay, header=header, footer=footer) urwid.MainLoop(urwid.AttrMap(frame, 'body'), palette=palette, unhandled_input=unhandled).run() return choice
def main(): background = AttrMap(SolidFill(' '), 'basic') pwdialog = PasswordDialog().compose() box = AttrMap(LineBox(pwdialog), 'blackongrey') window = Overlay(box, background, 'center', 30, 'middle', 10) mainloop = MainLoop(window, unhandled_input=callback, palette=simple_colours) mainloop.run()
def mount_node_refactored(node): node.ui = WidgetPlaceholder(SolidFill()) node.opts = render_opts(node) logic = extract_logic(node.impl.get('html')) attach_logic_to_node(logic, node, node.opts) node.document.children('script').remove() identify_document(node.document) node.expressions = parse_document_expressions( node.document.children().eq(0)) update_node_refactored(node) node.trigger('mount')
def render_component(self, props): return Overlay( top_w=Menu(store=props['store']), bottom_w=SolidFill(u'\N{DARK SHADE}'), align=CENTER, width=(RELATIVE, 95), valign=MIDDLE, height=(RELATIVE, 95), min_width=20, min_height=20, )
def __init__(self, body=SolidFill(), header=None, footer=None, focus_part=None, unhandled_input=None, palette=None): self.document = Frame(body, header, footer, focus_part) self.loop = MainLoop( self.document, palette, event_loop=AsyncioEventLoop(loop=asyncio.get_event_loop()), unhandled_input=unhandled_input ) self.loop.screen.set_terminal_properties(colors=256) self.body = body self.footer = footer self.header = header
def render_component(self, props): return Overlay( top_w=Frame( header=AddTodo(store=props['store']), body=VisibleTodoList(store=props['store']), footer=Footer(store=props['store']), focus_part='header', ), bottom_w=SolidFill(u'\N{MEDIUM SHADE}'), align=CENTER, width=(RELATIVE, 40), valign=MIDDLE, height=(RELATIVE, 60), min_width=20, min_height=20, )
def set_step_banner(self, msg): if self.progress: del self.progress[:] self.progress.append(BoxAdapter(AttrMap(SolidFill('#'), 'fill'), 3))
text = Text("""Just start writing... The text will automatically align correctly. To exit, press Return.""") string = [] cursor = 0 if len(sys.argv) > 1: string = hilbert_to_str(sys.argv[1]) cursor = len(string) if len(string) > 1: text.set_text(str_to_hilbert(string)) elif len(string) == 1: text.set_text(''.join(string)) filler = SolidFill(" ") overlay = Overlay(Filler(text), filler, "center", 40, "middle", 40) main = MainLoop(overlay, unhandled_input=keystroke) main.run() print("Do you want to save the file? (Ctrl+C to abort)") try: default = sys.argv[1] if len(sys.argv) > 1 else "test.act" fn = input("Save as [{}]: ".format(default)) if not fn: fn = default with open(fn, "w") as f: if len(string) > 1: lines = str_to_hilbert(string).split("\n") for line in lines:
def parse_tag_from_node(node): return SolidFill()
import urwid as u from urwid import SolidFill def exit(key): if key in ('q','Q'): raise u.ExitMainLoop bt = u.BigText("Table Tennis", u.font.HalfBlock5x4Font()) #bt = u.Padding(bt,'center', width='clip') #bt = u.Filler(bt,'top') loop = u.MainLoop(SolidFill('*'),unhandled_input=exit) loop.run() ##palette = [ # ('title','dark cnyan','dark red'), # ('dam','yellow','light red'), # ('bg','light cyan','black')] # #placeholder = u.SolidFill() #loop = u.MainLoop(placeholder,palette,unhandled_input=exit) #bt = u.BigText("Table-Tennis", u.font.HalfBlock5x4Font()) #bt = u.padding(bt,'center',width = 'clip') #bt = u.Filler(bt, 'top') #loop.widget.original_widget = u.Filler(u.Pile([])) # #div = u.Divider() #damn = u.Attr(div,'dam') #pile = loop.widget.base_widget #for item in [placeholder,damn,bt]: # pile.contents.append((item.pile.options())) #loop.run()
from urwid import MainLoop, SolidFill, Filler, Pile, Overlay, LineBox interior = Filler(Pile([])) window = LineBox(interior, title='Choose enviroment') background = SolidFill(' ') body = Overlay(window, background, 'center', 30, 'middle', 10) main_loop = MainLoop(body) main_loop.run()