[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] event processing?



>  > The docs mention that event.poll() returns a NOEVENT event if nothing
>  > is on the queue, and this has a type that evaluates to 0. How do I
>  > determine the type of an event? 
> 
> Ah, I've got it now. I call:
> 
> event.poll().type
> 
> That's clear enough from the example programs. I guess I was confused,
> since dir(event) returned [].

glad you were able to figure this out. the docs should be
changed slightly, stating that it returns an event with a type
of NOEVENT when none is waiting.

the event objects have no methods, only members. unfortunately,
the dir() command only lists methods for c extension objects
(unless there's a method i'm not aware of, it seems like there
should be?)

the event objects are basically simple read-only wrappers
around a dictionary object. you access the keys of the
dictionary by using members of the event object. the events
always have two extra members which are not part of the
dictionary "type" which is the event type code, and "dict" which
is the actual dictionary object.

until the documentation has more information like that, people
are going to need to crutch on the examples for awhile. that's
why i did spend some time to get a few decent examples.

the other type of object with no methods, only members in
pygame is the "VidInfo" object. gotten by calling 
pygame.display.get_info(). all other objects and modules in
pygame use methods exclusively, and do not rely on members.

the reason these two objects (event and vidinfo) are different
like this is because the objects themselves don't do anything,
they just contain information. it is easier to access that info
by simply getting the member, instead of using a get_xxx() func.


actually the "Rect" objects are the exception to this rule, 
but they are used very differently than the other objects.

anyways, back to the event stuff. the NOEVENT type is defined
by SDL, and just used here in pygame to represent this case.
NOEVENT is the only event type to evaluate to 0, so should be
easy to determine if an event was waiting by checking if it
is nonzero..

event = pygame.input.poll()
if event.type:
    print 'Got Event', event
else:
    print 'No Event'



____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org