def close(self): """ Close the SDL2 interface. """ video.VideoPlugin.close(self) if sdl2 and numpy: # free windows sdl2.SDL_DestroyWindow(self.display) # free surfaces for s in self.canvas: sdl2.SDL_FreeSurface(s) sdl2.SDL_FreeSurface(self.work_surface) sdl2.SDL_FreeSurface(self.overlay) # free palettes for p in self.show_palette: sdl2.SDL_FreePalette(p) sdl2.SDL_FreePalette(self.composite_palette) # close SDL2 sdl2.SDL_Quit()
def __exit__(self, type, value, traceback): """Close the SDL2 interface.""" base.VideoPlugin.__exit__(self, type, value, traceback) if sdl2 and numpy and self._has_window: # free windows sdl2.SDL_DestroyWindow(self.display) # free surfaces for s in self.canvas: sdl2.SDL_FreeSurface(s) sdl2.SDL_FreeSurface(self.work_surface) sdl2.SDL_FreeSurface(self.overlay) # free palettes for p in self.show_palette: sdl2.SDL_FreePalette(p) sdl2.SDL_FreePalette(self.composite_palette) # close IME sdl2.SDL_StopTextInput() # close SDL2 sdl2.SDL_Quit()
def _set_icon(self): """Set the icon on the SDL window.""" mask = numpy.array(self.icon).T.repeat(2, 0).repeat(2, 1) icon = sdl2.SDL_CreateRGBSurface(0, mask.shape[0], mask.shape[1], 8, 0, 0, 0, 0) pixels2d(icon.contents)[:] = mask # icon palette (black & white) icon_palette = sdl2.SDL_AllocPalette(256) icon_colors = [ sdl2.SDL_Color(x, x, x, 255) for x in [0, 255] + [255]*254 ] sdl2.SDL_SetPaletteColors(icon_palette, (sdl2.SDL_Color * 256)(*icon_colors), 0, 2) sdl2.SDL_SetSurfacePalette(icon, icon_palette) sdl2.SDL_SetWindowIcon(self.display, icon) sdl2.SDL_FreeSurface(icon) sdl2.SDL_FreePalette(icon_palette)