Hey guys.

I was just wondering what the logic was behind the way the event
dispatcher currently works.

In the code below I have to name the string value of my test event
something different from the name of the variable.  This appears to be
because as you register_event_type the EventDispatcher adds a new
attribute to the class in question with the same name as the event
string name. It may seem irrelevant but I was wondering why the event
string value binds to the class inheriting EventDispatcher in this
way?  It seems like it could create some kind of chaos.

I've seen other implementations of EventDispatchers use a private
variable to contain the tables rather than just attaching them
directly to the object.  Granted it is only a problem if you use
EventDispatcher like I have done below, but this tends to be the
typical approach I take to events.

Right now the error you get is very ambiguous if you accidentally name
your event the same as an attribute the class already has.  Maybe that
could be modified or checked for or noted in the documentation? (If it
already is I apologise, I did not see it).

The error you get currently (lets assume the TEST_EVENT declaration in
my below code declares a value of ' TEST_EVENT') :

Traceback (most recent call last):
  File "C:\Documents and Settings\Jotham\Desktop
\battleship_viewer_pyglet\event_test.py", line 17, in <module>
    test.trigger_test()
  File "C:\Documents and Settings\Jotham\Desktop
\battleship_viewer_pyglet\event_test.py", line 8, in trigger_test
    self.dispatch_event(Test.TEST_EVENT)
  File "build/bdist.linux-x86_64/egg/pyglet/event.py", line 280, in
dispatch_event
  File "build/bdist.linux-x86_64/egg/pyglet/event.py", line 296, in
_raise_dispatch_exception
  File "C:\Python25\lib\inspect.py", line 743, in getargspec
    raise TypeError('arg is not a Python function')
TypeError: arg is not a Python function

This is my modified example code to show the approach:

#!/usr/bin/env python
from pyglet import event

class Test (event.EventDispatcher):
    TEST_EVENT = 'TEST_EVENT_'

    def trigger_test (self):
        self.dispatch_event(Test.TEST_EVENT)

Test.register_event_type(Test.TEST_EVENT)

if __name__ == "__main__":
   def on_test_event ():
      print 'on_test_event'
   test = Test()
   test.set_handler(Test.TEST_EVENT, on_test_event)
   test.trigger_test()



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to