-
Notifications
You must be signed in to change notification settings - Fork 363
Pull Request to Add Optional view Argument in Window.run() #2450
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -402,15 +402,17 @@ def rect(self) -> Rect: | |
| """Return a Rect describing the size of the window.""" | ||
| return LBWH(0, 0, self.width, self.height) | ||
|
|
||
| def run(self) -> None: | ||
| from typing import Optional | ||
|
|
||
| def run(self, view: Optional[View] = None) -> None: | ||
| """ | ||
| Run the event loop. | ||
| Run the event 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``. | ||
|
Comment on lines
-409
to
-412
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not necessary to remove this part. |
||
| Args: | ||
| view (Optional[View]): The view to display when starting the run. Defaults to None. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit overkill to repeat the parameter typing here but not a big deal. |
||
| """ | ||
| if view is not None: | ||
| self.show_view(view) | ||
| arcade.run() | ||
|
|
||
| def close(self) -> None: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,7 +97,7 @@ def close_window() -> None: | |
| gc.collect() | ||
|
|
||
|
|
||
| def run(): | ||
| def run(view = None): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing annotation here. |
||
| """ | ||
| Run the main loop. | ||
|
|
||
|
|
@@ -108,6 +108,10 @@ def run(): | |
| """ | ||
| window = get_window() | ||
|
|
||
| # Show the specific view if provided | ||
| 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) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import pytest | ||
| import arcade | ||
|
|
||
|
|
||
| class TestView(arcade.View): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unit tests needs to use the global test window instead of making a new one or this will be extremely complicated. Write the tests like this. You will automatically get a test window fixture you can use. Creating new windows are not allowed in our unit tests. You should get a "clean" window for every function. def test_something(window):
window.run(..)As far as I know the |
||
| def __init__(self): | ||
| super().__init__() | ||
| self.on_show_called = False | ||
|
|
||
| def on_show_view(self): | ||
| self.on_show_called = True | ||
|
|
||
|
|
||
| def test_window_with_view(): | ||
| # Cria uma janela e uma view para o teste | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-English comment |
||
| window = arcade.Window(width=800, height=600, title="Window Test with View") | ||
| view = TestView() | ||
|
|
||
| # Executa o método run com a view | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-English comment |
||
| window.run(view=view) | ||
|
|
||
| # Verifica se a view foi mostrada automaticamente | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-English comment |
||
| assert window.current_view == view | ||
| assert view.on_show_called is True | ||
|
|
||
| # Fecha a janela ao finalizar o teste | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-English comment |
||
| window.close() | ||
|
|
||
|
|
||
| def test_run_without_view(): | ||
| # Cria uma janela e chama run sem uma view | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-English comment |
||
| window = arcade.Window(width=800, height=600, title="Window Test without View") | ||
|
|
||
| # Executa o método run sem uma view | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-English comment |
||
| window.run() | ||
|
|
||
| # Verifica que não há uma view ativa | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-English comment |
||
| assert window.current_view is None | ||
|
|
||
| # Fecha a janela ao finalizar o teste | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-English comment |
||
| window.close() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the modern
View | Nonenotation here instead ofOptionaland remove the stray import.