moderngl-window icon indicating copy to clipboard operation
moderngl-window copied to clipboard

allow to manage pygame2 USEREVENT

Open cubr3 opened this issue 2 years ago • 2 comments

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:

cubr3 avatar Jul 19 '22 20:07 cubr3

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.

einarf avatar Jul 19 '22 21:07 einarf

+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.

cubr3 avatar Jul 20 '22 09:07 cubr3

Should be in 2.4.2

einarf avatar Sep 17 '22 17:09 einarf