Skip to content

A few quick fixes #2503

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

Merged
merged 4 commits into from
Jan 23, 2025
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
4 changes: 2 additions & 2 deletions arcade/examples/threaded_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from __future__ import annotations

import sys
import time
from time import sleep

# Python's threading module has proven tools for working with threads, and
# veteran developers may want to explore 3.13's new 'No-GIL' concurrency.
Expand Down Expand Up @@ -104,7 +104,7 @@ def _load_levels(self):
with self._interaction_lock:
self._current_level = level

time.sleep(ARTIFICIAL_DELAY) # "Slow" down (delete this line before use)
sleep(ARTIFICIAL_DELAY) # "Slow" down (delete this line before use)

# Since unhandled exceptions "kill" threads, we catch the only major
# exception we expect. Level 4 is intentionally missing to test cases
Expand Down
16 changes: 12 additions & 4 deletions arcade/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def __init__(
name: str | None = None,
accept_keyboard_keys: bool | Iterable = True,
accept_mouse_events: bool | Iterable = True,
prevent_dispatch: Iterable | None = None,
prevent_dispatch_view: Iterable | None = None,
prevent_dispatch: Iterable | bool | None = None,
Copy link

@AnonymousCoward128746 AnonymousCoward128746 Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defval can be set to {True} now, and then L99 just becomes
self.prevent_dispatch = prevent_dispatch

same for _view. This would break existing code which explicitly passes in None (can't imagine such).

Also maybe bool | Iterable vs. Iterable | bool should be consistent for readability.

Thanks!

prevent_dispatch_view: Iterable | bool | None = None,
local_mouse_coordinates: bool = False,
enabled: bool = True,
modal: bool = False,
Expand Down Expand Up @@ -96,10 +96,18 @@ def __init__(
self.accept_mouse_events: bool | Iterable = accept_mouse_events
"""Arcade mouse events to accept."""

self.prevent_dispatch: Iterable = prevent_dispatch or {True}
if isinstance(prevent_dispatch, bool):
prevent_dispatch = {prevent_dispatch}
self.prevent_dispatch: Iterable = {True} if prevent_dispatch is None else prevent_dispatch
assert isinstance(self.prevent_dispatch, Iterable)
"""prevents events to propagate"""

self.prevent_dispatch_view: Iterable = prevent_dispatch_view or {True}
if isinstance(prevent_dispatch_view, bool):
prevent_dispatch_view = {prevent_dispatch_view}
self.prevent_dispatch_view: Iterable = (
{True} if prevent_dispatch_view is None else prevent_dispatch_view
)
assert isinstance(self.prevent_dispatch_view, Iterable)
"""prevents events to propagate to the view"""

self.local_mouse_coordinates: bool = local_mouse_coordinates
Expand Down
Loading