Lenard, your patch was enjoyable to read. I guess I should be looking at the chapter "Extending and Embedding the Python Interpreter".
Thanks again, you guys are great. On Tue, Apr 14, 2009 at 12:59 AM, Lenard Lindstrom <[email protected]> wrote: > Added to trunk in revision 2017. > > > Lenard Lindstrom wrote: > >> >> I'm working on it. For two events to be equal not only the types, but all >> attribute values will also have to be equal. I am currently testing the >> patch. >> >> Lenard >> >> Jordan Applewhite wrote: >> >>> I'm afraid I don't have the skills to offer a patch. Oh well, there are >>> lots of other ways to accomplish what I need. Thanks for the quick answer! >>> On Mon, Apr 13, 2009 at 7:08 PM, René Dudfield <[email protected]<mailto: >>> [email protected]>> wrote: >>> >>> hi, >>> >>> Sorry, the Event class doesn't let you add attributes(like >>> Nicholas says). >>> >>> If you have a patch at the C level we can add an __eq__ since it >>> seems like a good idea (I think). Or maybe someone will implement >>> it for you. >>> >>> Or maybe we could allow events to have a dictionary associated >>> with them... so you can add methods and attributes like this... So >>> it acts more like a normal object. Will have to think about >>> the implications of this... >>> >>> >>> cheers, >>> >>> >>> >>> >>> >>> On Tue, Apr 14, 2009 at 9:17 AM, Jordan Applewhite >>> <[email protected] <mailto:[email protected]>> >>> wrote: >>> >>> Hi! >>> I thought it would be nice to add an __eq__ method to the >>> pygame.event.Event class at runtime. This would let me use == >>> (rich comparison operator) on events in the manner of >>> >>> if pygame.event.wait() == trigger_event: >>> pass >>> >>> I tried to do this with setattr like so (please pardon the >>> one-liner): >>> setattr( pygame.event.Event.__class__, '__eq__', lambda >>> self, other: self.type == other.type ) >>> >>> I've tried several variations on this idea, but the attribute >>> seems to be off-limits. I keep getting errors like >>> "TypeError: can't set attributes of built-in/extension type >>> 'builtin_function_or_method'". I notice that calling >>> pygame.event.Event.__class__ lists it as a "builtin function >>> or method.", but I'm not sure why this means I can't create >>> the method. >>> >>> Could someone please point me in the right direction? Thanks, >>> and I'm sorry if this is more about python than pygame. I'm >>> hoping it passes the relevance threshold:) >>> >>> >>> >>> >> >> > > -- > Lenard Lindstrom > <[email protected]> > >
