Ejemplo n.º 1
0
 def __init__(self,
              app=None,
              show=True,
              height=Dimension(preferred=60),
              width=Dimension(preferred=1)): #80?                 
     self.app = app
     self.show = show
     self.basename = None
     self.filename = None
     self.current_line = -1
     self.handle_source_change = False
     self.lexer = None
     self.buffer = Buffer(document=Document(),
                          multiline=True) # TODO: Intelligent readonly lambda
     self.control = BufferControl(self.buffer,
                                  focusable=True,
                                  lexer=DynamicLexer(lambda: self.lexer),
                                  focus_on_click=True)
     self.window = Window(content=self.control,
                          height=height,
                          width=width,
                          wrap_lines=False,
                          left_margins=[NumberedMargin()],
                          scroll_offsets = ScrollOffsets(top=5, bottom=40),
                          get_line_prefix=self._get_line_prefix)
     
     self.info = InfoLine(text='', width=240)
     self.container = ConditionalContainer(
         content=HSplit([self.info.get_ui(),
                         self.window]),
         filter=Condition(lambda: self.show))
Ejemplo n.º 2
0
 def _box(self, body):
     return Box(
         body=body,
         height=Dimension(min=1),
         width=Dimension(min=1, weight=4),
         padding=1,
     )
Ejemplo n.º 3
0
    def __init__(self):
        self.lira = LiraApp()
        self.lira.setup()

        self.content = ContentArea(self)
        self.status = StatusBar(self)

        self.menu = SidebarMenu(self)
        self.menu.reset(BooksList(self))

        self.container = HSplit(
            [
                VSplit(
                    [
                        self.menu,
                        self.content,
                    ],
                    padding=Dimension.exact(1),
                    padding_char="│",
                    padding_style=theme["separator"],
                ),
                self.status,
            ],
            padding=Dimension.exact(1),
            padding_char="─",
            padding_style=theme["separator"],
        )
        self.app = Application(
            layout=Layout(self.container),
            key_bindings=self.get_key_bindings(),
            mouse_support=True,
            full_screen=True,
            style=style,
            after_render=self._ready,
        )
Ejemplo n.º 4
0
 def __init__(self, tui):
     self.tui = tui
     self.lira = self.tui.lira
     self.container = List(
         title=self._get_title(),
         elements=self._get_elements(),
         get_bullet=self._get_bullet,
         allow_select=self.allow_select,
         width=Dimension(min=1),
         height=Dimension(min=1),
     )
Ejemplo n.º 5
0
    def __init__(
        self,
        state,
    ):
        self.state = state
        self.kb = KeyBindings()

        # layout components
        self.header_bar = FormattedTextControl(focusable=False, )
        self.input_buffer = Buffer(multiline=False, )
        self.input_buffer.on_text_changed += self.update_results
        self.results_control = SelectableList(text="")
        self.preview_bar = FormattedTextControl(focusable=False, )
        self.preview_buffer = BufferControl(
            input_processors=[TabsProcessor(tabstop=4, char1="", char2="")],
            focusable=False,
        )
        self.status_bar = FormattedTextControl()
        self.layout = Layout(
            HSplit([
                Window(self.header_bar, height=1, style="reverse"),
                Window(
                    BufferControl(self.input_buffer),
                    height=1,
                ),
                Window(self.results_control,
                       height=Dimension(**RESULTS_DIMENSION_DICT)),
                Window(self.preview_bar, height=1, style="reverse"),
                Window(
                    self.preview_buffer,
                    wrap_lines=True,
                    height=Dimension(**PREVIEW_DIMENSION_DICT),
                ),
                Window(self.status_bar, height=1, style="reverse"),
            ]), )
        self.reset_view()

        @self.kb.add("up")
        def _(event):
            self.results_control.index -= 1
            self.update_preview()

        @self.kb.add("down")
        def _(event):
            self.results_control.index += 1
            self.update_preview()

        @self.kb.add("enter")
        def _(event):
            self.select_collection()
            self.reset_view()
Ejemplo n.º 6
0
def main():
    # Create a big layout of many text areas, then wrap them in a `ScrollablePane`.
    root_container = Frame(
        ScrollablePane(
            HSplit([
                Frame(TextArea(text=f"label-{i}"), width=Dimension())
                for i in range(20)
            ]))
        # ScrollablePane(HSplit([TextArea(text=f"label-{i}") for i in range(20)]))
    )

    layout = Layout(container=root_container)

    # Key bindings.
    kb = KeyBindings()

    @kb.add("c-c")
    def exit(event) -> None:
        get_app().exit()

    kb.add("tab")(focus_next)
    kb.add("s-tab")(focus_previous)

    # Create and run application.
    application = Application(layout=layout, key_bindings=kb, full_screen=True)
    application.run()
Ejemplo n.º 7
0
    def preferred_width(self, max_available_width: int) -> Dimension:
        _min = 40
        preferred = 80
        if max_available_width / 2 >= 80:
            preferred = max_available_width / 2

        return Dimension(min=_min, preferred=preferred)
Ejemplo n.º 8
0
 def __init__(self, app=None, show=False, height=Dimension(preferred=5)):
     self.lexer = ThreadsLexer()
     scroll_offsets = ScrollOffsets(top=5, bottom=5)
     super(ThreadsWindow, self).__init__(app=app,
                                         show=show,
                                         title='[ Threads ]',
                                         scroll_offsets=scroll_offsets)
Ejemplo n.º 9
0
    def get_user_comment(self):
        """Modifies the display to add an area to enter a comment for a command

        Creates a BufferControl in a Frame and replaces the toolbar with the Frame

        #bug: the new toolbar is unable to get focus right away; it requires the user to click 
                in the area
        """
        self._savedLayout = self.layout
        self.disabled_bindings = True
        commentControl = BufferControl(
            Buffer(accept_handler=self._set_user_comment), focus_on_click=True)
        user_in_area = Frame(
            Window(
                commentControl,
                height=Dimension(max=1, weight=10000),
                dont_extend_height=True,
            ),
            title="Enter Comment (alt-Enter to submit)",
        )

        self.toolbar = user_in_area
        self.main_view = HSplit([self.body, self.toolbar], padding_char="-")
        self.layout = Layout(self.main_view, focused_element=user_in_area.body)
        self.layout.focus(user_in_area.body)
        self.invalidate()
Ejemplo n.º 10
0
    def __init__(self,
                 app=None,
                 show=False,
                 title='[ A Window ]',
                 show_divider=lambda:True,
                 get_lexer=lambda: None,
                 height=Dimension(preferred=1),
                 wrap_lines=False,
                 scroll_offsets=ScrollOffsets()):
        self.app = app
        self.show = show
        self.buffer = Buffer(document=Document(),
                             multiline=True)
        self.control = BufferControl(buffer=self.buffer,
                                     focusable=True,
                                     lexer=self.lexer,
                                     focus_on_click=True)
        self.window = PromptWindow(content=self.control,
                                   height=height,
                                   wrap_lines=wrap_lines,
                                   scroll_offsets=scroll_offsets)

        self.divider = Divider(self, show=show_divider)
        self.info = InfoLine(title, width=240)
        self.container = ConditionalContainer(
            content=VSplit([
                self.divider.get_ui(),
                HSplit([self.info.get_ui(), self.window])]),
            filter=Condition(lambda: self.show))
Ejemplo n.º 11
0
 def __init__(self, app=None, show=False, height=Dimension(preferred=20)):
     self.frame = None
     self.lexer = CallstackLexer()
     scroll_offsets = ScrollOffsets(top=5, bottom=5)
     super(CallstackWindow, self).__init__(app=app,
                                           show=show,
                                           title='[ Callstack ]',
                                           scroll_offsets=scroll_offsets)
Ejemplo n.º 12
0
 def __init__(self, tui):
     super().__init__(tui)
     self.list = DynamicContainer(self.get_container)
     self.back_button = ConditionalContainer(
         Button("Back", handler=self.pop),
         filter=Condition(lambda: len(self.pages) > 1),
     )
     self.exit_button = Button("Exit", handler=exit_app)
     self.container = HSplit(
         [
             self.list,
             self.back_button,
             self.exit_button,
         ],
         height=Dimension(min=1),
         width=Dimension(min=1),
         key_bindings=self.get_key_bindings(),
     )
Ejemplo n.º 13
0
 def _get_status_area(self, status=""):
     return TextArea(
         text=status,
         height=Dimension.exact(1),
         prompt=">>> ",
         multiline=False,
         wrap_lines=False,
         focusable=False,
         read_only=True,
     )
Ejemplo n.º 14
0
 def __init__(self, app=None, show=False, height=Dimension(preferred=5)):
     self.lexer = BreakpointsLexer()
     self.breakpoints = {}
     self.changed = {}
     self.database = {}
     self.hits = {}
     scroll_offsets = ScrollOffsets(top=2, bottom=2)
     super(BreakpointsWindow, self).__init__(app=app,
                                             show=show,
                                             title='[ Breakpoints ]',
                                             scroll_offsets=scroll_offsets)
Ejemplo n.º 15
0
 def __init__(self, lexer_name='yaml'):
     self.buf = Buffer()
     self.buf.text = ''
     self.lexer = PygmentsLexer(find_lexer_class_by_name(lexer_name))
     self.window = HSplit([
         HorizontalLine(),
         Window(content=BufferControl(buffer=self.buf, lexer=self.lexer))
     ],
                          height=Dimension(min=5, max=20, weight=1))
     super(InfoWindow, self).__init__(content=self.window,
                                      filter=has_focus(self))
Ejemplo n.º 16
0
def get_layout(entry_point, top_menu_items):
    set_current_sidebar(entry_point)
    menu = DynamicContainer(get_current_sidebar)

    # windows that are focused by pressing tab keys.

    main_focus = [menu, _output_window]

    following = get_following(main_focus)

    def next_main_window(event):
        next_idx = following(1)
        event.app.layout.focus(main_focus[next_idx])

    def previous_main_window(event):
        next_idx = following(-1)
        event.app.layout.focus(main_focus[next_idx])

    key_binding = KeyBindings()
    kb.add("tab")(next_main_window)
    kb.add("s-tab")(previous_main_window)

    root_container = HSplit([
        VSplit(
            [menu, Window(width=1, char="|"), _output_window],
            height=Dimension(),
        ),
        Window(
            content=status_bar,
            width=Dimension(),
            height=1,
            style="class:status_bar",
        ),
    ])
    if top_menu_items:
        root_container = MenuContainer(body=root_container,
                                       menu_items=top_menu_items)
        main_focus.append(root_container.window)

    layout = Layout(root_container, focused_element=entry_point)
    return layout
Ejemplo n.º 17
0
    def __init__(self,
                 app,
                 height=Dimension(preferred=20),
                 width=Dimension(preferred=20),
                 callback=None):

        self.app = app
        gdb = self._get_gdb_path()
        self._create_pipes()
        self._update_pythonpath()

        gdbw_dir = self._get_gdbw_dir()
        source_cmd = 'source %s/gdbwhelper.py' % (gdbw_dir)
        gdb_run_cmd = [gdb, '-iex', source_cmd] + argv[1:]
        self.console = Terminal(gdb_run_cmd,
                                done_callback=self._done,
                                height=height,
                                width=width)
        self.info = InfoLine(text='', width=240)
        self.window = HSplit([self.info.get_ui(), self.console])
        self.update_info()
        self.in_pipe.begin_reading(callback)
Ejemplo n.º 18
0
    def __init__(self,
                 app=None,
                 show=False,
                 height=Dimension(preferred=22),
                 width=Dimension(preferred=25)):
        self.app = app
        self.show = show
        self.cursor_line = 0
        self.lexer = DisassemblyLexer(self)
        self.buffer = Buffer(document=Document(),
                             multiline=True)
        self.control = BufferControl(buffer=self.buffer,
                                     focusable=True,
                                     lexer=self.lexer,
                                     focus_on_click=True)
        self.window = Window(content=self.control,
                             height=height,
                             wrap_lines=False,
                             scroll_offsets = ScrollOffsets(top=0))

        self.info = InfoLine('[Disassembly]', width=240)
        self.container = ConditionalContainer(
            content=HSplit([self.info.get_ui(), self.window]),
            filter=Condition(lambda: self.show))
Ejemplo n.º 19
0
    def __init__(self,
                 app=None,
                 show=False,
                 title='[Line Items]',
                 show_divider=lambda: True,
                 height=Dimension(preferred=1)):
        self.lexer = LineItemsLexer(self)
        self.lines = []
        self.changed = []

        super(LineItemsWindow, self).__init__(app=app,
                                              show=show,
                                              title=title,
                                              show_divider=show_divider,
                                              height=height)
Ejemplo n.º 20
0
    def __init__(self, playback, save_location=None, *args, **kwargs):

        self.mainViewCondition = partial(self.mainView, self)
        self.mainViewCondition = Condition(self.mainViewCondition)
        self.disabled_bindings = False
        bindings = KeyBindings()
        self.init_bindings(bindings)

        super().__init__(full_screen=True,
                         key_bindings=bindings,
                         mouse_support=True,
                         *args,
                         **kwargs)

        self.displayingHelpScreen = (
            False)  # used to toggle between help screen on normal

        if save_location:
            self.save_location = save_location
        else:
            self.save_location = SAVE_LOCATION
        self.playback = playback
        self._savedLayout = Layout(Window())
        self.command_cache = deque([], maxlen=5)

        ##########################################
        ### Setting up views
        ##########################################

        self.old_command_window = FormattedTextControl(text="Output goes here",
                                                       focusable=True)
        self.new_command_window = FormattedTextControl(text="Output goes here",
                                                       focusable=True)

        self.body = Frame(
            HSplit([
                Frame(Window(self.old_command_window)),
                Frame(Window(self.new_command_window)),
            ]))
        self.toolbar = Window(
            FormattedTextControl(text=self.toolbar_text),
            height=Dimension(max=1, weight=10000),
            dont_extend_height=True,
        )

        self.main_view = HSplit([self.body, self.toolbar], padding_char="-")
        self.layout = Layout(self.main_view)
Ejemplo n.º 21
0
    def __init__(self, app=None, show=False, height=Dimension(preferred=20)):

        self.frame = None
        self.app = app
        self.show = show
        self.args = LineItemsWindow(app=app,
                                    show=show,
                                    title='[ Arguments ]',
                                    show_divider=self._show_divider)
        self.locals = LineItemsWindow(app=app,
                                      show=show,
                                      title='[ Locals ]',
                                      show_divider=self._show_divider)

        self.container = ConditionalContainer(
            content=HSplit([self.args.get_ui(),
                            self.locals.get_ui()]),
            filter=Condition(lambda: self.show))
Ejemplo n.º 22
0
def get_buffer_window(buffer,
                      height=20,
                      lexer_name="",
                      style="fg:black bg:ansiwhite"):
    """Generate a editable text window for pager in terminal

    :param buffer: Buffer object storing the text
    :type  buffer: str

    :param lexer_name: If the editable text should be highlighted with
        some kind of grammar, examples are ``yaml``, ``python`` ...
    :type  lexer_name: str

    :param height: Max height of the text area
    :type  height: int

    :param style: Color setting of backgorund and foreground
    :type  style: str

    :return: Container with window information
    :rtype : prompt_toolkit.layout.containers.Window
    """
    import prompt_toolkit.layout.containers
    import prompt_toolkit.layout.controls
    from prompt_toolkit.layout import Dimension
    from prompt_toolkit.lexers import PygmentsLexer
    from pygments.lexers import find_lexer_class_by_name

    return prompt_toolkit.layout.containers.Window(
        height=None if not height else Dimension(min=0, max=height),
        width=None,
        style=style,
        always_hide_cursor=False,
        content=prompt_toolkit.layout.controls.BufferControl(
            buffer=buffer,
            lexer=PygmentsLexer(find_lexer_class_by_name(lexer_name))))
Ejemplo n.º 23
0
    def __init__(self):
        # styling
        style = Style.from_dict({
            'completion-menu.completion': 'bg:#008888 #ffffff',
            'completion-menu.completion.current': 'bg:#00aaaa #000000',
            'scrollbar.background': 'bg:#88aaaa',
            'scrollbar.button': 'bg:#222222',
            'input-field': '#004400',
            'buffer': '#ff0066',
        })

        # create input fields
        self.source_field = make_text_area('[Source folder]: ')
        self.target_field = make_text_area('[Target folder]: ')
        self.dry_field = make_text_area('[{:13}]: '.format("Dry? (y/n)"))

        # get completers
        initialize_database()
        con = db_connect()

        self.source_field.completer = FuzzyCompleter(
            WordCompleter(get_source_paths(con), ignore_case=True))
        self.target_field.completer = FuzzyCompleter(
            WordCompleter(get_target_paths(con), ignore_case=True))
        self.dry_field.completer = WordCompleter(
            ['Yes', 'No', 'True', 'False', 'yes', 'no'], ignore_case=True)

        # bottom toolbar
        def bottom_toolbar_call():
            s1 = '<b><style bg="ansired">C-H</style></b>: history mode.'
            s2 = '<b><style bg="ansired">C-C/C-Q</style></b>: exit app.'
            s3 = '<b><style bg="ansired">C-O</style></b>: ordered paths.'
            s4 = '<b><style bg="ansired">C-R</style></b>: reverse paths.'
            return HTML(" ".join([s1, s2, s3, s4]))

        self.bottom_toolbar = ConditionalContainer(
            Window(FormattedTextControl(lambda: bottom_toolbar_call,
                                        style='class:bottom-toolbar.text'),
                   style='class:bottom-toolbar',
                   dont_extend_height=True,
                   height=Dimension(min=1)),
            filter=(~is_done & renderer_height_is_known
                    & Condition(lambda: bottom_toolbar_call is not None)))

        # create app body
        self.body = FloatContainer(content=HSplit(children=[
            self.source_field, self.target_field, self.dry_field,
            self.bottom_toolbar
        ],
                                                  height=8),
                                   floats=[
                                       Float(xcursor=True,
                                             ycursor=True,
                                             content=CompletionsMenu(
                                                 max_height=12,
                                                 scroll_offset=1))
                                   ])

        # define internal logic
        def execute_command(buff):
            """Send command to subprocess dealing with dry argument recursively"""
            dry = False if buff.text.lower() in ['n', 'no', 'false'] else True
            dry_flag = 'DRY' if dry else 'NOT DRY'
            dry_string = 'n' if dry else ''
            command = "rsync -avucP{} {} {}".format(dry_string,
                                                    self.source_field.text,
                                                    self.target_field.text)

            def run_script():
                subprocess.call(command, shell=True)

            def print_info():
                print_formatted_text(
                    HTML('<ansired>{} </ansired>'.format(dry_flag)))
                print_formatted_text(
                    HTML('<ansired>{} </ansired>'.format(
                        'You entered: {}'.format(command))))
                print_formatted_text(
                    HTML('<ansired>{} </ansired>'.format('Running...')))

            run_in_terminal(print_info)

            if dry:
                run_in_terminal(run_script)
                return
            else:
                con = db_connect()
                create_rsync_record(con, self.source_field.text,
                                    self.target_field.text)
                run_in_terminal(run_script)

                app = get_app()
                app.exit()
                return

        self.dry_field.buffer.accept_handler = execute_command

        # Key bindings
        self.kb = KeyBindings()

        @self.kb.add('c-q')
        @self.kb.add('c-c')
        def _(event):
            " Quit application. "
            event.app.exit()

        #kb.add('enter')(focus_next)
        self.kb.add('tab')(focus_next)
        self.kb.add('s-tab')(focus_previous)

        # The `Application`
        self.app = Application(
            layout=Layout(self.body),
            #style=style,
            key_bindings=self.kb,
            full_screen=False,
            mouse_support=True)
Ejemplo n.º 24
0
 def __init__(self, item, w_min=None, w_max=None, w_pre=None, w_weight=None, h_min=None, h_max=None, h_pre=None, h_weight=None):
     super().__init__()
     self.item = to_container(item)
     self.width  = Dimension(min=w_min, max=w_max, preferred=w_pre, weight=w_weight)
     self.height = Dimension(min=h_min, max=h_max, preferred=h_pre, weight=h_weight)
Ejemplo n.º 25
0
 def __init__(self, app=None, show=False, height=Dimension(preferred=22)):
     super(RegistersWindow, self).__init__(app=app,
                                           show=show,
                                           height=height,
                                           title='[ Registers ]',
                                           show_divider=self._show_divider)
Ejemplo n.º 26
0
 def _get_default_buffer_control_height(self) -> Dimension:
     dim = super()._get_default_buffer_control_height()
     # When there's no complete this line, don't reverse space for the autocompletion menu
     if not self.has_complete_this_line and self.default_buffer.complete_state is None:
         dim = Dimension()
     return dim
Ejemplo n.º 27
0
                            style="class:file-viewer",
                            ignore_content_height=True,
                            cursorline=True,
                            dont_extend_height=True,
                            left_margins=[NumberedMargin()],
                            scroll_offsets=ScrollOffsets(top=10, bottom=10))

output_buffer = Buffer(document=Document(output, 0))
output_buffer_control = BufferControl(
    buffer=output_buffer, input_processors=[AddStyleToDiff("bg:#222222")])
output_window = Window(content=output_buffer_control,
                       style="class:file-viewer",
                       ignore_content_height=True,
                       cursorline=True,
                       dont_extend_height=True,
                       height=Dimension(weight=1),
                       left_margins=[NumberedMargin()],
                       scroll_offsets=ScrollOffsets(top=10, bottom=10))

hotkeys = {
    '<': 'pick left line',
    '>': 'pick right line',
    'C-up': None,
    'C-down': 'go to output',
    'C-q': 'quit',
    'C-s': 'accept changes',
}

# The output titlebar: a vertical line in the middle.
output_titlebar = Window(content=FormattedTextControl(text=''),
                         height=1,
Ejemplo n.º 28
0
def text_area(title, text, lexer_name="", height=10, full_screen=False):
    """
    Small implementation of an editor/pager for small pieces of text.

    :param title: Title of the text_area
    :type  title: str
    :param text: Editable text
    :type  text: str
    :param lexer_name: If the editable text should be highlighted with
        some kind of grammar, examples are ``yaml``, ``python`` ...
    :type  lexer_name: str
    :param height: Max height of the text area
    :type  height: int
    :param full_screen: Wether or not the text area should be full screen.
    :type  full_screen: bool
    """
    from prompt_toolkit import Application
    from prompt_toolkit.enums import EditingMode
    from prompt_toolkit.buffer import Buffer
    from prompt_toolkit.layout.containers import HSplit, Window, WindowAlign
    from prompt_toolkit.layout.controls import (BufferControl,
                                                FormattedTextControl)
    from prompt_toolkit.layout.layout import Layout
    from prompt_toolkit.layout import Dimension
    from prompt_toolkit.key_binding import KeyBindings
    from prompt_toolkit.lexers import PygmentsLexer
    from pygments.lexers import find_lexer_class_by_name
    assert (type(title) == str)
    assert (type(text) == str)
    assert (type(lexer_name) == str)
    assert (type(height) == int)
    assert (type(full_screen) == bool)

    kb = KeyBindings()
    buffer1 = Buffer()
    buffer1.text = text

    @kb.add('c-q')
    def exit_(event):
        event.app.exit(0)

    @kb.add('c-s')
    def save_(event):
        event.app.return_text = buffer1.text

    class App(Application):
        return_text = None

    text_height = Dimension(min=0, max=height) if height is not None else None

    pygment_lexer = find_lexer_class_by_name(lexer_name)
    lexer = PygmentsLexer(pygment_lexer)
    text_window = Window(height=text_height,
                         content=BufferControl(buffer=buffer1, lexer=lexer))

    root_container = HSplit([
        Window(char='-',
               align=WindowAlign.CENTER,
               height=1,
               content=FormattedTextControl(text=[('fg:ansiblack bg:ansiwhite',
                                                   title)]),
               always_hide_cursor=True),
        text_window,
        Window(height=1,
               width=None,
               align=WindowAlign.CENTER,
               char='-',
               content=FormattedTextControl(
                   text=[('fg:ansiblack bg:ansiwhite',
                          "Quit [Ctrl-q]  Save [Ctrl-s]")])),
    ])

    layout = Layout(root_container)

    layout.focus(text_window)

    app = App(editing_mode=(EditingMode.EMACS if papis.config.get(
        'editmode', section='tui') == 'emacs' else EditingMode.VI),
              layout=layout,
              key_bindings=kb,
              full_screen=full_screen)
    app.run()
    return app.return_text
Ejemplo n.º 29
0
def generate_layout(input_field: TextArea,
                    output_field: TextArea,
                    log_field: TextArea,
                    right_pane_toggle: Button,
                    log_field_button: Button,
                    search_field: SearchToolbar,
                    timer: TextArea,
                    process_monitor: TextArea,
                    trade_monitor: TextArea,
                    command_tabs: Dict[str, CommandTab],
                    ):
    components = {}

    components["item_top_version"] = Window(FormattedTextControl(get_version), style="class:header")
    components["item_top_active"] = Window(FormattedTextControl(get_active_strategy), style="class:header")
    components["item_top_file"] = Window(FormattedTextControl(get_strategy_file), style="class:header")
    components["item_top_gateway"] = Window(FormattedTextControl(get_gateway_status), style="class:header")
    components["item_top_toggle"] = right_pane_toggle
    components["pane_top"] = VSplit([components["item_top_version"],
                                     components["item_top_active"],
                                     components["item_top_file"],
                                     components["item_top_gateway"],
                                     components["item_top_toggle"]], height=1)
    components["pane_bottom"] = VSplit([trade_monitor,
                                        process_monitor,
                                        timer], height=1)
    output_pane = Box(body=output_field, padding=0, padding_left=2, style="class:output-field")
    input_pane = Box(body=input_field, padding=0, padding_left=2, padding_top=1, style="class:input-field")
    components["pane_left"] = HSplit([output_pane, input_pane], width=Dimension(weight=1))
    if all(not t.is_selected for t in command_tabs.values()):
        log_field_button.window.style = "class:tab_button.focused"
    else:
        log_field_button.window.style = "class:tab_button"
    tab_buttons = [log_field_button]
    for tab in sorted(command_tabs.values(), key=lambda x: x.tab_index):
        if tab.button is not None:
            if tab.is_selected:
                tab.button.window.style = "class:tab_button.focused"
            else:
                tab.button.window.style = "class:tab_button"
            tab.close_button.window.style = tab.button.window.style
            tab_buttons.append(VSplit([tab.button, tab.close_button]))
    pane_right_field = log_field
    focused_right_field = [tab.output_field for tab in command_tabs.values() if tab.is_selected]
    if focused_right_field:
        pane_right_field = focused_right_field[0]
    components["pane_right_top"] = VSplit(tab_buttons, height=1, style="class:log-field", padding_char=" ", padding=2)
    components["pane_right"] = ConditionalContainer(
        Box(body=HSplit([components["pane_right_top"], pane_right_field, search_field], width=Dimension(weight=1)),
            padding=0, padding_left=2, style="class:log-field"),
        filter=True
    )
    components["hint_menus"] = [Float(xcursor=True,
                                      ycursor=True,
                                      transparent=True,
                                      content=CompletionsMenu(max_height=16,
                                                              scroll_offset=1))]

    root_container = HSplit([
        components["pane_top"],
        VSplit(
            [FloatContainer(components["pane_left"], components["hint_menus"]),
             components["pane_right"]]),
        components["pane_bottom"],
    ])
    return Layout(root_container, focused_element=input_field), components
Ejemplo n.º 30
0
 def fit_to_height(self):
     d = self.buffer.document
     l = len(d.lines)
     self.window.height = Dimension(preferred=l)