Package pygsear :: Module Util |
[show private | hide private]
[frames | no frames]

## Module pygsear.Util

Utilities for finding and loading different resources

Exceptions
`TextRectException` |

Function Summary
| `beep()`
| `color(name, modifier)`
| `color_darken(color)`
| `color_lighten(color)`
| `does_surface_have_pixel_alpha(surface)`
| ``get_dirs`(type)` return a list of potential data directories.
| ``get_full_path`(filename, dirs)` return the first existing file found in dirs.
| ``have_same_signs`(a, b)` return True if both integers have the same signs.
| ``line_seg_intersect`(line1point1, line1point2, line2point1, line2point2)` return True if 2 line segments intersect.
| ``load_image`(filename, convert)` Return pygame surface from filename string.
| ``load_images`(filenames, dirname, convert)` Return list of pygame surfaces.
| ``load_images_dict`(filenames, dirname, convert)` Return dict of `filename: image` pygame surfaces.
| ``load_points`(filename)` Return list of points `(x, y)`.
| ``load_sound`(filename)` Return pygame sound object.
| ``render_textrect`(string, rect, text_color, bgcolor, fontSize, justification, trim)` Returns a surface containing the passed text.
| ``scale_image`(img, width, height, keepAspectRatio)` return a scaled copy of a `pygame.Surface`

Variable Summary
`int` | `COLINEAR` = -1
`dict` | `dirs_cache` = `{}`
`int` | `DONT_INTERSECT` = 0
`dict` | `image_cache` = `{}`
`dict` | `point_cache` = `{}`
`dict` | `sound_cache` = `{}`

Function Details

### get_dirs(type=None) return a list of potential data directories. Looks around at possible locations, and returns possible data directories in this order: The current working directory. The "home" directory, where the main (invoked) script lives. NOTE: Not the user's home directory! The `data/type` directory underneath the "home" directory The `data` directory underneath the "home" directory The `libdata/type` directory underneath the pygsear lib directory. The `libdata` directory underneath the pygsear lib directory.

### get_full_path(filename, dirs) return the first existing file found in dirs. Parameters: `filename` - Name of file to find in dirs. `dirs` - List of directories to search.

### have_same_signs(a, b) return True if both integers have the same signs. Parameters: `a` - One number. (type=int) `b` - Another number. (type=int)

### line_seg_intersect(line1point1, line1point2, line2point1, line2point2) return True if 2 line segments intersect. Parameters: `line1point1` - (x, y) coord of one end of first line `line1point2` - (x, y) coord of other end of first line `line2point1` - (x, y) coord of one end of second line `line2point2` - (x, y) coord of other end of second line

### load_image(filename, convert=1) Return pygame surface from filename string. Uses `get_dirs` to know where to look for the file. Parameters: `filename` - Name of image file to load data from. `convert` - Optimize if True. Can sometimes cause colorspace problems... Will not convert if the image has an alpha mask.

### load_images(filenames=None, dirname=None, convert=1) Return list of pygame surfaces. Must pass either list of filenames, or name of directory from which to load all images. Uses `get_dirs` to know where to look for the file or directory. Parameters: `filenames` - List of image file names to load data from. `dirname` - Name of directory from which to load all images. `convert` - Optimize if True. Can sometimes cause colorspace problems...

### load_images_dict(filenames=None, dirname=None, convert=1) Return dict of `filename: image` pygame surfaces. Must pass either a list of filenames or the name of a directory from which to load all images. Uses `get_dirs` to know where to look for the file or directory. Parameters: `filenames` - List of image file names to load data from. `dirname` - Name of directory from which to load all images. `convert` - Optimize if True. Can sometimes cause colorspace problems...

### load_points(filename) Return list of points `(x, y)`. Parameters: `filename` - Name of file to load data from. Data should be formatted as `(x, y)` with one point per line.

### load_sound(filename) Return pygame sound object. Sound file shoud be a `.wav` file. Checks the status of the sound system first, and if there is a problem, hands out `pygsear.Sound.DummySound` objects instead of actual `pygame.mixer.Sound` objects. Parameters: `filename` - Name of file to load data from.

### render_textrect(string, rect, text_color=(255, 255, 255), bgcolor=(0, 0, 0), fontSize=20, justification=0, trim=0) Returns a surface containing the passed text. The text string will be reformatted to fit within the given rect, word-wrapping as necessary. The text will be anti-aliased. Raises a `TextRectException` if the text won't fit onto the surface. Parameters: `string` - The text you wish to render. Newline character begins a new line. `rect` - A rectstyle giving the size of the surface requested. `text_color` - RGB color tuple (ex (0, 0, 0) = BLACK) `bgcolor` - A three-byte tuple of the rgb value of the surface. `fontSize` - A Font object `justification` - Alignment of the text in the rectangle 0 (default) left-justified 1 horizontally centered 2 right-justified `trim` - If True, return a Surface just large enough to contain the text. Returns: A surface object with the text rendered onto it.

### scale_image(img, width, height, keepAspectRatio=1) return a scaled copy of a `pygame.Surface` Parameters: `img` - Original `pygame.Surface`. `width` - width of returned surface. `height` - height of returned surface. `keepAspectRatio` - If True, the returned surface will be padded with transparent borders.

Variable Details

    ### COLINEAR Type: `int` Value:
        -1

    ### dirs_cache Type: `dict` Value:
        {}

    ### DONT_INTERSECT Type: `int` Value:
        0

    ### image_cache Type: `dict` Value:
        {}

    ### point_cache Type: `dict` Value:
        {}

    ### sound_cache Type: `dict` Value:
        {}

Generated by Epydoc 2.0 on Sat Dec 9 14:11:20 2006 | http://epydoc.sf.net