[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Python property conventions in my new Sprite class



Hi,

On, Mon Jul 30, 2012, Sagie Maoz wrote:

[...]
> >
> > Avoid useless property encapsulations as in Java/C++/C#/..., as you did
> > for the "visible" one in your code. You do not do any internal magic, but
> > just assign it, why would you want a property for that?
> >
>
> Generally I agree, but this was done so that the 'visible' setter could be
> wrapped with the _visual_set wrapper (that fires a 'visual attribute
> changed' event).
> Come to think about that, this was also part of the reason I switched to
> using the property() notation.
> Do you have a suggestion on how to implement such events in a clearer
> manner?

Depends - I did not look (again) at your code, but I would not implement
events via decorators. They might break, if not overriden properly.

I am usually using a small event handler callback class, to which
callables can be attached easily:

http://wiki.pgreloaded.googlecode.com/hg/documentation/modules/events.html
http://code.google.com/p/pgreloaded/source/browse/pygame2/events.py

Cheers
Marcus

Attachment: pgpJVvrPKRmj1.pgp
Description: PGP signature