moderngl-window
moderngl-window copied to clipboard
allow to manage pygame2 USEREVENT
Hi,
Would you consider to add a quick fix like the following at the end of moderngl_window.context.pygame2.window.Window.process_events()
as you grab all events including pygame2 USEREVENT that could be excluded from the unified system (non standard events) ?
Proposal 1: simple
def process_events(self) -> None:
"""Handle all queued events in pygame2 dispatching events to standard methods"""
for event in pg.event.get():
if event.type == pg.MOUSEMOTION:
self._handle_mods()
...
elif event.type == pg.USEREVENT:
self.process_user_event(event)
or perhaps better
Proposal 2: more open solution
def process_events(self) -> None:
"""Handle all queued events in pygame2 dispatching events to standard methods"""
for event in pg.event.get():
if event.type == pg.MOUSEMOTION:
self._handle_mods()
...
else:
self.process_custom_event(event)
# or self.process_non_standard_event(event) ?
# or self.process_non_unified_event(event) ?
today, we have to copy/paste whole process_events
method in a new class that inherits from moderngl_window.context.pygame2.window.Window
. Not fan of copy/paste design.
references:
You can actually subclass a window and configure that window class in the settings module.
Maybe method 1 is better since it will be custom for pygame. The callback could be called on_generic_event
for example? That way we could funnel all non-processed events for all window types into this one.
+1 for on_generic_event
. The main point was to not grab all event in base class.
note: i've left settings module as i'm doing more complicated stuff so i switched to inheritance and manual setup.
Should be in 2.4.2