Add View Argument to Window.run() by emmett-bicker · Pull Request #2468 · pythonarcade/arcade · GitHub
Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions arcade/application.py
12 changes: 9 additions & 3 deletions arcade/window_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

if TYPE_CHECKING:
from arcade import Window

from arcade.application import View
Comment thread
einarf marked this conversation as resolved.

_window: Window | None = None

Expand Down Expand Up @@ -97,17 +97,23 @@ def close_window() -> None:
gc.collect()


def run():
def run(view: View | None = None) -> None:
"""
Run the main loop.
Run the main loop. Optionally start with a specified view.

After the window has been set up, and the event hooks are in place,
this is usually one of the last commands on the main program.
This is a blocking function starting pyglet's event loop meaning
it will start to dispatch events such as ``on_draw`` and ``on_update``.

Args:
view: The view to display when starting the run. Defaults to None.
"""
window = get_window()

if view is not None:
window.show_view(view)

# Used in some unit test
if os.environ.get("ARCADE_TEST"):
window.on_update(1.0 / 60.0)
Expand Down
17 changes: 15 additions & 2 deletions tests/unit/window/test_window.py