Exemple #1
0
    def __init__(self) -> None:
        self.cmder_input = TextArea(
            height=1, multiline=False, wrap_lines=False, style="class:normal"
        )
        self.input = self.cmder_input

        self.status_bar = Label("Loading status bar...", style="class:status")

        self.console = Frame(
            TextArea(plover_text, focusable=False),
            title="Console",
            style="class:normal",
        )

        self.tape = Tape()
        self.suggestions = Suggestions()

        self.outputs = [self.console]

        self.container = HSplit(
            [
                DynamicContainer(lambda: VSplit(self.outputs)),
                DynamicContainer(lambda: self.input),
                self.status_bar,
            ]
        )
Exemple #2
0
    def __init__(self, manager: mp.Manager, shared_state: dict, rpc_channel: mp.Queue):
        self.manager = manager
        self.shared_state = shared_state
        self.rpc_channel = rpc_channel

        self.fileman = Filemanager(self)
        self.fileman_visible = True

        self.toolbar = Toolbar(self)

        self.views = OrderedDict()  # type: Dict[str, SimpleView]

        self.app = Application(
            full_screen=True,
            mouse_support=True,
            color_depth=ColorDepth.DEPTH_24_BIT,
            clipboard=InMemoryClipboard(),
            enable_page_navigation_bindings=False,
            # key_bindings=get_filemanager_kb()
            layout=Layout(
                container=HSplit([
                    DynamicContainer(self._get_children),
                    DynamicContainer(lambda: self.toolbar)
                ]),
                # focused_element=(self.current_view or self.fileman).input_field,
            ),
        )
Exemple #3
0
    def process_steps(self):
        if self.intro:
            layout = Window(
                FormattedTextControl(to_formatted_text(HTML(self.intro))),
                wrap_lines=True,
            )
            self.steps.append(
                {
                    'layout': layout,
                    'label': 'Introduction',
                    'handler': None,
                }, )

        for handler in self.handlers:
            layout = handler.get_layout()
            layout.align = HorizontalAlign.JUSTIFY
            self.steps.append(
                {
                    'layout': layout,
                    'label': handler.get_label(),
                    'handler': handler,
                }, )

        if self.summary:
            layout = Box(
                body=DynamicContainer(self.get_summary),
                padding=D(preferred=1, max=1),
                padding_bottom=1,
            )
            self.steps.append(
                {
                    'layout': layout,
                    'label': 'Summary',
                    'handler': None,
                }, )
Exemple #4
0
    def init_layout(self):
        for i in range(len(self.top_screens)):
            s = self.top_screens[i]
            s.app = self
            s.screen_idx = i
            self.screen_sel_buttons.append(
                Button(text="%s %s" % (s.shortcut.upper(), s.shortcut_label),
                       handler=s.screen_sel))

        self.lbl_screen = Label(text=self.top_screens[0].title)

        self.top_screen = DynamicContainer(self.get_top_screen_container)

        btn_action = Button(text="F8 Action", handler=self.f_action)
        btn_exit = Button(text="F10 Exit", handler=self.f_exit)

        self.root_container = FloatContainer(
            HSplit([
                Box(
                    body=VSplit([self.lbl_screen], align="CENTER", padding=3),
                    style="class:button-bar",
                    height=1,
                ),
                self.top_screen,
                Box(
                    body=VSplit(self.screen_sel_buttons +
                                [btn_action, btn_exit],
                                align="CENTER",
                                padding=3),
                    style="class:button-bar",
                    height=1,
                ),
            ]), self.floats)
        self.top_layout = Layout(self.root_container,
                                 focused_element=self.screen_sel_buttons[0])
Exemple #5
0
    def __init__(self,
                 body: AnyContainer,
                 title: AnyFormattedText = '',
                 buttons: Optional[Sequence[Button]] = None,
                 modal: bool = True,
                 width: AnyDimension = None,
                 with_background: bool = False) -> None:

        self.body = body
        self.title = title

        buttons = buttons or []

        # When a button is selected, handle left/right key bindings.
        buttons_kb = KeyBindings()
        if len(buttons) > 1:
            first_selected = has_focus(buttons[0])
            last_selected = has_focus(buttons[-1])

            buttons_kb.add('left', filter=~first_selected)(focus_previous)
            buttons_kb.add('right', filter=~last_selected)(focus_next)

        frame_body: AnyContainer
        if buttons:
            frame_body = HSplit([
                # Add optional padding around the body.
                Box(body=DynamicContainer(lambda: self.body),
                    padding=D(preferred=1, max=1),
                    padding_bottom=0),
                # The buttons.
                Box(body=VSplit(buttons, padding=1, key_bindings=buttons_kb),
                    height=D(min=1, max=3, preferred=3))
            ])
        else:
            frame_body = body

        # Key bindings for whole dialog.
        kb = KeyBindings()
        kb.add('tab', filter=~has_completions)(focus_next)
        kb.add('s-tab', filter=~has_completions)(focus_previous)

        frame = Shadow(body=Frame(
            title=lambda: self.title,
            body=frame_body,
            style='class:dialog.body',
            width=(None if with_background is None else width),
            key_bindings=kb,
            modal=modal,
        ))

        self.container: Union[Box, Shadow]
        if with_background:
            self.container = Box(
                body=frame,
                style='class:dialog',
                width=width)
        else:
            self.container = frame
Exemple #6
0
    def __init__(self, view):
        self.view = view
        self.cwd: Path = Path('./').resolve()
        self.cancel_button = Button(text="Exit", handler=self.exit_handler)

        self.filelist = FileList(self, view.new_view)

        self.window = Dialog(
            title="Browse files",
            body=DynamicContainer(
                lambda: HSplit([
                    Label(text=f"Dir: {self.cwd}", dont_extend_height=True),
                    self.filelist,
                ],
                               padding=D(preferred=1, max=1))),
            buttons=[self.cancel_button],
            with_background=True)
Exemple #7
0
    def __init__(
        self,
        body: AnyContainer,
        title: AnyFormattedText = "",
        style: str = "",
        width: AnyDimension = None,
        height: AnyDimension = None,
        key_bindings: Optional[KeyBindings] = None,
        modal: bool = False,
    ) -> None:

        self.title = title
        self.body = body

        fill = partial(Window, style="class:frame.border")
        style = "class:frame " + style

        top_row_with_title = VSplit(
            [
                fill(width=1, height=1, char="├"),
                fill(char=Border.HORIZONTAL),
                # Notice: we use `Template` here, because `self.title` can be an
                # `HTML` object for instance.
                Label(
                    lambda: Template(" {} ").format(self.title),
                    style="class:frame.label",
                    dont_extend_width=True,
                ),
                fill(char=Border.HORIZONTAL),
                fill(width=1, height=1, char="┤"),
            ],
            height=1,
        )

        top_row_without_title = VSplit(
            [
                fill(width=1, height=1, char=Border.TOP_LEFT),
                fill(char=Border.HORIZONTAL),
                fill(width=1, height=1, char=Border.TOP_RIGHT),
            ],
            height=1,
        )

        @Condition
        def has_title() -> bool:
            return bool(self.title)

        self.container = HSplit(
            [
                ConditionalContainer(content=top_row_with_title,
                                     filter=has_title),
                ConditionalContainer(content=top_row_without_title,
                                     filter=~has_title),
                VSplit(
                    [
                        fill(width=1, char=Border.VERTICAL),
                        DynamicContainer(lambda: self.body),
                        fill(width=1, char=Border.VERTICAL),
                        # Padding is required to make sure that if the content is
                        # too small, the right frame border is still aligned.
                    ],
                    padding=0,
                ),
            ],
            width=width,
            height=height,
            style=style,
            key_bindings=key_bindings,
            modal=modal,
        )
Exemple #8
0
    def __init__(  # noqa: CCR001
        self,
        title,
        handlers,
        intro=None,
        summary=False,
        next_text='Next',
        previous_text='Previous',
        cancel_text='Cancel',
        finish_text='Finish',
    ):
        self.title = title
        self.handlers = handlers
        self.answers = {}
        self.intro = intro
        self.summary = summary
        self.steps = []
        self.current_step_idx = 0
        self.title = title
        self.process_steps()
        self.current_step = self.steps[self.current_step_idx]
        self.label_next = next_text
        self.label_previous = previous_text
        self.label_cancel = cancel_text
        self.label_finish = finish_text
        self.error_messages = ''

        self.cancel_btn = Button(
            text=self.label_cancel,
            handler=self.cancel,
        )
        self.previous_btn = Button(
            text=self.label_previous,
            handler=self.previous,
        )
        self.next_btn = Button(
            text=self.label_next if len(self.steps) > 1 else self.label_finish,
            handler=self.next,
        )

        self.buttons = [self.next_btn, self.cancel_btn]

        self.buttons_kb = KeyBindings()
        first_selected = has_focus(self.buttons[0])
        last_selected = has_focus(self.buttons[-1])

        self.buttons_kb.add('left', filter=~first_selected)(focus_previous)
        self.buttons_kb.add('right', filter=~last_selected)(focus_next)

        input_container = HSplit([
            Box(
                body=DynamicContainer(self.get_current_step_container),
                padding=D(preferred=1, max=1),
                padding_bottom=0,
            ),
        ], )

        left_container = Box(
            body=DynamicContainer(self.get_steps_labels),
            padding=D(preferred=1, max=1),
            padding_bottom=0,
        )
        right_container = HSplit([
            input_container,
            Box(
                body=DynamicContainer(self.get_status),
                padding=D(preferred=1, max=1),
                padding_bottom=1,
            ),
        ], )
        top_container = VSplit(
            [left_container, right_container],
            padding_char='│',
            padding=1,
            padding_style='#000000',
            height=D(min=10, preferred=24),
        )

        buttons_container = Box(
            body=DynamicContainer(self.get_buttons_container),
            height=D(min=1, max=3, preferred=3),
        )

        kb = KeyBindings()
        kb.add(Keys.Tab)(focus_next)
        kb.add(Keys.BackTab)(focus_previous)

        frame = Shadow(body=Frame(
            title=self.get_title,
            body=HSplit(
                [
                    top_container,
                    buttons_container,
                ],
                padding_char='─',
                padding=1,
                padding_style='#000000',
            ),
            style='class:dialog.body',
            key_bindings=kb,
            width=D(min=78, preferred=132),
        ), )
        self.container = Box(
            body=frame,
            style='class:dialog',
        )
Exemple #9
0
                       content=FormattedTextControl(""),
                       align=WindowAlign.LEFT)

root_container = HSplit([
    # The titlebar.
    Window(
        height=1,
        content=FormattedTextControl(get_titlebar_text),
        align=WindowAlign.CENTER,
    ),
    # Horizontal separator.
    Window(height=1, char="-", style="class:line"),
    # The 'body', like defined above.
    body,
    Window(height=1, char=".", style="class:line"),
    DynamicContainer(lambda: prompt_window),
])

# Key bindings
kb = KeyBindings()
kb_exit = KeyBindings()
kb_escape = KeyBindings()


@kb_exit.add("c-c", eager=True)
@kb_exit.add("c-q", eager=True)
def _(event):
    """
    Pressing Ctrl-Q or Ctrl-C will exit the user interface.
    """
    event.app.exit()
Exemple #10
0
    def __init__(self,
                 body,
                 title='',
                 style='',
                 width=None,
                 height=None,
                 key_bindings=None,
                 modal=False):
        assert is_container(body)
        assert is_formatted_text(title)
        assert isinstance(style, six.text_type)
        assert is_dimension(width)
        assert is_dimension(height)
        assert key_bindings is None or isinstance(key_bindings, KeyBindings)
        assert isinstance(modal, bool)

        self.title = title
        self.body = body

        fill = partial(Window, style='class:frame.border')
        style = 'class:frame ' + style

        top_row_with_title = VSplit(
            [
                fill(width=1, height=1, char=Border.TOP_LEFT),
                fill(char=Border.HORIZONTAL),
                fill(width=1, height=1, char='|'),
                # Notice: we use `Template` here, because `self.title` can be an
                # `HTML` object for instance.
                Label(lambda: Template(' {} ').format(self.title),
                      style='class:frame.label',
                      dont_extend_width=True),
                fill(width=1, height=1, char='|'),
                fill(char=Border.HORIZONTAL),
                fill(width=1, height=1, char=Border.TOP_RIGHT),
            ],
            height=1)

        top_row_without_title = VSplit([
            fill(width=1, height=1, char=Border.TOP_LEFT),
            fill(char=Border.HORIZONTAL),
            fill(width=1, height=1, char=Border.TOP_RIGHT),
        ],
                                       height=1)

        @Condition
        def has_title():
            return bool(self.title)

        self.container = HSplit(
            [
                ConditionalContainer(content=top_row_with_title,
                                     filter=has_title),
                ConditionalContainer(content=top_row_without_title,
                                     filter=~has_title),
                VSplit(
                    [
                        fill(width=1, char=Border.VERTICAL),
                        DynamicContainer(lambda: self.body),
                        fill(width=1, char=Border.VERTICAL),
                        # Padding is required to make sure that if the content is
                        # too small, that the right frame border is still aligned.
                    ],
                    padding=0),
                VSplit([
                    fill(width=1, height=1, char=Border.BOTTOM_LEFT),
                    fill(char=Border.HORIZONTAL),
                    fill(width=1, height=1, char=Border.BOTTOM_RIGHT),
                ]),
            ],
            width=width,
            height=height,
            style=style,
            key_bindings=key_bindings,
            modal=modal)
Exemple #11
0
 def __init__(self, state, Screen):
     self._Screen = Screen
     self._container = DynamicContainer(lambda: self._current_screen)
     self.set_state(state)
    " Pressing PageDown will scroll the console window. "
    layout.scroll_down()


@kb.add("pageup")
def _(event):
    " Pressing PageUp will scroll the console window. "
    layout.scroll_up()


def create_style(fg=None, bg=None) -> Style:
    styles = ""
    # plover.cfg doesn't know that "None" is None
    if fg and fg != "None":
        styles += f"fg:{fg} "
    if bg and bg != "None":
        styles += f"bg:{bg}"
    return Style.from_dict({
        "status": f"{styles} reverse",
        "normal": f"{styles}"
    })


application = Application(
    layout=Layout(DynamicContainer(layout), focused_element=layout.input),
    key_bindings=kb,
    mouse_support=False,
    full_screen=True,
    enable_page_navigation_bindings=False,
)