Childsplay Utils

Stas Z

E-mail: childsplay@users.sourceforge.net

Release 0.66
May 10, 2003


Childsplay reference - Utils.py

Copyright © 2003 Stas Z. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be found here
utils.py -> Classes and functions in the utils module.
Don't do import from * Everything in this module raises a internal exception on error (MyError).
MyError -> Returns a exception object.
Attributes : name, line Error class derived from the standard python exception class, the eventloop in childsplay catch MyError exceptions,prints the name and line Attributes and some other usefull stuff and finally makes a clean exit.
trace_error([file=sys.stderr]) -> Prints a stacktrace and ask to send a bugreport.
Mostly used in combination with MyError file can be used to send the output to a file like object.
load_image(file, [transparent=0]) -> Returns a pygame surface containing the file image file.
file -> Must be the full path to the image. transparent -> 0 = not transparent, >=1 = transparent.
load_sound(file) -> Returns a pygame sound object.
file -> Must be the full path to the sound file. If the file file can't be loaded a dummy object is returned with two methods, play and stop to mimic the pygame object. If the dummy class is used a error message is send to stderr.
load_music(file) -> Returns a pygame music object.
file -> Must be the full path to the music file. If the file file can't be loaded a dummy object is returned with two methods, play and stop to mimic the pygame object. If the dummy class is used a error message is send to stderr. Only one music file can be loaded this is a pygame/sdl limitation.
get_files(path,match) -> Returns a python list with the files from path which match the match.
path -> Must be a string containing a path. match -> A string containing the pattern to match. This pattern must be a python fnmatch string. See also python library ref : fnmatch.
txt2surf(seq,x,y,[fsize=18,[title=None,[box=None,[fcol=(0,0,0),[ttf=None]]]]]) ->   Returns a pygame surface object with the strings renderd onto it.
The surface has the background of the current screen to give the suggestion of transparancy. seq -> Must be a python list of strings. x,y -> Size of the surface. fsize -> Integer representing the font size. title -> String to use as the title. Size is fsize*1.3 box -> Draw a box around the surface. fcol -> Tuple with the RGB color code. Defaults to black. ttf -> Path to the ttf font file. Defaults to the standard pygame font. The strings are rendert onto the surface, everything that don't fit in the surface is discarded.
font2surf(word,size,[fcol=None,[ttf=None,[sizel=None]]]) ->    Returns the tuple (surface with a string of caracters renderd onto it, list with font sizes).
word -> Python string with caracters. size -> Integer representing the font size. fcol -> Tuple with the RGB color code. Defaults to black. ttf -> Path to the ttf font file. Defaults to the standard pygame font. sizel -> Sizelist FALSE = return a list with sizes of each caracter, TRUE = return a tuple with the size of the renderd string.
Dimmer -> Class for darkening the entire screen.
Constructer takes a optional argument; keepalive=0 If keepalive=1 the screen is stored in Dimmer.buffer to act as a memory for screen contents. Methods: dim([darken_factor=64,[color_filter=(0,0,0)]]) Saves the current screen for later restorage and lays a filter over it. darken_factor -> Alpha level color_filter -> Tuple with the RGB color code. A darken_factor of 0 just stores the current screen. undim() Retores the screen by blitting the saved state over the current screen.
MazeGen -> Class to produce a perfect maze, based on the Mazeworks algorithme.
Constructer takes two arguments; rows,cols used for maze size. These arguments must be uneven (or constructer substract one). Methods: get_maze() Returns a tuple with tuples representing the maze; 0 = wall, 1 = room. Usage: m = MazeGen(17,17) maze = m.get_maze()
import_module(filename,[globals=None,[locals=None,[fromlist=None]]]) ->    Imports any module without changes to sys.path.
The optional arguments are redunded and are removed from childsplay version > 0.66.
entry_edit(entry="",[maxlen=10,[but_ok_rect=(0,0,0,0),[but_cancel_rect=(0,0,0,0)]]]) ->   Basic entry field editing function. Returns a updated entry string.
Starts his own event loop, and only breaks when some user event occurs. entry - string with the entry text ("" in the beginning) but_ok_rect - pygame rect from the (optional) ok-button. but_cancel_rect - same as but_ok for the cancel button.
ReturnObject Class object to be used as the return object in the plugins eventloop.
The xml_dic is used to send xml data to the controller. The xml dic and all the future attributes in this class gets only checkt by the controller when the stop attribute is true or int(3). In this case the controller only checks the xml_dic.   Attributes: score = integer representing a score value to be added to the excisting score. stop = flag to signal the controller, 0=continue, 2=user exit (hit the stopsign),        -1=clear screen, 1=exit (game finished), 3=only check the xml_dic. xml_dic = dic used to parse data for the monitor. (see the docs or contact the mailinglist        for the preffered format).
Blink A general class object to provide a 'blinking' image.
Blink(img,img_h,pos,*args) img = image 1 img_h = image 2 (the highlight version) pos = position to blit, tuple(x,y) *args = optional data gets returned in the update method when the      mouse position is in the rect. The DATA attribute gets set by the instance which is selected by the mouse position.
txtfmt(text, split) -> list of wrapped strings Formats a list of strings in a list of strings of 'split' length.
returns a new list of strings. This depends on utils.__string_split(). text = list of strings split = integer
Valid HTML 4.01 Transitional
Firefox 2