Skip to content

Commit 36be772

Browse files
(api-break) remove DEFAULT_PRIORITY
1 parent efb4347 commit 36be772

File tree

10 files changed

+22
-27
lines changed

10 files changed

+22
-27
lines changed

examples/01_event_handling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async def main(*, sdlevent: apg.SDLEvent, **kwargs):
88
pygame.display.set_mode((400, 400))
99

1010
while True:
11-
e = await sdlevent.wait(pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP)
11+
e = await sdlevent.wait(pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP, priority=0x100)
1212
print(e)
1313

1414

examples/loop_animation (skippable).py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async def main(**kwargs: Unpack[apg.CommonParams]):
2222
r(pygame.display.flip, priority=0xFFFFFF00)
2323
del r
2424

25-
mouse_button_down = partial(kwargs["sdlevent"].wait, pygame.MOUSEBUTTONDOWN)
25+
mouse_button_down = partial(kwargs["sdlevent"].wait, pygame.MOUSEBUTTONDOWN, priority=0x100)
2626
move_sprite = partial(kwargs["clock"].anim_attrs, img_rect, duration=1000)
2727
wait_any = apg.wait_any
2828

examples/scene_transition_showcase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def show_transition(*, scene_switcher, userdata, executor, sdlevent, draw_
3636
text, transition = next(userdata['transitions'])
3737
img = font.render(text, True, "white").convert_alpha()
3838
with executor.register(partial(draw_target.blit, img, img.get_rect(center=draw_target.get_rect().center)), priority=0x100):
39-
await sdlevent.wait(pygame.MOUSEBUTTONDOWN)
39+
await sdlevent.wait(pygame.MOUSEBUTTONDOWN, priority=0)
4040
scene_switcher.switch_to(show_transition, transition)
4141
await apg.sleep_forever()
4242

src/asyncpygame/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
__all__ = (
2-
'DEFAULT_PRIORITY', 'run', 'quit', 'Clock', 'SDLEvent', 'PriorityExecutor',
2+
'run', 'quit', 'Clock', 'SDLEvent', 'PriorityExecutor',
33
'CommonParams', 'capture_current_frame', 'block_input_events',
44
)
55

66
from asyncgui import *
77
from asyncgui_ext.clock import Clock
88
from ._runner import run, quit
9-
from .constants import DEFAULT_PRIORITY
109
from ._sdlevent import SDLEvent
1110
from ._priority_executor import PriorityExecutor
1211
from ._utils import CommonParams, capture_current_frame, block_input_events

src/asyncpygame/_priority_executor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from heapq import merge as heapq_merge
2-
from .constants import DEFAULT_PRIORITY
32

43

54
class ExecutionRequest:
@@ -95,7 +94,7 @@ def __call__(self, *args):
9594
self._reqs = reqs2
9695
self._reqs_2 = reqs
9796

98-
def register(self, func, priority=DEFAULT_PRIORITY) -> ExecutionRequest:
97+
def register(self, func, priority) -> ExecutionRequest:
9998
req = ExecutionRequest(priority, func)
10099
self._reqs_to_be_added.append(req)
101100
return req

src/asyncpygame/_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def run(main_func, *, fps=30, auto_quit=True):
2020
main_task = ap.start(main_func(clock=clock, sdlevent=sdlevent, executor=executor, pygame_clock=pygame_clock))
2121

2222
if auto_quit:
23-
sdlevent.subscribe((pygame.QUIT, ), quit)
24-
sdlevent.subscribe((pygame.KEYDOWN, ), lambda e, K=pygame.K_ESCAPE: e.key == K and quit())
23+
sdlevent.subscribe((pygame.QUIT, ), quit, priority=0)
24+
sdlevent.subscribe((pygame.KEYDOWN, ), lambda e, K=pygame.K_ESCAPE: e.key == K and quit(), priority=0)
2525

2626
# LOAD_FAST
2727
pygame_event_get = pygame.event.get

src/asyncpygame/_sdlevent.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from pygame.event import Event
99
from asyncgui import _current_task, _sleep_forever, current_task
1010

11-
from .constants import DEFAULT_PRIORITY
12-
1311

1412
def _callback(filter, consume, task_step, event: Event):
1513
if filter(event):
@@ -141,7 +139,7 @@ def dispatch(self, event: Event):
141139
self._subs = subs2
142140
self._subs_2 = subs
143141

144-
def subscribe(self, topics, callback, priority=DEFAULT_PRIORITY) -> Subscriber:
142+
def subscribe(self, topics, callback, priority) -> Subscriber:
145143
'''
146144
async型APIの礎となっているコールバック型API。直接触るべきではない。
147145
'''
@@ -150,7 +148,7 @@ def subscribe(self, topics, callback, priority=DEFAULT_PRIORITY) -> Subscriber:
150148
return sub
151149

152150
@types.coroutine
153-
def wait(self, *event_types, filter=_accept_any, priority=DEFAULT_PRIORITY, consume=False) -> Awaitable[Event]:
151+
def wait(self, *event_types, filter=_accept_any, priority, consume=False) -> Awaitable[Event]:
154152
'''
155153
Waits for any of the specified types of events to occur.
156154
'''
@@ -162,7 +160,7 @@ def wait(self, *event_types, filter=_accept_any, priority=DEFAULT_PRIORITY, cons
162160
sub.cancel()
163161

164162
@asynccontextmanager
165-
async def wait_freq(self, *event_types, filter=_accept_any, priority=DEFAULT_PRIORITY, consume=False):
163+
async def wait_freq(self, *event_types, filter=_accept_any, priority, consume=False):
166164
'''
167165
``MOUSEMOTION`` や ``FINGERMOTION`` などの頻りに起こりうるイベントを効率良く捌けるかもしれない機能。
168166
以下のようなコードは

src/asyncpygame/constants.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
__all__ = (
2-
'DEFAULT_PRIORITY', 'INPUT_EVENTS',
2+
'INPUT_EVENTS',
33
)
44

55
import pygame.constants as C
66

77

8-
DEFAULT_PRIORITY = 0
98
INPUT_EVENTS = {
109
C.KEYDOWN, C.KEYUP,
1110
C.MOUSEMOTION, C.MOUSEBUTTONDOWN, C.MOUSEBUTTONUP, C.MOUSEWHEEL,

tests/test_priority_executor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def executor():
99

1010
def test_basis(executor):
1111
values = []
12-
req = executor.register(lambda: values.append('A'))
12+
req = executor.register(lambda: values.append('A'), priority=0)
1313
assert values == []
1414
executor()
1515
assert values == ['A', ]
@@ -22,8 +22,8 @@ def test_basis(executor):
2222

2323
def test_same_priority(executor):
2424
values = []
25-
req = executor.register(lambda: values.append('A'))
26-
executor.register(lambda: values.append('B'))
25+
req = executor.register(lambda: values.append('A'), priority=0)
26+
executor.register(lambda: values.append('B'), priority=0)
2727
assert values == []
2828
executor()
2929
assert sorted(values) == ['A', 'B', ]

tests/test_sdlevent.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def se():
1010

1111
def test_subscribe(se):
1212
received = []
13-
sub = se.subscribe((1, 2), received.append)
13+
sub = se.subscribe((1, 2), received.append, priority=0)
1414
se.dispatch(E(1))
1515
assert len(received) == 1
1616
se.dispatch(E(0))
@@ -30,10 +30,10 @@ def test_two_subscribers_with_the_same_priority(se):
3030
def store_value(e):
3131
value_list.append(e.value)
3232

33-
sub = se.subscribe((1, ), store_value)
33+
sub = se.subscribe((1, ), store_value, priority=0)
3434
se.dispatch(E(1, value='A'))
3535
assert value_list == ['A', ]
36-
se.subscribe((1, ), store_value)
36+
se.subscribe((1, ), store_value, priority=0)
3737
se.dispatch(E(1, value='B'))
3838
assert value_list == ['A', 'B', 'B',]
3939
sub.cancel()
@@ -77,7 +77,7 @@ def test_stop_dispatching(se):
7777
def test_wait(se):
7878
from asyncgui import start
7979

80-
task = start(se.wait(1, 2))
80+
task = start(se.wait(1, 2, priority=0))
8181
se.dispatch(E(0))
8282
assert not task.finished
8383
se.dispatch(E(1))
@@ -87,7 +87,7 @@ def test_wait(se):
8787
def test_wait_with_filter(se):
8888
from asyncgui import start
8989

90-
task = start(se.wait(1, 2, filter=lambda e: e.value == 'A'))
90+
task = start(se.wait(1, 2, filter=lambda e: e.value == 'A', priority=0))
9191
se.dispatch(E(0, value='B'))
9292
assert not task.finished
9393
se.dispatch(E(0, value='A'))
@@ -115,7 +115,7 @@ def test_wait_freq(se):
115115
from asyncgui import start
116116

117117
async def async_fn():
118-
async with se.wait_freq(1, 2) as event:
118+
async with se.wait_freq(1, 2, priority=0) as event:
119119
return await event()
120120

121121
task = start(async_fn())
@@ -129,7 +129,7 @@ def test_wait_freq_with_filter(se):
129129
from asyncgui import start
130130

131131
async def async_fn():
132-
async with se.wait_freq(1, 2, filter=lambda e: e.value == 'A') as event:
132+
async with se.wait_freq(1, 2, filter=lambda e: e.value == 'A', priority=0) as event:
133133
return await event()
134134

135135
task = start(async_fn())
@@ -168,7 +168,7 @@ def test_wait_freq_mixed_with_another_type_of_awaitable(se):
168168
from asyncgui import start, Event
169169

170170
async def async_fn():
171-
async with se.wait_freq(1, 2) as event:
171+
async with se.wait_freq(1, 2, priority=0) as event:
172172
await event()
173173
await ae.wait()
174174
await event()

0 commit comments

Comments
 (0)