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

Re: [pygame] Gui



I do event driven programming, but a little differently(a very pygame way).

Rather than using callbacks everywhere, I pass through lists of events
into instances.

I find it conceptually easier to follow, than callbacks.  Seems less abstract.

for event in event_list:
    if event.type == KEY_DOWN:
        if event.key == L_l:
            print "do something"
        elif event.key == L_k:
            print "do something else"

I can make very complex systems by using classes that have a
handle_events() method.

class Bla:
    def __init__(self):
        self.other_obj = SomeOtherEventWanter()

    def handle_events(self, event_list):
        for event in event_list:
            if event.type == KEY_DOWN:
                print "A KEY IS DOWN, TIME TO SLEEP NOW"

        self.other_obj.handle_event(event_list)



blabla = Bla()

blabla.handle_events(event_list)

for event in event_list:
    if event.type == KEY_DOWN:
        if event.key == L_l:
            print "do something"
        elif event.key == L_k:
            print "do something else"


On 6/28/05, Simon Wittber <simonwittber@xxxxxxxxx> wrote:
> The problem with most GUI toolkits, from a game programmer point of view...
> 
> ... is the need to integrate their GUI main loop.
> 
> Most of us like to do things our own way, and being shackled into a
> GUI framework is usually (at least for me) an unpleasant experience.
> I've ended up writing my own event engine, which I can plug into most
> GUI toolkits and frameworks. I've been able to integrate pygame,
> twisted, and wx in a fairly generic way.
> 
> I do wonder though, what/if people have tried as alternatives to event
> driven GUI programming... anyone care to share?
> 
> Sw.
>