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 __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 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 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 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 create_completion_float(self) -> Float: return Float(xcursor=True, ycursor=True, transparent=True, attach_to_window=self.input_window, content=CompletionsMenu(scroll_offset=1, max_height=16, extra_filter=has_focus( self.input_buffer)))
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 action(self): def btn_ok_handler(): self.app.remove_floats() btn_ok = Button(text="OK", handler=btn_ok_handler) dialog = Dialog(title="%s Actions" % self.title, body=Label( text="No actions are supported on this screen", dont_extend_height=True), buttons=[btn_ok]) return Float(content=dialog), btn_ok
def __build_root_container(body, do_save_file, do_share_file, do_file_info, do_exit, do_cut, do_copy, do_paste, do_delete, do_about, bindings) -> \ MenuContainer: """ Build a container that holds all components inside. :type body: HSplit :type do_save_file: function :type do_share_file: function :type do_file_info: function :type do_exit: function :type do_cut: function :type do_copy: function :type do_paste: function :type do_delete: function :type do_about: function :type bindings: KeyBindings :return: MenuContainer component """ return MenuContainer( body=body, menu_items=[ MenuItem( "File", children=[ MenuItem("Save", handler=do_save_file), MenuItem("Share", handler=do_share_file), MenuItem("Info", handler=do_file_info), MenuItem("-", disabled=True), MenuItem("Exit", handler=do_exit), ], ), MenuItem( "Edit", children=[ MenuItem("Cut", handler=do_cut), MenuItem("Copy", handler=do_copy), MenuItem("Paste", handler=do_paste), MenuItem("Delete", handler=do_delete) ], ), MenuItem("Info", children=[MenuItem("About", handler=do_about)]), ], floats=[ Float( xcursor=True, ycursor=True, content=CompletionsMenu(max_height=16, scroll_offset=1), ), ], key_bindings=bindings, )
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: 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"), ), ], )
async def show_dialog_as_float(dialog): " Coroutine. " float_ = Float(content=dialog) root_container.floats.insert(0, float_) focused_before = app.layout.current_window app.layout.focus(dialog) result = await dialog.future app.layout.focus(focused_before) if float_ in root_container.floats: root_container.floats.remove(float_) return result
def help_modal(title, text): help_container = Float( Frame( HSplit([ Window(FormattedTextControl(title), height=1, style="reverse"), Window(height=1), Window(FormattedTextControl(text)), Window( FormattedTextControl("[?] Close this window"), height=1, style="reverse", ), ]))) return help_container
def show_dialog(dialog): " Coroutine. " app = get_app() float_ = Float(content=dialog) app.layout.container.floats.insert(0, float_) focused_before = app.layout.current_window app.layout.focus(dialog) result = yield dialog.future app.layout.focus(focused_before) if float_ in app.layout.container.floats: app.layout.container.floats.remove(float_) raise Return(result)
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 update_selected_tab(self): float_window = Float( self.session.tabs[self.session.selected_tab_index].container, top=0, bottom=0, left=0, right=0) if len(self.float_container.floats) == 1: del self.float_container.floats[0] self.float_container.floats.append(float_window) elif len(self.float_container.floats) < 1: self.float_container.floats.append(float_window) return self.session.tabs[self.session.selected_tab_index].container
async def show_dialog_as_float(dialog): ' Coroutine. ' float_ = Float(content=dialog) ROOT_CONTAINER.floats.insert(0, float_) app = get_app() focused_before = app.layout.current_window app.layout.focus(dialog) result = await dialog.future app.layout.focus(focused_before) if float_ in ROOT_CONTAINER.floats: ROOT_CONTAINER.floats.remove(float_) return result
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 conditional_float(char, left=None, right=None, top=None, bottom=None, width=None, height=None): return Float(content=ConditionalContainer(Window( char=char, style='class:border'), filter=is_selected), left=left, right=right, top=top, bottom=bottom, width=width, height=height, z_index=Z_INDEX.HIGHLIGHTED_BORDER)
async def __show_dialog_as_float(self, dialog) -> None: """ Show dialog above main application window. :param dialog component """ float_ = Float(content=dialog) self.root_container.floats.insert(0, float_) app = get_app() focused_before = app.layout.current_window app.layout.focus(dialog) result = await dialog.future app.layout.focus(focused_before) if float_ in self.root_container.floats: self.root_container.floats.remove(float_) return result
async def show_dialog_as_float(dialog): """Coroutine.""" app = get_app() root_container = app.layout.container float_ = Float(content=dialog) root_container.floats.insert(0, float_) focused_before = app.layout.current_window app.layout.focus(dialog) app.layout.current_window.dialog = dialog result = await dialog.future if hasattr(app.layout.current_window, 'dialog'): del (app.layout.current_window.dialog) app.layout.focus(focused_before) if float_ in root_container.floats: root_container.floats.remove(float_) return result
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 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], ))
bottom_text = "Floating\nbottom" center_text = "Floating\ncenter" 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=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),
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)
'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() # The `Application`
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()
left_text = HTML("<reverse>transparent=False</reverse>\n") right_text = HTML("<reverse>transparent=True</reverse>") 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), ])
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)) ])