def mnk_game_tui( board, game_ai_class, method, ai_timeout, computer_plays, verbose): buffer1 = pt.buffer.Buffer() # Editable buffer. root_container = pt.layout.containers.VSplit([ # One window that holds the BufferControl with the default buffer on # the left. pt.layout.containers.Window( content=pt.layout.controls.BufferControl(buffer=buffer1)), # A vertical line in the middle. We explicitly specify the width, to # make sure that the layout engine will not try to divide the whole # width by three for all these windows. The window will simply fill its # content by repeating this character. pt.layout.containers.Window(width=20, height=10, char='|'), # Display the text 'Hello world' on the right. pt.layout.containers.Window( content=pt.layout.controls.FormattedTextControl( text='<b>Hello</b> world')), ]) lo = pt.layout.layout.Layout(root_container) app = pt.Application( layout=lo, key_bindings=kb, full_screen=False) app.run()
def init(): root_container = containers.VSplit(data.app_windows) data.app_layout = layout.Layout(root_container) data.application = prompt_toolkit.Application(layout=data.app_layout, full_screen=True, mouse_support=True)
def main(): global app loop = asyncio.get_event_loop() app = ptk.Application(layout=Layout(root_container), key_bindings=global_kb, full_screen=True) connection_task = loop.create_task(create_connection()) message_queue_task = loop.create_task( message_queue_processor(message_queue)) final_task = asyncio.gather(connection_task, message_queue_task, app.run_async().to_asyncio_future()) loop.run_until_complete(final_task)
def create_bottom_repl_application( completer=None, history=None, key_bindings_registry=None, on_abort=prompt_toolkit.interface.AbortAction.RETRY, on_exit=prompt_toolkit.interface.AbortAction.RAISE_EXCEPTION, accept_action=prompt_toolkit.interface.AcceptAction.RETURN_DOCUMENT): # Create list of input processors that we need input_processors = [ prompt_toolkit.layout.processors.ConditionalProcessor( prompt_toolkit.layout.processors.HighlightSearchProcessor( preview_search=True), prompt_toolkit.filters.HasFocus( prompt_toolkit.enums.SEARCH_BUFFER)), prompt_toolkit.layout.processors.HighlightSelectionProcessor(), prompt_toolkit.layout.processors.ConditionalProcessor( prompt_toolkit.layout.processors.AppendAutoSuggestion(), prompt_toolkit.filters.HasFocus( prompt_toolkit.enums.DEFAULT_BUFFER) & ~prompt_toolkit.filters.IsDone()), prompt_toolkit.layout.prompt.DefaultPrompt(lambda cli: []), StoreTokens() ] # Create layout (essentially a dummy - we draw tokens ourselves) layout = prompt_toolkit.layout.Window( prompt_toolkit.layout.BufferControl(input_processors=input_processors, preview_search=True), get_height=lambda cli: prompt_toolkit.layout.dimension.LayoutDimension. exact(1), wrap_lines=False, ) # Create application return prompt_toolkit.Application( layout=layout, buffer=prompt_toolkit.buffer.Buffer( history=history, completer=completer, accept_action=accept_action, initial_document=prompt_toolkit.document.Document(''), ), key_bindings_registry=key_bindings_registry, on_abort=on_abort, on_exit=on_exit)
# ) list_directory=subprocess.getoutput(["tree", "-L", "3", "/"]) buffer1 = prompt_toolkit.buffer.Buffer() root_container = prompt_toolkit.layout.containers.VSplit([ prompt_toolkit.layout.containers.Window(content=prompt_toolkit.layout.controls.BufferControl(buffer=buffer1)), prompt_toolkit.layout.containers.Window(width=1, char='|'), prompt_toolkit.layout.containers.Window(content=prompt_toolkit.layout.controls.FormattedTextControl(text=list_directory)), ]) layout = prompt_toolkit.layout.Layout(root_container) kb = prompt_toolkit.key_binding.KeyBindings() @kb.add('c-q') def exit_(event): """ pressing Ctrl-Q will exit the user interfact Setting a return value means: quit the event loop that drives the user interfact and return thei value from the `CommandLineInterface.run()` call. """ b = prompt_toolkit.key_binding.KeyBindings() @kb.add('c-rkkkkkkkkkkkkkkkkkkkkkVyjjjjjjjjjjVpxlllllllllllllllll app = prompt_toolkit.Application(key_bindings=kb, layout=layout, full_screen=True) app.run()
def main(): global root global folder def rerender(event): global folder event.app.current_buffer.set_document( pt.document.Document(text = makeDirText(folder)), bypass_readonly = True) kb = pt.key_binding.KeyBindings() globalKb = pt.key_binding.KeyBindings() promptKb = pt.key_binding.KeyBindings() folder = root @globalKb.add('c-q') def exit(event): event.app.exit() @kb.add('c-m') def open(event): global folder line = event.app.current_buffer.document.current_line if line[0] == ' ': num = int(line[1:line.find('.')]) if not num > len(folder.folders) + 1 and folder.folders != list(): folder = folder.folders[num - 1] rerender(event) else: num -= len(folder.folders) + 2 openFile(os.path.join(folder.dir, folder.files[num])) @kb.add('h') def home(event): global folder global root root.Scan() folder = root rerender(event) @kb.add('b') def back(event): global folder if not folder.parent == None: folder = folder.parent folder.Scan() rerender(event) @kb.add('m') def make(event): global folder MakeTemplate() folder.Scan() rerender(event) @kb.add('n') def new(event): global folder event.app.layout.focus(prompt) @promptKb.add('c-m') def AcceptNew(event): global folder name = event.app.current_buffer.document.current_line event.app.current_buffer.set_document(pt.document.Document()) event.app.layout.focus(displayer) newPage(name) rerender(event) text = pt.document.Document(text = makeDirText(root)) displayer = pt.buffer.Buffer(read_only = True, multiline = True, document = text) prompt = pt.buffer.Buffer(multiline = False) bottomText1 = pt.layout.controls.FormattedTextControl( text = pt.HTML('<ansigreen>c-q -> exit, enter -> open, h -> go to home dir, b -> go up a dir </ansigreen>')) bottomText2 = pt.layout.controls.FormattedTextControl( text = pt.HTML('<ansigreen>n -> new dir, m -> make new note file </ansigreen>')) aboveText1 = pt.layout.controls.FormattedTextControl( text = pt.HTML('<ansigreen>Python Note Manager v.2</ansigreen>')) root_container = pt.layout.containers.HSplit([ pt.layout.containers.Window(content = aboveText1, height = 1), pt.layout.containers.Window( content = pt.layout.controls.BufferControl(displayer, key_bindings = kb)), pt.layout.containers.Window( content = pt.layout.controls.BufferControl(prompt, key_bindings = promptKb), height = 1), pt.layout.containers.Window(content = bottomText1, height = 1), pt.layout.containers.Window(content = bottomText2, height = 1) ]) layout = pt.layout.Layout(root_container) app = pt.Application(key_bindings = globalKb, layout = layout, full_screen = True) app.run()
#!/usr/bin/env python3 """ screen.screen.data Data in screen application """ import threading import prompt_toolkit from prompt_toolkit import layout from prompt_toolkit import widgets from prompt_toolkit.key_binding import KeyBindings application = prompt_toolkit.Application() app_layout = None console_window = widgets.TextArea() messages_window = widgets.TextArea() app_windows = [] screen_up_event = threading.Event() screen_down_event = threading.Event() key_binding = KeyBindings() message_window_key_binding = KeyBindings() key_seq = [] kern_proc = None