pyassetmlSDL (version 0.3)
index
/home/stas/Projects/pyassetml/pyassetml-0.22/pyassetmlSDL.py

    Copyright (C) 2003 Stas Z <stas@linux.isbeter.nl>
 
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program. If not, write to the Free Software Foundation,
675 Mass Ave, Cambridge, MA 02139, USA.

 
Modules
       
os
pyassetml
pygame
sys

 
Classes
       
AssetmlSDL
exceptions.Exception
PyassetmlsdlError

 
class AssetmlSDL
    ## XXXX BIG TODO, what about the hardcoded paths, that sucks.
 
  Methods defined here:
__init__(self, assetmlpath='/usr/share/assetml')
class to fetch data from assetml files and provides methods
to turn these files into sdl objects
get_assets(self, filenames, class_instance=None)
This will return a dictionary with the found files as SDL objects.
example: {'file1':<pygame.image object>,'file2':<pygame.image object>}
When a class instance is given the dictionary is mapped onto this class instance.
Instead of a class instance you can parse any object that has a __dict__ method.
When filenames is a sequence of one then only the SDL object is returnt.
A special case is when filenames == ('*.foo',), then all the files whith '.foo'
in there name are returnt as a dictionary. The '*' in this case doesn't function
as a traditional wildcard, but to signal that, while it's a sequence of one we don't
want just one object, but all the matching objects.
It's a somewhat hackerish solution.
set_mldir(self, dirname)
This sets the assetml fil path to be used.
        XXX
        if not dirname in self.assetfiles:
            print >> sys.stderr, "pyassetmlSDL report a error:
Can't find", dirname
            raise PyassetmlsdlError
        # XXX maybe we could do a search here, so we can first search the dir we need
        # and then set it to mldir. Better wait until the dataset thing is ready
set_transparent_image(self, trans=1)
Set image to be transparent or not, 1 or 0.
This value will be used until it's been reset.

 
class PyassetmlsdlError(exceptions.Exception)
     Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
Functions
       
image = load_image(file)
loads an image and convert it
load_image(file)
loads an image and convert it
load_music(file)
Set up music object, if the music can't be loaded a bogus object will be returnt.
Beware that due to SDL limitations you can only have one music source loaded.
This means that even when you have multiple pygame instances, there can only be one
music source. This function returns a filename wrapped in a sound like object with
a play and stop method.
For multiple sources use the pygame.Sound and wave combination.
load_sound(name)
Loads a sound -> pygame sound object.
If no file can be loaded return a dummy class
music = load_music(file)
Set up music object, if the music can't be loaded a bogus object will be returnt.
Beware that due to SDL limitations you can only have one music source loaded.
This means that even when you have multiple pygame instances, there can only be one
music source. This function returns a filename wrapped in a sound like object with
a play and stop method.
For multiple sources use the pygame.Sound and wave combination.
sound = load_sound(name)
Loads a sound -> pygame sound object.
If no file can be loaded return a dummy class

 
Data
        DEBUG = 0
EXT_switch = {'au': <function load_sound>, 'bmp': <function load_image>, 'gif': <function load_image>, 'jpg': <function load_image>, 'mp3': <function load_music>, 'ogg': <function load_music>, 'png': <function load_image>, 'wav': <function load_sound>}
RLEACCEL = 16384
TRANSPARENT_IMAGE = 1
__version__ = '0.3'