Skip to content

Commit

Permalink
Refactoring of the event loop:
Browse files Browse the repository at this point in the history
- Use coroutines whenever possible.
- Don't pass the loop around everywhere. Use get_event_loop (just like asyncio).
- A couple of bug fixes.
- Fixed run_system_command.
  • Loading branch information
jonathanslenders committed May 23, 2017
1 parent bc10816 commit 8346a99
Show file tree
Hide file tree
Showing 26 changed files with 566 additions and 674 deletions.
20 changes: 2 additions & 18 deletions examples/full-screen/split-screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,18 @@

from prompt_toolkit.application import Application
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.eventloop.defaults import create_event_loop
from prompt_toolkit.key_binding.defaults import load_key_bindings
from prompt_toolkit.key_binding.key_bindings import KeyBindings, merge_key_bindings
from prompt_toolkit.layout.containers import VSplit, HSplit, Window, Align
from prompt_toolkit.layout.controls import BufferControl, FormattedTextControl
from prompt_toolkit.layout.layout import Layout


# 1. Create an event loop
# --------------------

# We need to create an eventloop for this application. An eventloop is
# basically a while-true loop that waits for user input, and when it receives
# something (like a key press), it will send that to the application. Usually,
# you want to use this `create_eventloop` shortcut, which -- according to the
# environment (Windows/posix) -- returns something that will work there. If you
# want to run your application inside an "asyncio" environment, you'd have to
# pass another eventloop.

loop = create_event_loop()


# 3. Create the buffers
# ------------------

left_buffer = Buffer(loop=loop)
right_buffer = Buffer(loop=loop)
left_buffer = Buffer()
right_buffer = Buffer()

# 1. First we create the layout
# --------------------------
Expand Down Expand Up @@ -150,7 +135,6 @@ def default_buffer_changed(_):
# This glues everything together.

application = Application(
loop=loop,
layout=Layout(root_container, focussed_window=left_window),
key_bindings=all_bindings,

Expand Down
14 changes: 2 additions & 12 deletions examples/full-screen/yes-no-dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from prompt_toolkit.application import Application
from prompt_toolkit.contrib.completers import WordCompleter
from prompt_toolkit.eventloop import create_event_loop, set_event_loop
from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous
from prompt_toolkit.key_binding.defaults import load_key_bindings
from prompt_toolkit.key_binding.key_bindings import KeyBindings, merge_key_bindings
Expand All @@ -19,12 +18,6 @@
from pygments.lexers import HtmlLexer


loop = create_event_loop()
set_event_loop(loop)


# >>>

def accept_yes(app):
app.set_return_value(True)

Expand All @@ -35,15 +28,13 @@ def do_exit(app):
app.set_return_value(False)


# Make partials that pass the loop everywhere.

yes_button = Button(text='Yes', handler=accept_yes)
no_button = Button(text='No', handler=accept_no)
textfield = TextArea(lexer=PygmentsLexer(HtmlLexer))
checkbox1 = Checkbox(text='Checkbox')
checkbox2 = Checkbox(text='Checkbox')

radios = RadioList(loop=loop, values=[
radios = RadioList(values=[
('Red', 'red'),
('Green', 'green'),
('Blue', 'blue'),
Expand Down Expand Up @@ -87,7 +78,7 @@ def do_exit(app):
),
])

root_container = MenuContainer(loop=loop, body=root_container, menu_items=[
root_container = MenuContainer(body=root_container, menu_items=[
MenuItem('File', children=[
MenuItem('New'),
MenuItem('Open', children=[
Expand Down Expand Up @@ -162,7 +153,6 @@ def do_exit(app):


application = Application(
loop=loop,
layout=Layout(
root_container,
focussed_window=yes_button,
Expand Down
4 changes: 2 additions & 2 deletions examples/tutorial/sqlite-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
'delete', 'from', 'where', 'table'], ignore_case=True)

style = Style.from_dict({
'completion-menu,current-completion': 'bg:#00aaaa #000000',
'completion-menu,completion': 'bg:#008888 #ffffff',
'completion-menu.current-completion': 'bg:#00aaaa #000000',
'completion-menu.completion': 'bg:#008888 #ffffff',
})


Expand Down
Loading

0 comments on commit 8346a99

Please sign in to comment.