[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pygame] subclassing rect



I'm a pygame newbie and python user evaluating possible replacements for
Macromedia Director for programming educational multimedia. I'm going to
rewrite parts of our commercial multimedia title in python/pygame to see
how it fits our needs.

While learning the basics I ran into a subclassing issue: I couldn't
subclass the Rect class. See the python session below.
A related page at http://pygame.org/pcr/submissions/01062002a.html
states: "Before Python 2.2, data types implemented in C (such as
pygame's Rect class) couldn't be subclassed. Pete included the UserRect
module - it's just the thinnest possible python wrapper around Rect.
However, it would be cleaner and faster just to upgrade to python 2.2,
and subclass the actual Rect class."
Am I missing something?

BTW, has anyone set up a keyword searchable archive for this mailing
list?

Regards,

Antti Kaihola
Ambitone Oy
Helsinki, Finland

------------------

$ python
Python 2.2.1 (#1, Jun  2 2002, 23:28:47) 
[GCC 3.1.1 (Mandrake Linux 8.3 3.1.1-0.1mdk)] on linux-i386
>>> import pygame
>>> pygame.ver
'1.4.9'
>>> class A(dict): # subclassing dict works ok
...     def __init__(self):
...             dict.__init__({})
...             self.x = 1
... 
>>> a=A()
>>> a
{}
>>> type(a)
<class '__main__.A'>
>>> a.x
1
>>> class B(pygame.rect.Rect): # problems with subclassing Rect
...     def __init__(self):
...             pygame.rect.Rect.__init__(0,0,10,10)
...             self.x = 1
... 
>>> b=B()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: Argument must be rect style object
>>> b=B(0,0,1,1)
>>> b
<rect(0, 0, 1, 1)>
>>> type(b)
<type 'Rect'>
>>> b.x
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: x


____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org