<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0053)http://www.pygame.org/pcr/submissions/ftp/UserRect.py -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY><PRE>"""UserRect, python class wrapped around the pygame Rect type. This allows
you to do things like inherit the rectangle object into a sprite class. While
this makes for some neat features, current testing has shown there is a bit of
a peformance penalty. (as opposed to just keeping a Rect value inside the class)

Note, this might be worthless now, as python-2.2 allows you to subclass real
python types, no need for this placeholder. Still, it may provide some assistance
to somebody out there.
"""

from pygame.rect import Rect


class UserRect:
    """UserRect() -&gt; class instance
Python class for the pygame Rect type

This python class can be treated exactly like a normal Rect
object. The only difference is it is a real python class
object, not a C extension type.
"""
    def __init__(self, *args):
        try: self.__dict__['rect'] = apply(Rect, args)
        except TypeError:
            raise TypeError, 'Argument must be rectstyle object'
        for a in dir(self.rect):
            self.__dict__[a] = getattr(self.rect, a)

    def __getattr__(self, name):
        return getattr(self.rect, name)
    def __setattr__(self, name, val):
        if name is 'rect':
            self.__dict__['rect'][:] = val
        else:
            try: setattr(self.__dict__['rect'], name, val)
            except (AttributeError, KeyError): self.__dict__[name] = val
    def __len__(self): return 4
    def __getitem__(self, i): return self.rect[i]
    def __setitem__(self, i, val): self.rect[i] = val
    def __getslice__(self, i, j): return self.rect[i:j]
    def __setslice__(self, i, j, val): self.rect[i:j] = val
    def __nonzero__(self): return nonzero(self.rect)
    def __cmp__(self, o): return cmp(self.rect, o)
    def __repr__(self):
        return '&lt;UserRect(%d, %d, %d, %d)&gt;' % tuple(self.rect)
    def __str__(self):
        return '&lt;UserRect(%d, %d, %d, %d)&gt;' % tuple(self.rect)

    
</PRE></BODY></HTML>
