File tree Expand file tree Collapse file tree 3 files changed +31
-7
lines changed
Expand file tree Collapse file tree 3 files changed +31
-7
lines changed Original file line number Diff line number Diff line change @@ -402,15 +402,20 @@ def rect(self) -> Rect:
402402 """Return a Rect describing the size of the window."""
403403 return LBWH (0 , 0 , self .width , self .height )
404404
405- def run (self ) -> None :
405+ def run (self , view : View | None = None ) -> None :
406406 """
407- Run the event loop.
407+ Run the event loop. Optionally start with a specified view.
408408
409409 After the window has been set up, and the event hooks are in place, this
410410 is usually one of the last commands on the main program. This is a blocking
411411 function starting pyglet's event loop meaning it will start to dispatch
412412 events such as ``on_draw`` and ``on_update``.
413+
414+ Args:
415+ view: The view to display when starting the run. Defaults to None.
413416 """
417+ if view is not None :
418+ self .show_view (view )
414419 arcade .run ()
415420
416421 def close (self ) -> None :
Original file line number Diff line number Diff line change 1616
1717if TYPE_CHECKING :
1818 from arcade import Window
19-
19+ from arcade . application import View
2020
2121_window : Window | None = None
2222
@@ -97,17 +97,23 @@ def close_window() -> None:
9797 gc .collect ()
9898
9999
100- def run () :
100+ def run (view : View | None = None ) -> None :
101101 """
102- Run the main loop.
102+ Run the main loop. Optionally start with a specified view.
103103
104104 After the window has been set up, and the event hooks are in place,
105105 this is usually one of the last commands on the main program.
106106 This is a blocking function starting pyglet's event loop meaning
107107 it will start to dispatch events such as ``on_draw`` and ``on_update``.
108+
109+ Args:
110+ view: The view to display when starting the run. Defaults to None.
108111 """
109112 window = get_window ()
110113
114+ if view is not None :
115+ window .show_view (view )
116+
111117 # Used in some unit test
112118 if os .environ .get ("ARCADE_TEST" ):
113119 window .on_update (1.0 / 60.0 )
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ def test_window(window: arcade.Window):
4141 assert v [3 ] == height
4242
4343 factor = window .get_pixel_ratio ()
44- assert isinstance (factor , float )
44+ assert isinstance (factor , float )
4545 assert factor > 0
4646
4747 def f ():
@@ -52,6 +52,19 @@ def f():
5252 arcade .unschedule (f )
5353 window .test ()
5454
55+ def test_window_with_view_arg (window : arcade .Window ):
56+ class TestView (arcade .View ):
57+ def __init__ (self ):
58+ super ().__init__ ()
59+ self .on_show_called = False
60+
61+ def on_show_view (self ):
62+ self .on_show_called = True
63+ v = TestView ()
64+ window .run (view = v )
65+
66+ assert v .on_show_called
67+ assert window .current_view is v
5568
5669def test_start_finish_render (window ):
5770 """Test start and finish render"""
@@ -68,7 +81,7 @@ def test_start_finish_render(window):
6881 # Only allowed to call start_render once
6982 with pytest .raises (RuntimeError ):
7083 arcade .start_render ()
71-
84+
7285 arcade .finish_render ()
7386
7487 # Make sure we rendered something to the screen
You can’t perform that action at this time.
0 commit comments