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:
+class Path(object):
- “”" Allow programatic specification of DLL path+
-
Usage:
-
-
from sdl2.init import Path
-
Path().PYSDL2_DLL_PATH = "blah"
-
import sdl2
- “”"
-
- @property
- 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
-
- @PYSDL2_DLL_PATH.setter
- 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:
import os
import ctypes
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 *
def run():
""" Renders a string to a fixed surface and draws the entire surface “”"
if SDL_Init(SDL_INIT_VIDEO) != 0:
print(SDL_GetError())
return -1
if TTF_Init() == -1:
print(TTF_GetError())
return -1
window = SDL_CreateWindow(b"Text", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, 800, 600,
SDL_WINDOW_SHOWN)
if not window:
print(SDL_GetError())
return -1
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)
SDL_FreeSurface(text_surf)
r2 = SDL_Rect(10, 10, 100, 20)
event = SDL_Event()
running = True
while running:
while SDL_PollEvent(ctypes.byref(event)) != 0:
if event.type == SDL_QUIT:
running = False
SDL_RenderClear(renderer)
SDL_RenderCopyEx(renderer, text_value, None, r2, 0, SDL_Point(25,
25), SDL_FLIP_NONE)
SDL_RenderPresent(renderer)
SDL_DestroyRenderer(renderer)
SDL_DestroyTexture(text_value)
SDL_DestroyWindow(window)
SDL_Quit()
TTF_Quit()
return 0
if name == “main”:
run()
Not an ideal solution, but something like this would be really handy.
Great work though, all in all. I’m really enjoying using this~
~
Doug.
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
rendering
- a new sdl2.ext.SpriteFactory.from_text() method, which creates text
sprites
- 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
http://pysdl2.readthedocs.org/.
Note:
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.
Cheers
Marcus
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
-------------- next part --------------
A non-text attachment was scrubbed…
Name: changes.diff
Type: application/octet-stream
Size: 9773 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20130819/f2dde708/attachment-0001.obj