This is really great by the way!
One comment; the way it uses PYSDL2_DLL_PATH is ok, but I find it quite
annoying to use (especially on windows, where the os.env() doesn’t work in
some shells and stuff. :(. If you move the sdl api into sdl.py, you get a
more consistent api (from sdl2.sdl import *, from sdl2.sdlmixer import *,
from sdl2.sdlimage import *) and you can have an init module that lets you
manually specify the dll path.
I was just messing around and come up with:
- “”" Allow programatic specification of DLL path+
from sdl2.init import Path
Path().PYSDL2_DLL_PATH = "blah"
- def PYSDL2_DLL_PATH(self):
- if not hasattr(type(self), ‘_dll_path’):
type(self)._dll_path = os.getenv("PYSDL2_DLL_PATH")
- return type(self)._dll_path
- def PYSDL2_DLL_PATH(self, value):
- type(self)._dll_path = value
(full diff attached).
Means you can use the api like this, which I really like:
Set path to shared library here
from sdl2.init import Path
Path().PYSDL2_DLL_PATH = os.path.join(os.getcwd(), ‘py’)
from sdl2.sdl import *
from sdl2.sdlttf import *
""" Renders a string to a fixed surface and draws the entire surface “”"
if SDL_Init(SDL_INIT_VIDEO) != 0:
if TTF_Init() == -1:
window = SDL_CreateWindow(b"Text", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 800, 600,
if not window:
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED)
font = TTF_OpenFont(“assets/droid.ttf”, 10)
if not font:
print(‘Failed: %s’ % TTF_GetError())
color = SDL_Color(r=255, g=0)
text_surf = TTF_RenderText_Blended(font, “Hello World”, color)
text_value = SDL_CreateTextureFromSurface(renderer, text_surf)
r2 = SDL_Rect(10, 10, 100, 20)
event = SDL_Event()
running = True
while SDL_PollEvent(ctypes.byref(event)) != 0:
if event.type == SDL_QUIT:
running = False
SDL_RenderCopyEx(renderer, text_value, None, r2, 0, SDL_Point(25,
if name == “main”:
Not an ideal solution, but something like this would be really handy.
Great work though, all in all. I’m really enjoying using this~
On Wed, Aug 14, 2013 at 2:59 PM, Marcus von Appen wrote:
PySDL2 0.5.0 has been released.
PySDL2 is a wrapper around the SDL2 library and as such similar to the
discontinued PySDL project. In contrast to PySDL, it has no licensing
restrictions, nor does it rely on C code, but uses ctypes instead.
Version 0.5.0 is a feature release, which comes with
- a new sdl2.ext.FontManager class, which provides simple TTF font
- a new sdl2.ext.SpriteFactory.from_text() method, which creates text
- a fix for Win32 platforms; sometimes third party DLLs are not properly
loaded, if the DLL path is not placed at the beginning of PATH
- minor documentation fixes
You can download it from http://bitbucket.org/marcusva/py-sdl2/downloads.
The documentation, listing all of its features, can be browsed online at
The SDL2 third party DLL package for Windows is not offered anymore with
SDL2 being officially released now. Please use the official Windows
builds of the DLLs instead.
SDL mailing list
SDL at lists.libsdl.org
-------------- next part --------------
A non-text attachment was scrubbed…
Size: 9773 bytes
Desc: not available