Skip to content

Create new event loop as fallback behaviour. #5753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ class App(Generic[ReturnType], DOMNode):
scrollbar-background-active: ansi_default;
scrollbar-color: ansi_blue;
scrollbar-color-active: ansi_bright_blue;
scrollbar-color-hover: ansi_bright_blue;
scrollbar-corner-color: ansi_default;
scrollbar-color-hover: ansi_bright_blue;
scrollbar-corner-color: ansi_default;
}

.bindings-table--key {
Expand All @@ -336,18 +336,18 @@ class App(Generic[ReturnType], DOMNode):
}

/* When a widget is maximized */
Screen.-maximized-view {
Screen.-maximized-view {
layout: vertical !important;
hatch: right $panel;
overflow-y: auto !important;
align: center middle;
.-maximized {
dock: initial !important;
dock: initial !important;
}
}
/* Fade the header title when app is blurred */
&:blur HeaderTitle {
text-opacity: 50%;
&:blur HeaderTitle {
text-opacity: 50%;
}
}
*:disabled:can-focus {
Expand Down Expand Up @@ -399,7 +399,7 @@ class MyApp(App[None]):

ALLOW_SELECT: ClassVar[bool] = True
"""A switch to toggle arbitrary text selection for the app.

Note that this doesn't apply to Input and TextArea which have builtin support for selection.
"""

Expand Down Expand Up @@ -445,7 +445,7 @@ class MyApp(App[None]):
"""The default value of [Screen.ALLOW_IN_MAXIMIZED_VIEW][textual.screen.Screen.ALLOW_IN_MAXIMIZED_VIEW]."""

CLICK_CHAIN_TIME_THRESHOLD: ClassVar[float] = 0.5
"""The maximum number of seconds between clicks to upgrade a single click to a double click,
"""The maximum number of seconds between clicks to upgrade a single click to a double click,
a double click to a triple click, etc."""

BINDINGS: ClassVar[list[BindingType]] = [
Expand All @@ -472,7 +472,7 @@ class MyApp(App[None]):

ESCAPE_TO_MINIMIZE: ClassVar[bool] = True
"""Use escape key to minimize widgets (potentially overriding bindings).

This is the default value, used if the active screen's `ESCAPE_TO_MINIMIZE` is not changed from `None`.
"""

Expand Down Expand Up @@ -544,7 +544,7 @@ def __init__(

self._registered_themes: dict[str, Theme] = {}
"""Themes that have been registered with the App using `App.register_theme`.

This excludes the built-in themes."""

for theme in BUILTIN_THEMES.values():
Expand Down Expand Up @@ -746,7 +746,7 @@ def __init__(

self.theme_changed_signal: Signal[Theme] = Signal(self, "theme-changed")
"""Signal that is published when the App's theme is changed.

Subscribers will receive the new theme object as an argument to the callback.
"""

Expand Down Expand Up @@ -2681,10 +2681,13 @@ def push_screen(
try:
loop = asyncio.get_running_loop()
except RuntimeError:
# Mainly for testing, when push_screen isn't called in an async context
future: asyncio.Future[ScreenResultType] = asyncio.Future()
else:
future = loop.create_future()
# Mainly for testing, when push_screen isn't called in an async context.
# Note:
# Creating a new event loop is necessary. Simply calling Future()
# without a loop parameter can fail when running tests using
# pytest-xdist.
loop = asyncio.new_event_loop()
future = loop.create_future()

if self._screen_stack:
self.screen.post_message(events.ScreenSuspend())
Expand Down
Loading