module resource

The resource module exports some utility functions for finding, loading and cacheing various types of resources. By default, resource files are looked for in a directory named resources alongside the .py file of the progam's main module, but that can be changed by assigning to the resource_dir module variable.

Specific resource types are looked for in subdirectories of the resources directory as follows:

Images
resources/images
Fonts
resources/fonts
Sounds
resources/sounds

Each type of resource has a cache. The first time a resource with a given name is requested, it is loaded and placed in the cache; subsequent requests for the same name will return the cached object.

Default Fonts

Various widgets default to using members of the Bitstream Vera font family (specifically the Vera and Vera Bold typefaces). These are not distributed with this package; if you want to use the defaults, you will have to obtain these fonts yourself and put them in the fonts directory indicated above.

Variables

resource_dir
Pathname of the directory in which to look for resource files. Initialized to a directory called resources in the same directory as the resource.py file.


default_font
The default font used by text-displaying widgets. Initialized to Font(default_font_name, 12).
default_font_name
Filename of the default font to use if no font is named when calling get_font(). Initialized to Vera.ttf.

optimize
If true, images loaded with get_image() will have convert_alpha() called on them. Defaults to true.

Functions

resource_path(*names)
Constructs a resource pathname from the module variable resource_dir and the given pathname components.

get_image(filename, border = 0)
Loads the specified image from the images directory or returns it from the cache. If border is specified, a border of that number of pixels is stripped from around the image (making it 2 * border pixels smaller in each direction).

If the module variable optimize is true, the image is converted with convert_alpha() after loading. For this to work correctly, you must have initialized the PyGame screen before calling get_image().

get_font(size, filename = default_font_name)
Loads the specified font or returns it from the cache.

get_sound(filename)
Loads the specified sound or returns it from the cache.
---