Beispiel #1
0
def peek(types=None):
    """ peek(type) -> bool
    test if event types are waiting on the queue
    """
    mask = 0
    if not types:
        mask = sdl.SDL_ALLEVENTS
    elif isinstance(types, int):
        mask |= event_mask(types) 
    elif hasattr(types, '__iter__'):
        try:
            for t in types:
                mask |= event_mask(int(t))
        except (ValueError, TypeError):
            raise TypeError("type sequence must contain valid event types")
    else:
        raise TypeError("peek type must be numeric or a sequence")

    sdl.SDL_PumpEvents()
    event = ffi.new('SDL_Event*')
    result = sdl.SDL_PeepEvents(event, 1, sdl.SDL_PEEKEVENT, mask)

    if not types:
        return EventType(event[0])
    return result == 1
Beispiel #2
0
def clear(event_filter=None):
    if event_filter is None:
        # unfiltered list of events
        mask = sdl.SDL_ALLEVENTS
    else:
        raise NotImplementedError("Implement me")
    sdl.SDL_PumpEvents()
    event = ffi.new("SDL_Event *")
    while sdl.SDL_PeepEvents(event, 1, sdl.SDL_GETEVENT, mask) == 1:
        pass
Beispiel #3
0
def get(event_filter=None):
    if event_filter is None:
        # unfiltered list of events
        mask = sdl.SDL_ALLEVENTS
    else:
        raise RuntimeError("Implement me")
    sdl.SDL_PumpEvents()
    event_list = []
    event = ffi.new("SDL_Event *")
    while sdl.SDL_PeepEvents(event, 1, sdl.SDL_GETEVENT, mask) == 1:
        event_list.append(EventType(event))
    return event_list