Skip to content

Commit

Permalink
Hotfix threaded loading examples and sections issue #2499 (#2503)
Browse files Browse the repository at this point in the history
* Fix threaded_loading example fighting for definition of `time` during testing

* (#2499) Allow for Falsey values for preventing dispatch in Sections

* linting pass

* modify sections to accept bools for `prevent_dispatch` and `prevent_dispatch_view`
  • Loading branch information
DragonMoffon authored Jan 23, 2025
1 parent 9aa8e1a commit 434ed57
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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,
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

0 comments on commit 434ed57

Please sign in to comment.