pythonarcade / arcade

Easy to use Python library for creating 2D arcade games.
http://arcade.academy
Other
1.68k stars 319 forks source link

Look into multiple dispatch helpers for cleaning up GUI event code #2313

Open pushfoo opened 1 month ago

pushfoo commented 1 month ago

Enhancement request:

TL;DR: Consider one of the other dispatch tools to clean up GUI event code

What should be added/changed?

Consider one of the following to clean up our event code:

  1. functools.singledispatchmethod
  2. The 3rd party multipledispatch
  3. Beartype's plum

Why wait til 3.0+?

There might be unexpected problems which would delay 3.0.

The status of the following are unclear:

  1. Union types and arguments
  2. It looks like there are issues with inheritance as of a month ago

What would it help with?

Reduce verbosity in cases like this: https://github.com/pythonarcade/arcade/blob/05b476f5bbe3e02a2a7352d67e5daa980e7f489b/arcade/gui/widgets/text.py#L432-L477

cspotcode commented 1 month ago

Bear in mind, every if statement is going to become an annotated method declaration, so total lines of code may increase.

On Thu, Jul 25, 2024, 2:26 PM Paul @.***> wrote:

Enhancement request:

TL;DR: Consider one of the other dispatch tools to clean up GUI event code What should be added/changed?

Consider one of the following to clean up our event code:

  1. functools.singledispatchmethod https://docs.python.org/3/library/functools.html#functools.singledispatchmethod
  2. The 3rd party multipledispatch https://github.com/mrocklin/multipledispatch/
  3. Beartype's plum https://github.com/beartype/plum

Why wait til 3.0+?

There might be unexpected problems which would delay 3.0.

The status of the following are unclear:

  1. Union types and arguments
  2. It looks like there are issues with inheritance as of a month ago https://stackoverflow.com/questions/68190543/how-to-use-singledispatchmethod-with-inheritance-class

What would it help with?

Reduce verbosity in cases like this:

https://github.com/pythonarcade/arcade/blob/05b476f5bbe3e02a2a7352d67e5daa980e7f489b/arcade/gui/widgets/text.py#L432-L477

— Reply to this email directly, view it on GitHub https://github.com/pythonarcade/arcade/issues/2313, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAC35ODWCKMQFWB2WILJBP3ZOE7LRAVCNFSM6AAAAABLPCTRJOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQZTANZSG42DONQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

eruvanos commented 1 month ago

Hi,

from my point of view, we do not have to enforce a decision for such topic without experimenting and testing it in praxis.

You can just create a UIWidget, which passes the events to the singledispatch function. This could even be an opt-in Mix-in.

Side note:

I personally try to stick to the current arcade "statement":

Arcade is an easy-to-learn Python library for creating 2D video games. It is ideal for beginning programmers, or programmers who want to create 2D games without learning a complex framework.

My conclusion is, it should be easy to understand for beginner, or have to be optional. ( I am aware, that the GUI comes with its own complexity, but it is the easiest solution I found so far 🙈)