[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] UI event handling [was: Re: Re: New GUI]



On, Wed Jan 23, 2008, Kamilche wrote:

> Marcus wanted an example of how events could be handled better.
> I've worked up an example of how the mainline code could look, if the
> event handling were done using a more VB-like structure.
> 
> import kamgui
> 
> # This example creates a screen with 2 buttons and 3 labels.
> 
> # -------------------------------------------------------------
> # App level features handled with this code:
> # -------------------------------------------------------------
> # Clicking the buttons updates the status label.
> # Moving the mouse updates the mousepos label.
> # The fps label is updated when the global 'FPS' event is fired.

Looking at the code below it suffers from several flaws:
a class specific event list that at some point (unknown to the
developer) will be used to generate method bindings using a fixed
scheme. The developer cannot influence that as well. 

If I have a fixed styleguide of naming private methods
_frugulator_blabla() - or in general different from your scheme, your
GUI interfers by not allowing me to switch the names of the event
callbacks.

Binding multiple methods to one event seems to be something I have to
implement in the On_*, *_Click event hooks myself, or do I miss
something?

> # --------------------------------------------------------------
> # Engine level 'automatic' features:
> # --------------------------------------------------------------
> # The buttons automatically hilight when you hover the
> # mouse over them, and unhilight when you leave.
> 
> # Clicking the button sets the focus to the button,
> # and draws it with a border around it and darker text.

Something all toolkits implement in the one or other way. Necessary for
a good usability and some fancy effects :-).
 
> # Events that are targeted to a specific control, propagate
> # up the ownership hierarchy until the event is handled.
> # If no control is listening, the event is silently ignored.
> 
> # Events that are sent to no specific control,
> # are broadcast to all 'listening' controls.

Sounds like the usual event queue and listener stuff. Regarding your UI,
can I use own events by simply adding them to events = ... list?

class MyApp(kamgui.App):
    events = ['MousePos', 'Doowahickey', 'FPS']

and at which time and how will 'Doowahickey' be thrown?

Regards
Marcus

Attachment: pgplVyTyXSxie.pgp
Description: PGP signature