-
-
Notifications
You must be signed in to change notification settings - Fork 193
Open
Labels
New APIThis pull request may need extra debate as it adds a new class or function to pygameThis pull request may need extra debate as it adds a new class or function to pygameeventpygame.eventpygame.event
Description
This isn't fully developed, mostly putting this up so it doesn't get forgotten
Currently, event types don't have great autocomplete or type hinting correctness, because they are very generic. They are all instances of Event
.
What if a pygame.KEYDOWN event, for example, was an instance of a KeydownEvent
class, a subclass of Event
? The KeydownEvent
class could have its own docstring, type stub for properties, properties docstrings with descriptions, and it could all be type checked effectively.
In a game loop, one would do a bunch of isinstance() calls, rather than event.type checks. For example:
if isinstance(event, pygame.KeyDownEvent):
if event.key == pygame.K_1:
window.maximize()
This could be backwards compatible even, since each subclass could still export .type
correctly to the old style constants (pygame.KEYDOWN
)
- How would this work elegantly with custom event types made by users?
- Is this a pygame-ce 3 level thing?
yunline, gresm, JiffyRob and elliot-100
Metadata
Metadata
Assignees
Labels
New APIThis pull request may need extra debate as it adds a new class or function to pygameThis pull request may need extra debate as it adds a new class or function to pygameeventpygame.eventpygame.event