body = HSplit([ Window(FormattedTextControl(left_text), align=WindowAlign.LEFT), Window(height=1, char='-'), Window(FormattedTextControl(center_text), align=WindowAlign.CENTER), Window(height=1, char='-'), Window(FormattedTextControl(right_text), align=WindowAlign.RIGHT), ]) # 2. Key bindings kb = KeyBindings() @kb.add('q') def _(event): " Quit application. " event.app.exit() # 3. The `Application` application = Application(layout=Layout(body), key_bindings=kb, full_screen=True) def run(): application.run() if __name__ == '__main__': run()
@bindings.add('q') def _(event): " Quit. " event.app.exit() style = Style.from_dict({ 'status': 'reverse', 'status.position': '#aaaa00', 'status.key': '#ffaa00', 'not-searching': '#888888', }) # create application. application = Application(layout=Layout( root_container, focused_element=text_area, ), key_bindings=bindings, enable_page_navigation_bindings=True, mouse_support=True, style=style, full_screen=True) def run(): application.run() if __name__ == '__main__': run()
def main(): # The layout. search_field = SearchToolbar() # For reverse search. output_field = TextArea(style='class:output-field', text=help_text) input_field = TextArea(height=1, prompt='>>> ', style='class:input-field', multiline=False, wrap_lines=False, search_field=search_field) container = HSplit([ output_field, Window(height=1, char='-', style='class:line'), input_field, search_field, ]) # Attach accept handler to the input field. We do this by assigning the # handler to the `TextArea` that we created earlier. it is also possible to # pass it to the constructor of `TextArea`. # NOTE: It's better to assign an `accept_handler`, rather then adding a # custom ENTER key binding. This will automatically reset the input # field and add the strings to the history. def accept(buff): # Evaluate "calculator" expression. try: output = '\n\nIn: {}\nOut: {}'.format( input_field.text, eval(input_field.text)) # Don't do 'eval' in real code! except BaseException as e: output = '\n\n{}'.format(e) new_text = output_field.text + output # Add text to output buffer. output_field.buffer.document = Document(text=new_text, cursor_position=len(new_text)) input_field.accept_handler = accept # The key bindings. kb = KeyBindings() @kb.add('c-c') @kb.add('c-q') def _(event): " Pressing Ctrl-Q or Ctrl-C will exit the user interface. " event.app.exit() # Style. style = Style([ ('output-field', 'bg:#000044 #ffffff'), ('input-field', 'bg:#000000 #ffffff'), ('line', '#004400'), ]) # Run application. application = Application(layout=Layout(container, focused_element=input_field), key_bindings=kb, style=style, mouse_support=True, full_screen=True) application.run()
Window(FormattedTextControl(LIPSUM), style='bg:#444488'), ], padding=1, padding_style='bg:#888888', align=HorizontalAlign.JUSTIFY, height=5, padding_char='|'), ]), ], padding=1, padding_style="bg:#ff3333 #ffffff", padding_char='.', align=VerticalAlign.TOP) ]) # 2. Key bindings kb = KeyBindings() @kb.add('q') def _(event): " Quit application. " event.app.exit() # 3. The `Application` application = Application( layout=Layout(body), key_bindings=kb, full_screen=True) def run(): application.run() if __name__ == '__main__': run()
When the buffer on the left changes, update the buffer on the right. We just reverse the text. """ right_buffer.text = left_buffer.text[::-1] left_buffer.on_text_changed += default_buffer_changed # 3. Creating an `Application` instance # ---------------------------------- # This glues everything together. application = Application( layout=Layout(root_container, focused_element=left_window), key_bindings=kb, # Let's add mouse support! mouse_support=True, # Using an alternate screen buffer means as much as: "run full screen". # It switches the terminal to an alternate screen. full_screen=True) # 4. Run the application # ------------------- def run():
'window.border shadow': '#444444', 'focused button': 'bg:#880000 #ffffff noinherit', # Styling for Dialog widgets. 'radiolist focused': 'noreverse', 'radiolist focused radio.selected': 'reverse', 'button-bar': 'bg:#aaaaff' }) application = Application( layout=Layout( root_container, focused_element=yes_button, ), key_bindings=bindings, style=style, mouse_support=True, full_screen=True) def run(): result = application.run() print('You said: %r' % result) if __name__ == '__main__': run()
MenuItem('About', handler=do_about), ]), ], floats=[ Float(xcursor=True, ycursor=True, content=CompletionsMenu(max_height=16, scroll_offset=1)), ], key_bindings=bindings) style = Style.from_dict({ 'status': 'reverse', 'shadow': 'bg:#440044', }) layout = Layout(root_container, focused_element=text_field) application = Application(layout=layout, enable_page_navigation_bindings=True, style=style, mouse_support=True, full_screen=True) def run(): application.run() if __name__ == '__main__': run()