def create_popup_window(title, body): """ Return the layout for a pop-up window. It consists of a title bar showing the `title` text, and a body layout. The window is surrounded by borders. """ assert isinstance(title, six.text_type) assert isinstance(body, Container) return HSplit([ VSplit([ Window(width=D.exact(1), height=D.exact(1), content=FillControl(BORDER.TOP_LEFT, token=Token.Window.Border)), TokenListToolbar( get_tokens=lambda cli: [(Token.Window.Title, ' %s ' % title)], align_center=True, default_char=Char(BORDER.HORIZONTAL, Token.Window.Border)), Window(width=D.exact(1), height=D.exact(1), content=FillControl(BORDER.TOP_RIGHT, token=Token.Window.Border)), ]), VSplit([ Window(width=D.exact(1), content=FillControl(BORDER.VERTICAL, token=Token.Window.Border)), body, Window(width=D.exact(1), content=FillControl(BORDER.VERTICAL, token=Token.Window.Border)), ]), VSplit([ Window(width=D.exact(1), height=D.exact(1), content=FillControl(BORDER.BOTTOM_LEFT, token=Token.Window.Border)), Window(height=D.exact(1), content=FillControl(BORDER.HORIZONTAL, token=Token.Window.Border)), Window(width=D.exact(1), height=D.exact(1), content=FillControl(BORDER.BOTTOM_RIGHT, token=Token.Window.Border)), ]), ])
def status_bar(key_bindings_manager, python_input): """ Create the `Layout` for the status bar. """ TB = Token.Toolbar.Status @if_mousedown def toggle_paste_mode(cli, mouse_event): python_input.paste_mode = not python_input.paste_mode @if_mousedown def enter_history(cli, mouse_event): python_input.enter_history(cli) def get_tokens(cli): python_buffer = cli.buffers[DEFAULT_BUFFER] result = [] append = result.append append((TB, ' ')) result.extend(get_inputmode_tokens(cli, python_input)) append((TB, ' ')) # Position in history. append((TB, '%i/%i ' % (python_buffer.working_index + 1, len(python_buffer._working_lines)))) # Shortcuts. if not python_input.vi_mode and cli.current_buffer_name == SEARCH_BUFFER: append((TB, '[Ctrl-G] Cancel search [Enter] Go to this position.')) elif bool(cli.current_buffer.selection_state ) and not python_input.vi_mode: # Emacs cut/copy keys. append( (TB, '[Ctrl-W] Cut [Meta-W] Copy [Ctrl-Y] Paste [Ctrl-G] Cancel')) else: result.extend([ (TB.Key, '[F3]', enter_history), (TB, ' History ', enter_history), (TB.Key, '[F6]', toggle_paste_mode), (TB, ' ', toggle_paste_mode), ]) if python_input.paste_mode: append((TB.PasteModeOn, 'Paste mode (on)', toggle_paste_mode)) else: append((TB, 'Paste mode', toggle_paste_mode)) return result return TokenListToolbar( get_tokens, default_char=Char(token=TB), filter=~IsDone() & RendererHeightIsKnown() & Condition(lambda cli: python_input.show_status_bar and not python_input.show_exit_confirmation))
def create_layout(python_input, history_mapping): """ Create and return a `Container` instance for the history application. """ processors = [ HighlightSearchProcessor(preview_search=True), HighlightSelectionProcessor() ] help_window = create_popup_window( title='History Help', body=Window(content=BufferControl(buffer_name=HELP_BUFFER, default_char=Char(token=Token), lexer=PygmentsLexer(RstLexer), input_processors=processors), right_margins=[ScrollbarMargin()], scroll_offsets=ScrollOffsets(top=2, bottom=2))) return HSplit([ # Top title bar. TokenListToolbar(get_tokens=_get_top_toolbar_tokens, align_center=True, default_char=Char(' ', Token.Toolbar.Status)), FloatContainer( content=VSplit([ # Left side: history. Window(content=BufferControl(buffer_name=HISTORY_BUFFER, lexer=PygmentsLexer(PythonLexer), input_processors=processors), wrap_lines=False, left_margins=[HistoryMargin(history_mapping)], scroll_offsets=ScrollOffsets(top=2, bottom=2)), # Separator. Window(width=D.exact(1), content=FillControl(BORDER.LIGHT_VERTICAL, token=Token.Separator)), # Right side: result. Window( content=BufferControl(buffer_name=DEFAULT_BUFFER, input_processors=processors + [GrayExistingText(history_mapping)], lexer=PygmentsLexer(PythonLexer)), wrap_lines=False, left_margins=[ResultMargin(history_mapping)], scroll_offsets=ScrollOffsets(top=2, bottom=2)), ]), floats=[ # Help text as a float. Float( width=60, top=3, bottom=2, content=ConditionalContainer( # (We use InFocusStack, because it's possible to search # through the help text as well, and at that point the search # buffer has the focus.) content=help_window, filter=InFocusStack(HELP_BUFFER))), ]), # Bottom toolbars. ArgToolbar(), SearchToolbar(), TokenListToolbar(get_tokens=partial(_get_bottom_toolbar_tokens, python_input=python_input), default_char=Char(' ', Token.Toolbar.Status)), ])
def __init__(self, pager): self.pager = pager self.dynamic_body = _DynamicBody(pager) # Build an interface. has_colon = HasColon(pager) self.container = FloatContainer(content=HSplit([ Titlebar(pager), self.dynamic_body, SearchToolbar(vi_mode=True), SystemToolbar(), ConditionalContainer(content=VSplit([ Window(height=D.exact(1), content=TokenListControl( self._get_statusbar_left_tokens, default_char=Char(' ', Token.Statusbar))), Window(height=D.exact(1), content=TokenListControl( self._get_statusbar_right_tokens, align_right=True, default_char=Char(' ', Token.Statusbar))), ]), filter=~HasSearch() & ~HasFocus(SYSTEM_BUFFER) & ~has_colon & ~HasFocus('EXAMINE')), ConditionalContainer(content=TokenListToolbar( lambda cli: [(Token.Statusbar, ' :')], default_char=Char(token=Token.Statusbar)), filter=has_colon), ConditionalContainer(content=Window(BufferControl( buffer_name='EXAMINE', default_char=Char(token=Token.Toolbar.Examine), lexer=SimpleLexer(default_token=Token.Toolbar.Examine.Text), input_processors=[ BeforeInput( lambda cli: [(Token.Toolbar.Examine, ' Examine: ')]), ]), height=D.exact(1)), filter=HasFocus('EXAMINE')), ConditionalContainer(content=Window(BufferControl( buffer_name='PATTERN_FILTER', default_char=Char(token=Token.Toolbar.Search), lexer=SimpleLexer(default_token=Token.Toolbar.Search.Text), input_processors=[ BeforeInput(lambda cli: [(Token.Toolbar.Search, '&/')]), ]), height=D.exact(1)), filter=HasFocus('PATTERN_FILTER')), ]), floats=[ Float(right=0, height=1, bottom=1, content=_Arg()), Float(bottom=1, left=0, right=0, height=1, content=MessageToolbarBar( pager)), Float( right=0, height=1, bottom=1, content=ConditionalContainer( content=TokenListToolbar( lambda cli: [ (Token.Loading, ' Loading... ') ], default_char=Char( token=Token. Statusbar)), filter=Condition( lambda cli: pager. waiting_for_input_stream ))), Float( xcursor=True, ycursor=True, content= MultiColumnCompletionsMenu()), ])