def generate_layout(input_field: TextArea, output_field: TextArea, log_field: TextArea, search_field: SearchToolbar): root_container = HSplit([ VSplit([ Window(FormattedTextControl(get_version), style="class:title"), Window(FormattedTextControl(get_paper_trade_status), style="class:title"), Window(FormattedTextControl(get_title_bar_right_text), align=WindowAlign.RIGHT, style="class:title"), ], height=1), VSplit([ FloatContainer( HSplit([ output_field, Window(height=1, char='-', style='class:primary'), input_field, ]), [ # Completion menus. Float(xcursor=True, ycursor=True, transparent=True, content=CompletionsMenu(max_height=16, scroll_offset=1)), ]), Window(width=1, char='|', style='class:primary'), HSplit([ log_field, search_field, ]), ]), ]) return Layout(root_container, focused_element=input_field)
def get_root_container(self) -> FloatContainer: header_row = self.table.format_table().splitlines()[0] data_rows = self.table.format_table().splitlines()[1:] row_buttons = [ SelectableLabel(row, handler=functools.partial(self._handle_answer, i)) for i, row in enumerate(data_rows) ] table_container = HSplit([ Label(FormattedText([("class:column-name", header_row)]), ), HorizontalLine(), *row_buttons, ]) rules_container = Box( Label( self.table.format_constraints(separator="\n\n"), dont_extend_width=True, ), ) return FloatContainer( Box( Frame( VSplit([ table_container, VerticalLine(), rules_container, ])), ), floats=[], )
def get_root_container(self) -> FloatContainer: buttons = [ *self._game_buttons.keys(), HorizontalLine(), Button("Quit", width=MENU_BUTTON_WIDTH, handler=self._exit), ] menu_keybindings = _create_menu_keybindings(buttons) game_buttons_container = Frame( HSplit( buttons, width=Dimension(min=MENU_BUTTON_WIDTH, max=40), height=Dimension(), ), title="Games", key_bindings=menu_keybindings, ) game_description_container = Frame( Box( Label( text=self._get_game_description, dont_extend_height=False, width=Dimension(min=40), ), padding=0, padding_left=1, ), ) return FloatContainer(VSplit([ game_buttons_container, game_description_container, ]), floats=[])
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])
def generate_layout(input_field: TextArea, output_field: TextArea, log_field: TextArea): root_container = VSplit([ FloatContainer( HSplit([ output_field, Window(height=1, char='-', style='class:line'), input_field, TextArea( height=1, text= f'Version: {version} [Ctrl + C] QUIT Hold down "fn" for selecting and copying text', style='class:label'), ]), [ # Completion menus. Float(xcursor=True, ycursor=True, transparent=True, content=CompletionsMenu(max_height=16, scroll_offset=1)), ]), Window(width=1, char='|', style='class:line'), log_field, ]) return Layout(root_container, focused_element=input_field)
def __init__(self, session): self.session = session self.tabs_toolbar = TabsToolbar(self.session) self.float_container = FloatContainer( # Dummy window content=VSplit([Window(BufferControl())]), floats=[]) super().__init__( children=[ # Tabs self.tabs_toolbar, # Seperation line. Window(height=1, char='-', style='class:line'), # Here goes current tab buffer self.float_container ], window_too_small=None, align=VerticalAlign.JUSTIFY, padding=0, padding_char=None, padding_style='', width=None, height=None, z_index=None, modal=False, key_bindings=None, style='')
def __init__(self) -> None: self._percentage = 60 self.label = Label('60%') self.container = FloatContainer( content=Window(height=1), floats=[ # We first draw the label, then the actual progress bar. Right # now, this is the only way to have the colors of the progress # bar appear on top of the label. The problem is that our label # can't be part of any `Window` below. Float(content=self.label, top=0, bottom=0), Float(left=0, top=0, right=0, bottom=0, content=VSplit([ Window( style='class:progress-bar.used', width=lambda: D(weight=int(self._percentage))), Window(style='class:progress-bar', width=lambda: D(weight=int(100 - self. _percentage))), ])), ])
def create_tutorial_layout(lex): """ layout for example tutorial """ lexer, _, _ = get_lexers(lex, None, None) layout_full = HSplit([ FloatContainer( Window(BufferControl(input_processors=input_processors, lexer=lexer, preview_search=Always()), get_height=get_height), [ Float(xcursor=True, ycursor=True, content=CompletionsMenu( max_height=MAX_COMPLETION, scroll_offset=1, extra_filter=(HasFocus(DEFAULT_BUFFER)))) ]), ConditionalContainer(HSplit([ get_hline(), get_param(lexer), get_hline(), Window(content=BufferControl(buffer_name='example_line', lexer=lexer), ), Window(TokenListControl(get_tutorial_tokens, default_char=Char(' ', Token.Toolbar)), height=D.exact(1)), ]), filter=~IsDone() & RendererHeightIsKnown()) ]) return layout_full
def __init__(self, exchange): super().__init__() self._exchange = exchange self._loading_component = Loading() self._currently_syncing_component = None self._recently_synced_component = None self._held_files_component = None self.menu_bar = Window( FormattedTextControl( "[s] Stop [d] Sync files down [q] Quit [?] Help"), height=1, style="reverse", ) self._screen_container = HSplit( [self._loading_component.container, self.menu_bar]) self.main_container = FloatContainer(self._screen_container, floats=[]) self._subscription_ids = [ self._exchange.subscribe( Messages.START_WATCH_SYNC_MAIN_LOOP, lambda _: self._start_main_screen(), ), self._exchange.subscribe( Messages.HELD_FILES_CHANGED, lambda held_files: self._update_held_files(held_files), ), self._exchange.subscribe( Messages.STARTING_HANDLING_FS_EVENT, lambda event: self._on_start_handling_fs_event(event), ), self._exchange.subscribe( Messages.FINISHED_HANDLING_FS_EVENT, lambda event: self._on_finish_handling_fs_event(event), ), ] self.bindings = KeyBindings() @self.bindings.add("s") def _(event): self._exchange.publish(Messages.STOP_WATCH_SYNC) @self.bindings.add("d") def _(event): self._exchange.publish(Messages.DOWN_IN_WATCH_SYNC) @self.bindings.add("?") def _(event): self._toggle_help()
def __init__(self, use_theme): self.statusbar = Window(height=1, char='/', style='class:line', content=FormattedTextControl(text='druid////'), align=WindowAlign.RIGHT) self.content = HSplit([ Window(), self.statusbar, Window(height=1), ]) self.container = FloatContainer( content=self.content, floats=[ Float( xcursor=True, ycursor=True, content=CompletionsMenu(max_height=16, scroll_offset=1), ), ], ) self.key_bindings = KeyBindings() @self.key_bindings.add('c-c', eager=True) @self.key_bindings.add('c-q', eager=True) def quit_druid(event): event.app.exit() if use_theme: self.style = Style([ ('capture-field', '#747369'), ('output-field', '#d3d0c8'), ('input-field', '#f2f0ec'), ('line', '#747369'), ('scrollbar.background', 'bg:#000000'), ('scrollbar.button', 'bg:#747369'), ]) else: self.style = Style([]) self.layout = Layout(self.container) self.app = Application( layout=self.layout, key_bindings=self.key_bindings, style=self.style, mouse_support=True, full_screen=True, ) self.pages = dict() self.current_page = None
def create_layout(self, exam_lex, toolbar_lex): """ creates the layout """ lexer, exam_lex, toolbar_lex = get_lexers(self.shell_ctx.lexer, exam_lex, toolbar_lex) if not any( isinstance(processor, DefaultPrompt) for processor in self.input_processors): self.input_processors.append(DefaultPrompt(self.get_prompt_tokens)) layout_lower = ConditionalContainer(HSplit([ get_anyhline(self.shell_ctx.config), get_descriptions(self.shell_ctx.config, exam_lex, lexer), get_examplehline(self.shell_ctx.config), get_example(self.shell_ctx.config, exam_lex), ConditionalContainer(get_hline(), filter=self.show_default | self.show_symbol), ConditionalContainer(Window(content=BufferControl( buffer_name='default_values', lexer=lexer)), filter=self.show_default), ConditionalContainer(get_hline(), filter=self.show_default & self.show_symbol), ConditionalContainer(Window( content=BufferControl(buffer_name='symbols', lexer=exam_lex)), filter=self.show_symbol), ConditionalContainer(Window( content=BufferControl(buffer_name='progress', lexer=lexer)), filter=self.show_progress), Window(content=BufferControl(buffer_name='bottom_toolbar', lexer=toolbar_lex), ), ]), filter=~IsDone() & RendererHeightIsKnown()) layout_full = HSplit([ FloatContainer( Window( BufferControl(input_processors=self.input_processors, lexer=lexer, preview_search=Always()), get_height=get_height, ), [ Float(xcursor=True, ycursor=True, content=CompletionsMenu( max_height=MAX_COMPLETION, scroll_offset=1, extra_filter=(HasFocus(DEFAULT_BUFFER)))) ]), layout_lower ]) return layout_full
def __init__(self, body): assert is_container(body) self.container = FloatContainer( content=body, floats=[ Float(bottom=-1, height=1, left=1, right=-1, transparent=True, content=Window(style='class:shadow')), Float(bottom=-1, top=1, width=1, right=-1, transparent=True, content=Window(style='class:shadow')), ] )
def layout(self): return Layout( FloatContainer(content=VSplit([ HSplit([ WindowManager.header(), ] + self._get_layout_folders()), VerticalLine(), HSplit([ WindowManager.player(self.playing), Frame(body=self.stations.radio_list, title=self.stations_folder) ]) ]), floats=[self.dialog] if self.dialog else []))
def generate_layout( input_field: TextArea, output_field: TextArea, log_field: TextArea, search_log_field: SearchToolbar, search_out_field: SearchToolbar, timer: TextArea, process_monitor: TextArea, # trade_monitor: TextArea): ): root_container = HSplit([ # VSplit([ # Window(FormattedTextControl(get_version), style="class:title"), # # Window(FormattedTextControl(get_paper_trade_status), style="class:title"), # # Window(FormattedTextControl(get_active_strategy), style="class:title"), # # Window(FormattedTextControl(get_active_markets), style="class:title"), # # Window(FormattedTextControl(get_script_file), style="class:title"), # # Window(FormattedTextControl(get_strategy_file), style="class:title"), # ], height=1), VSplit([ FloatContainer( HSplit([ output_field, Window(height=1, char='-', style='class:primary'), Window(FormattedTextControl(get_partial_args), style="class:title"), Window(height=1, char='-', style='class:primary'), input_field, ]), [ # Completion menus. Float(xcursor=True, ycursor=True, transparent=True, content=CompletionsMenu(max_height=16, scroll_offset=1)), ]), Window(width=1, char='|', style='class:primary'), HSplit([log_field, search_log_field, search_out_field]), ]), VSplit( [ # trade_monitor, process_monitor, timer, ], height=1), ]) return Layout(root_container, focused_element=input_field)
def create_layout(lex, exam_lex, toolbar_lex): """ creates the layout """ config = azclishell.configuration.CONFIGURATION lexer, exam_lex, toolbar_lex = get_lexers(lex, exam_lex, toolbar_lex) input_processors.append(DefaultPrompt(get_prompt_tokens)) layout_lower = ConditionalContainer(HSplit([ get_anyhline(config), get_descriptions(config, exam_lex, lexer), get_examplehline(config), get_example(config, exam_lex), ConditionalContainer(get_hline(), filter=ShowDefault() | ShowSymbol()), ConditionalContainer(Window( content=BufferControl(buffer_name='default_values', lexer=lexer)), filter=ShowDefault()), ConditionalContainer(get_hline(), filter=ShowDefault() & ShowSymbol()), ConditionalContainer(Window( content=BufferControl(buffer_name='symbols', lexer=exam_lex)), filter=ShowSymbol()), ConditionalContainer( Window(content=BufferControl(buffer_name='progress', lexer=lexer)), filter=ShowProgress()), Window(content=BufferControl(buffer_name='bottom_toolbar', lexer=toolbar_lex), ), ]), filter=~IsDone() & RendererHeightIsKnown()) layout_full = HSplit([ FloatContainer( Window( BufferControl(input_processors=input_processors, lexer=lexer, preview_search=Always()), get_height=get_height, ), [ Float(xcursor=True, ycursor=True, content=CompletionsMenu( max_height=MAX_COMPLETION, scroll_offset=1, extra_filter=(HasFocus(DEFAULT_BUFFER)))) ]), layout_lower ]) return layout_full
def create_app(listen_handler, home): # components logo = Label(text=LOGO) text_area = TextArea(text=str(home), read_only=True, scrollbar=True) listen_btn = Button('Listen', handler=listen_handler(text_area=text_area)) help_btn = Button('Help', handler=help_handler) exit_btn = Button('Exit', handler=lambda: get_app().exit()) buttons = HSplit(children=[ Label(text=' MENU'), Frame(listen_btn), Frame(help_btn), Frame(exit_btn) ], style='bg:#00aa00 #000000') # root container root_container = FloatContainer(HSplit([ Box(body=VSplit([buttons, logo], padding=12), padding=0, style='bg:#888800 #000000'), text_area, ]), floats=[]) # key bindings bindings = KeyBindings() bindings.add('tab')(focus_next) bindings.add('s-tab')(focus_previous) @bindings.add('c-c') @bindings.add('q') def _(event): event.app.exit() # application application = Application(layout=Layout(root_container, focused_element=listen_btn), key_bindings=bindings, enable_page_navigation_bindings=True, mouse_support=True, full_screen=True) return application
def create_layout(yarn_watcher): """ Create the layout. """ app_table = create_application_table(yarn_watcher) app_details = create_application_details(yarn_watcher) # Toolbars. titlebar_text = HTML( '<strong>YARN Application Watcher</strong> Press <shortcut>[Ctrl-C]</shortcut> to quit.' ) bottom_toolbar_text = HTML( '<shortcut>[Ctrl-C]</shortcut>: quit ' '<shortcut>[Up]</shortcut>/<shortcut>[Down]</shortcut> select previous/next.' ) root_container = FloatContainer( content=HSplit([ # The titlebar. Window(height=1, content=FormattedTextControl(titlebar_text), align=VerticalAlign.CENTER, style='class:header'), # The table. VSplit([app_table, app_details]), # bottom buttons VSplit([ Button('Resource Manager', width=30), Button('Node Manager', width=30) ], align=VerticalAlign.CENTER), # bottom toolbar. Window(height=1, content=FormattedTextControl(bottom_toolbar_text), style='class:footer'), ]), floats=[]) return Layout(root_container, focused_element=app_table)
def generate_layout(input_field: TextArea, output_field: TextArea, log_field: TextArea, log_toggle: Button, search_field: SearchToolbar, timer: TextArea, process_monitor: TextArea, trade_monitor: TextArea): components = {} components["item_top_version"] = Window(FormattedTextControl(get_version), style="class:header") components["item_top_paper"] = Window( FormattedTextControl(get_paper_trade_status), style="class:header") components["item_top_active"] = Window( FormattedTextControl(get_active_strategy), style="class:header") # Window(FormattedTextControl(get_active_markets), style="class:header"), # Window(FormattedTextControl(get_script_file), style="class:header"), components["item_top_file"] = Window( FormattedTextControl(get_strategy_file), style="class:header") components["item_top_toggle"] = log_toggle components["pane_top"] = VSplit([ components["item_top_version"], components["item_top_paper"], components["item_top_active"], components["item_top_file"], components["item_top_toggle"] ], height=1) components["pane_bottom"] = VSplit([trade_monitor, process_monitor, timer], height=1) components["pane_left"] = HSplit([output_field, input_field]) components["pane_right"] = HSplit([log_field, search_field]) 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
def __init__(self, body: AnyContainer) -> None: self.container = FloatContainer( content=body, floats=[ Float( bottom=-1, height=1, left=1, right=-1, transparent=True, content=Window(style="class:shadow"), ), Float( bottom=-1, top=1, width=1, right=-1, transparent=True, content=Window(style="class:shadow"), ), ], )
def layout(self) -> Layout: """:class:`prompt_toolkit.layout.Layout`: Get app layout dynamically.""" if self._layout_mode == LayoutMode.vertical: layout = HSplit([ VSplit([self._left_pane, self._right_pane]), self._command_pane ]) elif (self._layout_mode == LayoutMode.horizontal or self._layout_mode == LayoutMode.single): layout = HSplit( [self._left_pane, self._right_pane, self._command_pane]) else: self._layout_mode = LayoutMode.vertical self.set_error( Notification("Unexpected layout.", error_type=ErrorType.warning)) return self.layout if self._border: layout = Frame(layout) return Layout( FloatContainer( content=layout, floats=[Float(content=self._option_pane), self._error_pane], ))
body = FloatContainer( content=Window(FormattedTextControl(LIPSUM), wrap_lines=True), floats=[ # Important note: Wrapping the floating objects in a 'Frame' is # only required for drawing the border around the # floating text. We do it here to make the layout more # obvious. # Left float. Float(Frame(Window(FormattedTextControl(left_text), width=10, height=2), style='bg:#44ffff #ffffff'), left=0), # Right float. Float(Frame(Window(FormattedTextControl(right_text), width=10, height=2), style='bg:#44ffff #ffffff'), right=0), # Bottom float. Float(Frame(Window(FormattedTextControl(bottom_text), width=10, height=2), style='bg:#44ffff #ffffff'), bottom=0), # Top float. Float(Frame(Window(FormattedTextControl(top_text), width=10, height=2), style='bg:#44ffff #ffffff'), top=0), # Center float. Float( Frame(Window(FormattedTextControl(center_text), width=10, height=2), style='bg:#44ffff #ffffff')), # Quit text. Float(Frame(Window(FormattedTextControl(quit_text), width=18, height=1), style='bg:#ff44ff #ffffff'), top=6), ])
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
def create_layout(python_input, lexer=PythonLexer, extra_body=None, extra_toolbars=None, extra_buffer_processors=None, input_buffer_height=None): D = Dimension extra_body = [extra_body] if extra_body else [] extra_toolbars = extra_toolbars or [] extra_buffer_processors = extra_buffer_processors or [] input_buffer_height = input_buffer_height or D(min=6) search_toolbar = SearchToolbar(python_input.search_buffer) def create_python_input_window(): def menu_position(): """ When there is no autocompletion menu to be shown, and we have a signature, set the pop-up position at `bracket_start`. """ b = python_input.default_buffer if b.complete_state is None and python_input.signatures: row, col = python_input.signatures[0].bracket_start index = b.document.translate_row_col_to_index(row - 1, col) return index return Window( BufferControl( buffer=python_input.default_buffer, search_buffer_control=search_toolbar.control, lexer=lexer, include_default_input_processors=False, input_processors=[ ConditionalProcessor( processor=HighlightIncrementalSearchProcessor(), filter=has_focus(SEARCH_BUFFER) | has_focus(search_toolbar.control), ), HighlightSelectionProcessor(), DisplayMultipleCursors(), # Show matching parentheses, but only while editing. ConditionalProcessor( processor=HighlightMatchingBracketProcessor( chars='[](){}'), filter=has_focus(DEFAULT_BUFFER) & ~is_done & Condition(lambda: python_input. highlight_matching_parenthesis)), ConditionalProcessor(processor=AppendAutoSuggestion(), filter=~is_done) ] + extra_buffer_processors, menu_position=menu_position, # Make sure that we always see the result of an reverse-i-search: preview_search=True, ), left_margins=[PythonPromptMargin(python_input)], # Scroll offsets. The 1 at the bottom is important to make sure the # cursor is never below the "Press [Meta+Enter]" message which is a float. scroll_offsets=ScrollOffsets(bottom=1, left=4, right=4), # As long as we're editing, prefer a minimal height of 6. height=(lambda: (None if get_app().is_done or python_input. show_exit_confirmation else input_buffer_height)), wrap_lines=Condition(lambda: python_input.wrap_lines), ) root_container = HSplit([ VSplit([ HSplit([ FloatContainer( content=HSplit([create_python_input_window()] + extra_body), floats=[ Float(xcursor=True, ycursor=True, content=ConditionalContainer( content=CompletionsMenu(scroll_offset=( lambda: python_input. completion_menu_scroll_offset), max_height=12), filter=show_completions_menu(python_input))), Float(xcursor=True, ycursor=True, content=ConditionalContainer( content=MultiColumnCompletionsMenu(), filter=show_multi_column_completions_menu( python_input))), Float(xcursor=True, ycursor=True, content=signature_toolbar(python_input)), Float(left=2, bottom=1, content=exit_confirmation(python_input)), Float(bottom=0, right=0, height=1, content=meta_enter_message(python_input), hide_when_covering_content=True), Float(bottom=1, left=1, right=0, content=python_sidebar_help(python_input)), ]), ArgToolbar(), search_toolbar, SystemToolbar(), ValidationToolbar(), ConditionalContainer(content=CompletionsToolbar(), filter=show_completions_toolbar( python_input)), # Docstring region. ConditionalContainer(content=Window( height=D.exact(1), char='\u2500', style='class:separator'), filter=HasSignature(python_input) & ShowDocstring(python_input) & ~is_done), ConditionalContainer( content=Window( BufferControl( buffer=python_input.docstring_buffer, lexer=SimpleLexer(style='class:docstring'), #lexer=PythonLexer, ), height=D(max=12)), filter=HasSignature(python_input) & ShowDocstring(python_input) & ~is_done), ]), ConditionalContainer(content=HSplit([ python_sidebar(python_input), Window(style='class:sidebar,separator', height=1), python_sidebar_navigation(python_input), ]), filter=ShowSidebar(python_input) & ~is_done) ]), ] + extra_toolbars + [ VSplit([ status_bar(python_input), show_sidebar_button_info(python_input), ]) ]) return Layout(root_container)
'snake', 'spider', 'turkey', 'turtle', ], ignore_case=True) # The layout buff = Buffer(completer=animal_completer, complete_while_typing=True) body = FloatContainer(content=HSplit([ Window(FormattedTextControl('Press "q" to quit.'), height=1, style='reverse'), Window(BufferControl(buffer=buff)), ]), floats=[ Float(xcursor=True, ycursor=True, content=CompletionsMenu(max_height=16, scroll_offset=1)) ]) # Key bindings kb = KeyBindings() @kb.add('q') @kb.add('c-c') def _(event): " Quit application. " event.app.exit()
def start_app(args): """Text-based GUI application""" cmd = Commands() completer = WordCompleter(cmd.commands(), meta_dict=cmd.meta_dict(), ignore_case=True) history = InMemoryHistory() # Individual windows input_field = TextArea(height=1, prompt='ctserial> ', style='class:input-field', completer=completer, history=history) output_field = TextArea(scrollbar=True, style='class:output-field', text='') statusbar = Window(content=FormattedTextControl(get_statusbar_text), height=1, style='class:statusbar') # Organization of windows body = FloatContainer(HSplit([ input_field, Window(height=1, char='-', style='class:line'), output_field, statusbar ]), floats=[ Float(xcursor=True, ycursor=True, content=CompletionsMenu(max_height=16, scroll_offset=1)) ]) # Adding menus root_container = MenuContainer( body=body, menu_items=[], # menu_items=[ # MenuItem('Project ', children=[ # MenuItem('New'), # MenuItem('Open'), # MenuItem('Save'), # MenuItem('Save as...'), # MenuItem('-', disabled=True), # MenuItem('Exit'), ]), # MenuItem('View ', children=[ # MenuItem('Split'), ]), # MenuItem('Info ', children=[ # MenuItem('Help'), # MenuItem('About'), ]), ], floats=[ Float(xcursor=True, ycursor=True, content=CompletionsMenu(max_height=16, scroll_offset=1)), ]) # The key bindings. kb = KeyBindings() @kb.add('space') def _(event): input_text = input_field.text cursor = len(input_text) input_updated = input_text[:cursor] + ' ' + input_text[cursor + 1:] cursor += 1 input_field.buffer.document = Document(text=input_updated, cursor_position=cursor) input_field.buffer.completer = WordCompleter([], ignore_case=True) @kb.add('enter', filter=has_focus(input_field)) def _(event): # Process commands on prompt after hitting enter key # tx_bytes = parse_command(input_field.text, event=event) input_field.buffer.completer = WordCompleter(cmd.commands(), meta_dict=cmd.meta_dict(), ignore_case=True) if len(input_field.text) == 0: return output_text = cmd.execute(input_field.text, output_field.text, event) input_field.buffer.reset(append_to_history=True) # For commands that do not send data to serial device if output_text == None: input_field.text = '' return # For invalid commands forcing users to correct them elif output_text == False: return # For invalid commands forcing users to correct them else: output_field.buffer.document = Document( text=output_text, cursor_position=len(output_text)) input_field.text = '' @kb.add('c-c') def _(event): """Pressing Control-C will copy highlighted text to clipboard""" data = output_field.buffer.copy_selection() get_app().clipboard.set_data(data) @kb.add('c-p') def _(event): """Pressing Control-P will paste text from clipboard""" input_field.buffer.paste_clipboard_data(get_app().clipboard.get_data()) @kb.add('c-q') def _(event): " Pressing Ctrl-Q will exit the user interface. " cmd.do_exit(input_field.text, output_field.text, event) @kb.add('c-d') def _(event): """Press Ctrl-D to start the python debugger""" import pdb pdb.set_trace() style = Style([ # ('output-field', 'bg:#000000 #ffffff'), # ('input-field', 'bg:#000000 #ffffff'), ('line', '#004400'), ('statusbar', 'bg:#AAAAAA') ]) # Run application. application = MyApplication(layout=Layout(root_container, focused_element=input_field), key_bindings=kb, style=style, mouse_support=True, full_screen=True) application.run()
def __init__( self, message: InquirerPyMessage, choices: InquirerPyListChoices, default: InquirerPyDefault = None, style: InquirerPyStyle = None, vi_mode: bool = False, qmark: str = "?", amark: str = "?", pointer: str = INQUIRERPY_POINTER_SEQUENCE, instruction: str = "", long_instruction: str = "", transformer: Callable[[Any], Any] = None, filter: Callable[[Any], Any] = None, height: Union[int, str] = None, max_height: Union[int, str] = None, multiselect: bool = False, marker: str = INQUIRERPY_POINTER_SEQUENCE, marker_pl: str = " ", border: bool = False, validate: InquirerPyValidate = None, invalid_message: str = "Invalid input", keybindings: Dict[str, List[Dict[str, Any]]] = None, show_cursor: bool = True, cycle: bool = True, wrap_lines: bool = True, raise_keyboard_interrupt: bool = True, mandatory: bool = True, mandatory_message: str = "Mandatory prompt", session_result: InquirerPySessionResult = None, ) -> None: if not hasattr(self, "_content_control"): self.content_control = InquirerPyListControl( choices=choices, default=default, pointer=pointer, marker=marker, session_result=session_result, multiselect=multiselect, marker_pl=marker_pl, ) super().__init__( message=message, style=style, border=border, vi_mode=vi_mode, qmark=qmark, amark=amark, instruction=instruction, long_instruction=long_instruction, transformer=transformer, filter=filter, validate=validate, invalid_message=invalid_message, multiselect=multiselect, keybindings=keybindings, cycle=cycle, wrap_lines=wrap_lines, raise_keyboard_interrupt=raise_keyboard_interrupt, mandatory=mandatory, mandatory_message=mandatory_message, session_result=session_result, ) self._show_cursor = show_cursor self._dimmension_height, self._dimmension_max_height = calculate_height( height, max_height, height_offset=self.height_offset) main_content_window = Window( content=self.content_control, height=Dimension( max=self._dimmension_max_height, preferred=self._dimmension_height, ), dont_extend_height=True, ) if self._border: main_content_window = Frame(main_content_window) self._layout = FloatContainer( content=HSplit([ MessageWindow( message=self._get_prompt_message_with_cursor if self._show_cursor else self._get_prompt_message, filter=True, wrap_lines=self._wrap_lines, show_cursor=self._show_cursor, ), ConditionalContainer(main_content_window, filter=~IsDone()), ConditionalContainer( Window(content=DummyControl()), filter=~IsDone() & self._is_displaying_long_instruction, ), InstructionWindow( message=self._long_instruction, filter=~IsDone() & self._is_displaying_long_instruction, wrap_lines=self._wrap_lines, ), ]), floats=[ ValidationFloat( invalid_message=self._get_error_message, filter=self._is_invalid & ~IsDone(), wrap_lines=self._wrap_lines, left=0, bottom=self._validation_window_bottom_offset, ), ], ) self.application = Application( layout=Layout(self._layout), style=self._style, key_bindings=self._kb, after_render=self._after_render, )
quit_text = "Press 'q' to quit." body = FloatContainer( content=Window(FormattedTextControl(LIPSUM), wrap_lines=True), floats=[ # Important note: Wrapping the floating objects in a 'Frame' is # only required for drawing the border around the # floating text. We do it here to make the layout more # obvious. # Left float. Float(Frame(Window(FormattedTextControl(left_text), width=20, height=4)), transparent=False, left=0), # Right float. Float(Frame( Window(FormattedTextControl(right_text), width=20, height=4)), transparent=True, right=0), # Quit text. Float(Frame(Window(FormattedTextControl(quit_text), width=18, height=1), style='bg:#ff44ff #ffffff'), top=1), ]) # 2. Key bindings
def __init__(self, command=['/bin/bash'], before_exec_func=None, bell_func=None, style='', width=None, height=None, done_callback=None): self.terminal_control = _TerminalControl( command=command, before_exec_func=before_exec_func, bell_func=bell_func, done_callback=done_callback) self.terminal_window = _Window(terminal_control=self.terminal_control, content=self.terminal_control, wrap_lines=False) # Key bindigns for copy buffer. kb = KeyBindings() @kb.add('c-c') def _(event): self.exit_copy_mode() @kb.add('space') def _(event): " Reset selection. " event.current_buffer.start_selection() @kb.add('enter', filter=has_selection) def _(event): " Reset selection. " data = event.current_buffer.copy_selection() event.app.clipboard.set_data(data) self.search_toolbar = SearchToolbar( forward_search_prompt='Search down: ', backward_search_prompt='Search up: ') self.copy_buffer = Buffer(read_only=True) self.copy_buffer_control = BufferControl( buffer=self.copy_buffer, search_buffer_control=self.search_toolbar.control, include_default_input_processors=False, input_processors=[ _UseStyledTextProcessor(self), HighlightSelectionProcessor(), HighlightSearchProcessor(), HighlightIncrementalSearchProcessor(), ], preview_search= True, # XXX: not sure why we need twice preview_search. key_bindings=kb) self.copy_window = Window(content=self.copy_buffer_control, wrap_lines=False) self.is_copying = False self.styled_copy_lines = [ ] # List of lists of (style, text) tuples, for each line. @Condition def is_copying(): return self.is_copying self.container = FloatContainer( content=HSplit( [ # Either show terminal window or copy buffer. VSplit([ # XXX: this nested VSplit should not have been necessary, # but the ConditionalContainer which width can become # zero will collapse the other elements. ConditionalContainer(self.terminal_window, filter=~is_copying), ConditionalContainer(self.copy_window, filter=is_copying), ]), ConditionalContainer(self.search_toolbar, filter=is_copying), ], style=style, width=width, height=height), floats=[ Float(top=0, right=0, height=1, content=ConditionalContainer(Window( content=FormattedTextControl( text=self._copy_position_formatted_text), style='class:copy-mode-cursor-position'), filter=is_copying)) ])
def __init__(self, history): search_toolbar = SearchToolbar() self.help_buffer_control = BufferControl( buffer=history.help_buffer, lexer=PygmentsLexer(RstLexer)) help_window = _create_popup_window( title='History Help', body=Window( content=self.help_buffer_control, right_margins=[ScrollbarMargin(display_arrows=True)], scroll_offsets=ScrollOffsets(top=2, bottom=2))) self.default_buffer_control = BufferControl( buffer=history.default_buffer, input_processors=[GrayExistingText(history.history_mapping)], lexer=PygmentsLexer(PythonLexer)) self.history_buffer_control = BufferControl( buffer=history.history_buffer, lexer=PygmentsLexer(PythonLexer), search_buffer_control=search_toolbar.control, preview_search=True) history_window = Window( content=self.history_buffer_control, wrap_lines=False, left_margins=[HistoryMargin(history)], scroll_offsets=ScrollOffsets(top=2, bottom=2)) self.root_container = HSplit([ # Top title bar. Window( content=FormattedTextControl(_get_top_toolbar_fragments), align=WindowAlign.CENTER, style='class:status-toolbar'), FloatContainer( content=VSplit([ # Left side: history. history_window, # Separator. Window(width=D.exact(1), char=BORDER.LIGHT_VERTICAL, style='class:separator'), # Right side: result. Window( content=self.default_buffer_control, wrap_lines=False, left_margins=[ResultMargin(history)], scroll_offsets=ScrollOffsets(top=2, bottom=2)), ]), floats=[ # Help text as a float. Float(width=60, top=3, bottom=2, content=ConditionalContainer( content=help_window, filter=has_focus(history.help_buffer))), ] ), # Bottom toolbars. ArgToolbar(), search_toolbar, Window( content=FormattedTextControl( partial(_get_bottom_toolbar_fragments, history=history)), style='class:status-toolbar'), ]) self.layout = Layout(self.root_container, history_window)
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)), ])