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
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
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
def set_mode(resolution=(0, 0), flags=0, depth=0): """ set_mode(resolution=(0,0), flags=0, depth=0) -> Surface Initialize a window or screen for display """ w, h = unpack_rect(resolution) if w < 0 or h < 0: raise SDLError("Cannot set negative sized display mode") if flags == 0: flags = sdl.SDL_SWSURFACE if not get_init(): init() # depth and double buffering attributes need to be set specially for OpenGL if flags & sdl.SDL_OPENGL: if flags & sdl.SDL_DOUBLEBUF: gl_set_attribute(sdl.SDL_GL_DOUBLEBUFFER, 1) else: gl_set_attribute(sdl.SDL_GL_DOUBLEBUFFER, 0) if depth: gl_set_attribute(sdl.SDL_GL_DEPTH_SIZE, depth) c_surface = sdl.SDL_SetVideoMode(w, h, depth, flags) if c_surface and gl_get_attribute(sdl.SDL_GL_DOUBLEBUFFER): c_surface.flags |= sdl.SDL_DOUBLEBUF else: if depth == 0: flags |= sdl.SDL_ANYFORMAT c_surface = sdl.SDL_SetVideoMode(w, h, depth, flags) if not c_surface: raise SDLError.from_sdl_error() title = ffi.new("char*[1]") icon = ffi.new("char*[1]") sdl.SDL_WM_GetCaption(title, icon) if not title: sdl.SDL_WM_SetCaption("pygame window", "pygame") # pygame does this, so it's possibly a good idea sdl.SDL_PumpEvents() global _display_surface _display_surface = SurfaceNoFree._from_sdl_surface(c_surface) # TODO: set icon stuff return _display_surface
def pump(): sdl.SDL_PumpEvents()