trying to use sdl_pango with python

inhahe inhahe at gmail.com
Sun Aug 22 14:23:19 CEST 2010


i'm new to ctypes. can someone help me use sdl_pango with python?

here's the documentation: http://sdlpango.sourceforge.net/

here's my code:

-----------------------------------------------------
import pygame
from ctypes import *
import win32api

MATRIX_TRANSPARENT_BACK_WHITE_LETTER = c_char_p("\xFF\xFF\0\0\xFF\xFF
\0\0\xFF\xFF\0\0\0\xFF\0\0")

margin_x = margin_y = 10

def sdlwrite(rtext, width, height=None):
  context = sdlpango.SDLPango_CreateContext()
  sdlpango.SDLPango_SetDefaultColor(context,
MATRIX_TRANSPARENT_BACK_WHITE_LETTER)
  sdlpango.SDLPango_SetMinimumSize(context, width, height)
  sdlpango.SDLPango_SetMarkup(context, rtext, -1)
  w = sdlpango.SDLPango_GetLayoutWidth(context)
  h = sdlpango.SDLPango_GetLayoutHeight(context)
  surface = sdl.SDL_CreateRGBSurface(sdlpango.SDL_SWSURFACE, w +
margin_x, h + margin_y, 32, 255 << (8*3), 255 << (8*2), 255 << (8*1),
255)
  sp = POINTER(surface)
  sdlpango.SDLPango_Draw(context, ps, margin_x, margin_y)
  sdl.SDL_FreeSurface(ps)
  return context

def surfwrite(rtext, width, height=None):
  sdlcontext = sdlwrite(rtext, width, height)
  print 'sdlcontext:', sdlcontext

#scr = pygame.set_mode()
#rloss, gloss, bloss, aloss = scr.

sdlpango = windll.LoadLibrary(r"C:\projects\soundshop\pango-1.18.3\bin
\sdl_pango.dll")
sdl =  windll.LoadLibrary(r"sdl.dll")

#sdlpango.SDLPango_SetDefaultColor.argtypes = [c_void_p, c_char_p]
#sdlpango.SDLPango_SetMinimumSize.argtypes = [c_void_p, c_int, c_int]
#sdlpango.SDLPango_SetMarkup.argtypes = [c_void_p, c_char_p, c_int]
#sdlpango.SDLPango_GetLayoutWidth.argtypes = [c_void_p]
#sdlpango.SDLPango_GetLayoutHeight.argtypes = [c_void_p]
#sdl.SDL_CreateRGBSurface.argtypes = [c_uint, c_int, c_int, c_int,
c_uint, c_uint, c_uint, c_uint]
#sdlpango.SDLPango_Draw.argtypes = [c_void_p, c_uint, c_int, c_int]
#sdl.SDL_FreeSurface.argtypes = [c_void_p]

sdlpango.SDLPango_SetDefaultColor.argtypes = [c_uint, c_uint]
sdlpango.SDLPango_SetMinimumSize.argtypes = [c_uint, c_int, c_int]
sdlpango.SDLPango_SetMarkup.argtypes = [c_uint, c_char_p, c_int]
sdlpango.SDLPango_GetLayoutWidth.argtypes = [c_uint]
sdlpango.SDLPango_GetLayoutHeight.argtypes = [c_uint]
sdl.SDL_CreateRGBSurface.argtypes = [c_uint, c_int, c_int, c_int,
c_uint, c_uint, c_uint, c_uint]
sdlpango.SDLPango_Draw.argtypes = [c_uint, c_uint, c_int, c_int]
sdl.SDL_FreeSurface.argtypes = [c_uint]

surfwrite("hello", 640)
-----------------------------------------------------

here's the .h file that i got MATRIX_TRANSPARENT_BACK_WHITE_LETTER
from.  http://sdlpango.sourceforge.net/_s_d_l___pango_8h-source.html

-----------------------------------------------------
here's my error:

Traceback (most recent call last):
  File "C:\projects\soundshop\sdlpango.py", line 54, in <module>
    surfwrite("hello", 640)
  File "C:\projects\soundshop\sdlpango.py", line 25, in surfwrite
    sdlcontext = sdlwrite(rtext, width, height)
  File "C:\projects\soundshop\sdlpango.py", line 13, in sdlwrite
    sdlpango.SDLPango_SetDefaultColor(context,
MATRIX_TRANSPARENT_BACK_WHITE_LETTER)
ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: wrong
type

-----------------------------------------------------

i've tried other things, like using c_char_p instead for
MATRIX_TRANSPARENT_BACK_WHITE_LETTER, but the only other result i can
manage to get is this:

C:\projects\soundshop>sdlpango.py
Traceback (most recent call last):
  File "C:\projects\soundshop\sdlpango.py", line 52, in <module>
    surfwrite("hello", 640)
  File "C:\projects\soundshop\sdlpango.py", line 25, in surfwrite
    sdlcontext = sdlwrite(rtext, width, height)
  File "C:\projects\soundshop\sdlpango.py", line 13, in sdlwrite
    sdlpango.SDLPango_SetDefaultColor(context,
MATRIX_TRANSPARENT_BACK_WHITE_LETTER)
ValueError: Procedure probably called with too many arguments (8 bytes
in excess)


-----------------------------------------------------
thx for any help.




More information about the Python-list mailing list