Hello,

how about this below for the custom event type API? Then we hide the
USEREVENT in the docs, and suggest people use this. Then libraries can
exist without stomping over each others events. Also, I think custom_type
is a bit of a better name. Because it's an event type(not an event), and
it's custom.

What do you reckon?

PIRATE_APPROACH = pygame.event.custom_type()
>
> e = pygame.event.Event(PIRATE_APPROACH, num=5)
> pygame.event.post(e)
>
> for e in events:
>     if e.type == PIRATE_APPROACH:
>         print('pirates are coming!')
>


It would be implemented something like this (thanks Sam!)

_CUSTOM_EVENT = iter(range(pygame.constants.USEREVENT,
> pygame.constants.NUMEVENTS))
>
> def custom_type():
>     """ Return an event type we can use for our own events.
>     """
>     return next(_CUSTOM_EVENT)
>

Issue is here:
https://github.com/pygame/pygame/issues/477

Reply via email to