def __init__(self, underlying, unlock): self.unlock = unlock self.password = Edit("Password: "******"") w = ListBox([Text(self.LOCKED), self.invalid, self.password]) w = LineBox(w) w = AttrWrap(w, "dialog") Overlay.__init__(self, w, underlying, 'center', 60, 'middle', 8)
def __init__(self, name, named_grid_elements: list, callback: Callable): self.name = name self.named_widgets = {} unnamed_grid_elements = [] for row in named_grid_elements: self.named_widgets.update(row) unnamed_grid_elements.append(list(row.values())) confirm = Button("Confirm", "confirm_button", self.__confirm) abort = Button("Abort", "abort_button", self.__quit) unnamed_grid_elements.append([confirm, abort]) super().__init__(unnamed_grid_elements) self.keybind["f1"] = self.keybind["ctrl x"] = self.__confirm self.keybind["f5"] = self.keybind["ctrl g"] = self.__quit self.on_submit = callback bottom = Filler(self, valign="top") popup = AttrWrap( Filler(Text("Work in progress...\n\nPlease wait.", "center")), "popup") self.overlay = Overlay(popup, bottom, "center", 30, "middle", 5) self.root = WidgetPlaceholder(bottom)
def keypress(self, size, key): if key == 'tab': if self.lb.get_focus()[0] == self.buttons: self.keypress(size, 'page up') else: self.keypress(size, 'page down') return Overlay.keypress(self, size, key)
def show_overlay(self, overlay_widget, **kw): args = dict( align='center', width=('relative', 60), min_width=80, valign='middle', height='pack' ) PADDING = 3 # Don't expect callers to account for the padding if # they pass a fixed width. if 'width' in kw: if isinstance(kw['width'], int): kw['width'] += 2*PADDING args.update(kw) top = Pile([ ('pack', Text("")), Columns([ (PADDING, Text("")), overlay_widget, (PADDING, Text("")) ]), ('pack', Text("")), ]) self._w = Overlay(top_w=top, bottom_w=disabled(self._w), **args)
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 show_overlay(self, overlay_widget, **kw): self.orig_w = self._w args = dict(align='center', width=('relative', 60), min_width=80, valign='middle', height='pack') args.update(kw) self._w = Overlay(top_w=overlay_widget, bottom_w=self._w, **args)
def show_overlay(self, overlay_widget): self.orig_w = self._w self._w = Overlay(top_w=overlay_widget, bottom_w=self._w, align='center', width=('relative', 60), min_width=80, valign='middle', height='pack')
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 _build_overlay_widget(self, top_w, align, width, valign, height, min_width, min_height): return Overlay(top_w=Filler(top_w), bottom_w=self.frame, align=align, width=width, valign=valign, height=height, min_width=width, min_height=height)
def keypress(self, size, key): if key == 'enter': if pegasus.OPENSTACK_PASSWORD is None: self.invalid.set_text(self.IOERROR) elif pegasus.OPENSTACK_PASSWORD == self.password.get_edit_text(): self.unlock() else: self.invalid.set_text(self.INVALID) self.password.set_edit_text("") else: return Overlay.keypress(self, size, key)
def show_map(_map): lines = shutil.get_terminal_size()[1] # число строк в окне main_widget.original_widget = Overlay( _map, box, align="center", width=(game.mazeclass.width * 2 + 5), height=int(lines * 0.9) if game.mazeclass.height > lines * 0.9 else game.mazeclass.height + 4, valign="middle") button_power.overlay = 1
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, underlying, command_runner): self.underlying = underlying self.command_runner = command_runner self.done = False self.machine = None self.deployed_charm_classes = [] self.finalized_charm_classes = [] self.single_net_configured = False self.lxc_root_tarball_configured = False self.info_text = Text(self.NODE_WAIT if pegasus.SINGLE_SYSTEM else self.PXE_BOOT) w = LineBox(Filler(self.info_text)) w = AttrWrap(w, "dialog") Overlay.__init__(self, w, self.underlying, 'center', 60, 'middle', 5)
def __init__(self, underlying, juju_state, destroy, command_runner=None): import cloudinstall.charms charm_modules = [import_module('cloudinstall.charms.' + mname) for (_, mname, _) in pkgutil.iter_modules(cloudinstall.charms.__path__)] charm_classes = [m.__charm_class__ for m in charm_modules if m.__charm_class__.allow_multi_units] self.cr = command_runner self.underlying = underlying self.destroy = destroy self.boxes = [] self.bgroup = [] first_index = 0 for i, charm_class in enumerate(charm_classes): charm = charm_class(juju_state=juju_state) if charm.name() and not first_index: first_index = i r = RadioButton(self.bgroup, charm.name()) r.text_label = charm.name() self.boxes.append(r) self.count_editor = IntEdit("Number of units to add: ", 1) self.boxes.append(self.count_editor) wrapped_boxes = _wrap_focus(self.boxes) bs = [Button("Ok", self.yes), Button("Cancel", self.no)] wrapped_buttons = _wrap_focus(bs) self.buttons = Columns(wrapped_buttons) self.items = ListBox(wrapped_boxes) self.items.set_focus(first_index) ba = BoxAdapter(self.items, height=len(wrapped_boxes)) self.lb = ListBox([ba, Text(""), self.buttons]) self.w = LineBox(self.lb, title="Add unit") self.w = AttrMap(self.w, "dialog") Overlay.__init__(self, self.w, self.underlying, 'center', 45, 'middle', len(wrapped_boxes) + 4)
def __init__(self, underlying, juju_state, on_success, on_cancel): import cloudinstall.charms charm_modules = [import_module('cloudinstall.charms.' + mname) for (_, mname, _) in pkgutil.iter_modules(cloudinstall.charms.__path__)] charm_classes = sorted([m.__charm_class__ for m in charm_modules], key=attrgetter('deploy_priority')) self.boxes = [] first_index = 0 for i, charm_class in enumerate(charm_classes): charm = charm_class(juju_state=juju_state) if charm.name() and not first_index: first_index = i r = CheckBox(charm.name()) r.text_label = charm.name() self.boxes.append(r) wrapped_boxes = _wrap_focus(self.boxes) def ok(button): selected = filter(lambda r: r.get_state(), self.boxes) on_success([s.text_label for s in selected]) def cancel(button): on_cancel() bs = [Button("Ok", ok), Button("Cancel", cancel)] wrapped_buttons = _wrap_focus(bs) self.buttons = Columns(wrapped_buttons) self.items = ListBox(wrapped_boxes) self.items.set_focus(first_index) ba = BoxAdapter(self.items, height=len(wrapped_boxes)) self.lb = ListBox([ba, self.count_editor, self.buttons]) root = LineBox(self.lb, title="Select new charm") root = AttrMap(root, "dialog") Overlay.__init__(self, root, underlying, 'center', 30, 'middle', len(wrapped_boxes) + 4)
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 show_copybook(body): listbox = ListBox([*body]) main_widget.original_widget = Overlay(LineBox(listbox), box, align="center", width=62, height=31, valign="middle") #меняем фокус на последний зарисованный участок лабиринта listbox.change_focus((20, 20), len(body) - 1, offset_inset=0, coming_from=None, cursor_coords=None, snap_rows=None) button_power.overlay = 1
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()
def show_shutdown_dialog(self, exit_code): self.frame.body = Overlay(ShutdownView(exit_code), self.frame.body, 'center', ('relative', 45), 'middle', 'pack')
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: f.write(line.rstrip())