Beispiel #1
0
 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)
Beispiel #2
0
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())
Beispiel #3
0
    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 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')
Beispiel #5
0
 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)
Beispiel #6
0
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
Beispiel #7
0
 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)
Beispiel #8
0
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()
Beispiel #9
0
 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,
     )
Beispiel #10
0
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
Beispiel #11
0
 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,
     )
Beispiel #12
0
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
Beispiel #13
0
 def show_shutdown_dialog(self, exit_code):
     self.frame.body = Overlay(ShutdownView(exit_code), self.frame.body,
                               'center', ('relative', 45), 'middle', 'pack')
Beispiel #14
0
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())
Beispiel #15
0
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()