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'),
#!/usr/bin/env python """ Example usage of 'print_container', a tool to print any layout in a non-interactive way. """ from prompt_toolkit_dev.shortcuts import print_container from prompt_toolkit_dev.widgets import Frame, TextArea print_container( Frame( TextArea(text='Hello world!\n'), title='Stage: parse', ))
button2 = Button('Button 2', handler=button2_clicked) button3 = Button('Button 3', handler=button3_clicked) button4 = Button('Exit', handler=exit_clicked) text_area = TextArea(focusable=True) # Combine all the widgets in a UI. # The `Box` object ensures that padding will be inserted around the containing # widget. It adapts automatically, unless an explicit `padding` amount is given. root_container = Box( HSplit([ Label(text='Press `Tab` to move the focus.'), VSplit([ Box(body=HSplit([button1, button2, button3, button4], padding=1), padding=1, style='class:left-pane'), Box(body=Frame(text_area), padding=1, style='class:right-pane'), ]), ]), ) layout = Layout(container=root_container, focused_element=button1) # Key bindings. kb = KeyBindings() kb.add('tab')(focus_next) kb.add('s-tab')(focus_previous) # Styling. style = Style([ ('left-pane', 'bg:#888800 #000000'), ('right-pane', 'bg:#00aa00 #000000'), ('button', '#000000'),
# 1. The layout 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), ])
from prompt_toolkit_dev.widgets import Frame TITLE = HTML(""" <u>HSplit HorizontalAlign</u> example. Press <b>'q'</b> to quit.""") LIPSUM = """\ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas quis interdum enim.""" # 1. The layout body = HSplit([ Frame( Window(FormattedTextControl(TITLE), height=2), style='bg:#88ff88 #000000'), HSplit([ # Left alignment. VSplit([ Window(FormattedTextControl(HTML('<u>LEFT</u>')), width=10, ignore_content_width=True, style='bg:#ff3333 ansiblack', align=WindowAlign.CENTER), VSplit([ Window(FormattedTextControl(LIPSUM), height=4, style='bg:#444488'), Window(FormattedTextControl(LIPSUM), height=4, style='bg:#444488'), Window(FormattedTextControl(LIPSUM), height=4, style='bg:#444488'), ], padding=1, padding_style='bg:#888888', align=HorizontalAlign.LEFT, height=5, padding_char='|'), ]), # Center alignment. VSplit([ Window(FormattedTextControl(HTML('<u>CENTER</u>')), width=10, ignore_content_width=True, style='bg:#ff3333 ansiblack', align=WindowAlign.CENTER),
('Orange', 'orange'), ('Yellow', 'yellow'), ('Purple', 'Purple'), ('Brown', 'Brown'), ]) animal_completer = WordCompleter([ 'alligator', 'ant', 'ape', 'bat', 'bear', 'beaver', 'bee', 'bison', 'butterfly', 'cat', 'chicken', 'crocodile', 'dinosaur', 'dog', 'dolphin', 'dove', 'duck', 'eagle', 'elephant', 'fish', 'goat', 'gorilla', 'kangaroo', 'leopard', 'lion', 'mouse', 'rabbit', 'rat', 'snake', 'spider', 'turkey', 'turtle', ], ignore_case=True) root_container = HSplit([ VSplit([ Frame(body=Label(text='Left frame\ncontent')), Dialog(title='The custom window', body=Label('hello\ntest')), textfield, ], height=D()), VSplit([ Frame(body=ProgressBar(), title='Progress bar'), Frame(title='Checkbox list', body=HSplit([ checkbox1, checkbox2, ])), Frame(title='Radio list', body=radios), ], padding=1), Box(
#!/usr/bin/env python """ A simple example of a a text area displaying "Hello World!". """ from prompt_toolkit_dev.application import Application from prompt_toolkit_dev.key_binding import KeyBindings from prompt_toolkit_dev.layout import Layout from prompt_toolkit_dev.widgets import Box, Frame, TextArea # Layout for displaying hello world. # (The frame creates the border, the box takes care of the margin/padding.) root_container = Box( Frame( TextArea( text='Hello world!\nPress control-c to quit.', width=40, height=10, )), ) layout = Layout(container=root_container) # Key bindings. kb = KeyBindings() @kb.add('c-c') def _(event): " Quit when control-c is pressed. " event.app.exit() # Build a main application object.