Rename event.fire to event.handle
The terminology should be consistent
This commit is contained in:
parent
1be849415f
commit
158dcb5155
@ -3,7 +3,7 @@ Event system
|
|||||||
|
|
||||||
Generic library provides ``generic.event`` module which helps you implement
|
Generic library provides ``generic.event`` module which helps you implement
|
||||||
event systems in your application. By event system I mean an API for
|
event systems in your application. By event system I mean an API for
|
||||||
*subscribing* for some types of events and to *fire* those events so previously
|
*subscribing* for some types of events and to *handle* those events so previously
|
||||||
subscribed *handlers* are being executed.
|
subscribed *handlers* are being executed.
|
||||||
|
|
||||||
.. contents::
|
.. contents::
|
||||||
@ -29,12 +29,12 @@ Now you want to register handler for your event type::
|
|||||||
def print_comment(ev):
|
def print_comment(ev):
|
||||||
print "Got new comment: %s" % ev.comment
|
print "Got new comment: %s" % ev.comment
|
||||||
|
|
||||||
Then you just call ``generic.event.fire`` function with ``CommentAdded``
|
Then you just call ``generic.event.handle`` function with ``CommentAdded``
|
||||||
instance as its argument::
|
instance as its argument::
|
||||||
|
|
||||||
from generic.event import fire
|
from generic.event import handle
|
||||||
|
|
||||||
fire(CommentAdded(167, "Hello!")) # prints `Got new comment: Hello!`
|
handle(CommentAdded(167, "Hello!")) # prints `Got new comment: Hello!`
|
||||||
|
|
||||||
This is how it works.
|
This is how it works.
|
||||||
|
|
||||||
@ -48,12 +48,12 @@ API reference
|
|||||||
-------------
|
-------------
|
||||||
|
|
||||||
.. autoclass:: generic.event.Manager
|
.. autoclass:: generic.event.Manager
|
||||||
:members: subscribe, subscriber, fire, unsubscribe
|
:members: subscribe, subscriber, handle, unsubscribe
|
||||||
|
|
||||||
Functions below are just aliases for methods of globally instantiated
|
Functions below are just aliases for methods of globally instantiated
|
||||||
manager:
|
manager:
|
||||||
|
|
||||||
.. autofunction:: generic.event.subscribe(handler, event_type)
|
.. autofunction:: generic.event.subscribe(handler, event_type)
|
||||||
.. autofunction:: generic.event.subscriber(event_type)
|
.. autofunction:: generic.event.subscriber(event_type)
|
||||||
.. autofunction:: generic.event.fire(event)
|
.. autofunction:: generic.event.handle(event)
|
||||||
.. autofunction:: generic.event.unsubscribe(handler, event_type)
|
.. autofunction:: generic.event.unsubscribe(handler, event_type)
|
||||||
|
@ -2,9 +2,9 @@ UML datamodel
|
|||||||
=============
|
=============
|
||||||
|
|
||||||
Gaphor uses the UML metamodel specs as guidelines for its data storage.
|
Gaphor uses the UML metamodel specs as guidelines for its data storage.
|
||||||
In fact, the datamodel is generated for a model file.
|
In fact, the datamodel is generated for a model file.
|
||||||
|
|
||||||
The model is built using smart properties (descriptors). Those descriptors fire
|
The model is built using smart properties (descriptors). Those descriptors handle
|
||||||
events when they're changed. This allows the rest of the application (visuals,
|
events when they're changed. This allows the rest of the application (visuals,
|
||||||
undo system) to update their state accordingly. The events are send using Zope
|
undo system) to update their state accordingly. The events are send using Zope
|
||||||
(3)'s signalling mechanism, called Handlers.
|
(3)'s signalling mechanism, called Handlers.
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
This module provides API for event management. There are two APIs provided:
|
This module provides API for event management. There are two APIs provided:
|
||||||
|
|
||||||
* Global event management API: subscribe, unsubscribe, fire.
|
* Global event management API: subscribe, unsubscribe, handle.
|
||||||
* Local event management API: Manager
|
* Local event management API: Manager
|
||||||
|
|
||||||
If you run only one instance of your application per Python
|
If you run only one instance of your application per Python
|
||||||
@ -25,7 +25,7 @@ class Manager(object):
|
|||||||
|
|
||||||
Provides API for subscribing for and firing events. There's also global
|
Provides API for subscribing for and firing events. There's also global
|
||||||
event manager instantiated at module level with functions
|
event manager instantiated at module level with functions
|
||||||
:func:`.subscribe`, :func:`.fire` and decorator :func:`.subscriber` aliased
|
:func:`.subscribe`, :func:`.handle` and decorator :func:`.subscriber` aliased
|
||||||
to corresponding methods of class.
|
to corresponding methods of class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ class Manager(object):
|
|||||||
if handler_set and handler in handler_set:
|
if handler_set and handler in handler_set:
|
||||||
handler_set.remove(handler)
|
handler_set.remove(handler)
|
||||||
|
|
||||||
def fire(self, event):
|
def handle(self, event):
|
||||||
""" Fire ``event``
|
""" Fire ``event``
|
||||||
|
|
||||||
All subscribers will be executed with no determined order.
|
All subscribers will be executed with no determined order.
|
||||||
@ -76,7 +76,7 @@ class Manager(object):
|
|||||||
... # handle event
|
... # handle event
|
||||||
... return
|
... return
|
||||||
|
|
||||||
>>> mymanager.fire(MyEvent())
|
>>> mymanager.handle(MyEvent())
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class ManagerTests(unittest.TestCase):
|
|||||||
events = self.createManager()
|
events = self.createManager()
|
||||||
events.subscribe(self.makeHandler("handler1"), EventA)
|
events.subscribe(self.makeHandler("handler1"), EventA)
|
||||||
e = EventA()
|
e = EventA()
|
||||||
events.fire(e)
|
events.handle(e)
|
||||||
self.assertEqual(len(e.effects), 1)
|
self.assertEqual(len(e.effects), 1)
|
||||||
self.assertTrue("handler1" in e.effects)
|
self.assertTrue("handler1" in e.effects)
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ class ManagerTests(unittest.TestCase):
|
|||||||
events = self.createManager()
|
events = self.createManager()
|
||||||
events.subscriber(EventA)(self.makeHandler("handler1"))
|
events.subscriber(EventA)(self.makeHandler("handler1"))
|
||||||
e = EventA()
|
e = EventA()
|
||||||
events.fire(e)
|
events.handle(e)
|
||||||
self.assertEqual(len(e.effects), 1)
|
self.assertEqual(len(e.effects), 1)
|
||||||
self.assertTrue("handler1" in e.effects)
|
self.assertTrue("handler1" in e.effects)
|
||||||
|
|
||||||
@ -37,12 +37,12 @@ class ManagerTests(unittest.TestCase):
|
|||||||
events.subscribe(self.makeHandler("handler2"), EventB)
|
events.subscribe(self.makeHandler("handler2"), EventB)
|
||||||
|
|
||||||
ea = EventA()
|
ea = EventA()
|
||||||
events.fire(ea)
|
events.handle(ea)
|
||||||
self.assertEqual(len(ea.effects), 1)
|
self.assertEqual(len(ea.effects), 1)
|
||||||
self.assertTrue("handler1" in ea.effects)
|
self.assertTrue("handler1" in ea.effects)
|
||||||
|
|
||||||
eb = EventB()
|
eb = EventB()
|
||||||
events.fire(eb)
|
events.handle(eb)
|
||||||
self.assertEqual(len(eb.effects), 2)
|
self.assertEqual(len(eb.effects), 2)
|
||||||
self.assertTrue("handler1" in eb.effects)
|
self.assertTrue("handler1" in eb.effects)
|
||||||
self.assertTrue("handler2" in eb.effects)
|
self.assertTrue("handler2" in eb.effects)
|
||||||
@ -54,17 +54,17 @@ class ManagerTests(unittest.TestCase):
|
|||||||
events.subscribe(self.makeHandler("handler3"), EventD)
|
events.subscribe(self.makeHandler("handler3"), EventD)
|
||||||
|
|
||||||
ea = EventA()
|
ea = EventA()
|
||||||
events.fire(ea)
|
events.handle(ea)
|
||||||
self.assertEqual(len(ea.effects), 1)
|
self.assertEqual(len(ea.effects), 1)
|
||||||
self.assertTrue("handler1" in ea.effects)
|
self.assertTrue("handler1" in ea.effects)
|
||||||
|
|
||||||
ec = EventC()
|
ec = EventC()
|
||||||
events.fire(ec)
|
events.handle(ec)
|
||||||
self.assertEqual(len(ec.effects), 1)
|
self.assertEqual(len(ec.effects), 1)
|
||||||
self.assertTrue("handler2" in ec.effects)
|
self.assertTrue("handler2" in ec.effects)
|
||||||
|
|
||||||
ed = EventD()
|
ed = EventD()
|
||||||
events.fire(ed)
|
events.handle(ed)
|
||||||
self.assertEqual(len(ed.effects), 3)
|
self.assertEqual(len(ed.effects), 3)
|
||||||
self.assertTrue("handler1" in ed.effects)
|
self.assertTrue("handler1" in ed.effects)
|
||||||
self.assertTrue("handler2" in ed.effects)
|
self.assertTrue("handler2" in ed.effects)
|
||||||
@ -74,7 +74,7 @@ class ManagerTests(unittest.TestCase):
|
|||||||
events = self.createManager()
|
events = self.createManager()
|
||||||
|
|
||||||
ea = EventA()
|
ea = EventA()
|
||||||
events.fire(ea)
|
events.handle(ea)
|
||||||
self.assertEqual(len(ea.effects), 0)
|
self.assertEqual(len(ea.effects), 0)
|
||||||
|
|
||||||
def test_subscribe_base_event(self):
|
def test_subscribe_base_event(self):
|
||||||
@ -82,7 +82,7 @@ class ManagerTests(unittest.TestCase):
|
|||||||
events.subscribe(self.makeHandler("handler1"), EventA)
|
events.subscribe(self.makeHandler("handler1"), EventA)
|
||||||
|
|
||||||
ea = EventB()
|
ea = EventB()
|
||||||
events.fire(ea)
|
events.handle(ea)
|
||||||
self.assertEqual(len(ea.effects), 1)
|
self.assertEqual(len(ea.effects), 1)
|
||||||
self.assertTrue("handler1" in ea.effects)
|
self.assertTrue("handler1" in ea.effects)
|
||||||
|
|
||||||
@ -93,18 +93,18 @@ class ManagerTests(unittest.TestCase):
|
|||||||
events.subscribe(self.makeHandler("handler3"), EventE)
|
events.subscribe(self.makeHandler("handler3"), EventE)
|
||||||
|
|
||||||
ea = EventA()
|
ea = EventA()
|
||||||
events.fire(ea)
|
events.handle(ea)
|
||||||
self.assertEqual(len(ea.effects), 1)
|
self.assertEqual(len(ea.effects), 1)
|
||||||
self.assertTrue("handler1" in ea.effects)
|
self.assertTrue("handler1" in ea.effects)
|
||||||
|
|
||||||
ed = EventD()
|
ed = EventD()
|
||||||
events.fire(ed)
|
events.handle(ed)
|
||||||
self.assertEqual(len(ed.effects), 2)
|
self.assertEqual(len(ed.effects), 2)
|
||||||
self.assertTrue("handler1" in ed.effects)
|
self.assertTrue("handler1" in ed.effects)
|
||||||
self.assertTrue("handler2" in ed.effects)
|
self.assertTrue("handler2" in ed.effects)
|
||||||
|
|
||||||
ee = EventE()
|
ee = EventE()
|
||||||
events.fire(ee)
|
events.handle(ee)
|
||||||
self.assertEqual(len(ee.effects), 3)
|
self.assertEqual(len(ee.effects), 3)
|
||||||
self.assertTrue("handler1" in ee.effects)
|
self.assertTrue("handler1" in ee.effects)
|
||||||
self.assertTrue("handler2" in ee.effects)
|
self.assertTrue("handler2" in ee.effects)
|
||||||
@ -116,7 +116,7 @@ class ManagerTests(unittest.TestCase):
|
|||||||
events.subscribe(self.makeHandler("handler2"), EventB)
|
events.subscribe(self.makeHandler("handler2"), EventB)
|
||||||
|
|
||||||
eb = EventB()
|
eb = EventB()
|
||||||
events.fire(eb)
|
events.handle(eb)
|
||||||
self.assertEqual(len(eb.effects), 2)
|
self.assertEqual(len(eb.effects), 2)
|
||||||
self.assertTrue("handler1" in eb.effects)
|
self.assertTrue("handler1" in eb.effects)
|
||||||
self.assertTrue("handler2" in eb.effects)
|
self.assertTrue("handler2" in eb.effects)
|
||||||
@ -127,7 +127,7 @@ class ManagerTests(unittest.TestCase):
|
|||||||
events.subscribe(handler, EventA)
|
events.subscribe(handler, EventA)
|
||||||
events.unsubscribe(handler, EventA)
|
events.unsubscribe(handler, EventA)
|
||||||
e = EventA()
|
e = EventA()
|
||||||
events.fire(e)
|
events.handle(e)
|
||||||
self.assertEqual(len(e.effects), 0)
|
self.assertEqual(len(e.effects), 0)
|
||||||
|
|
||||||
def test_unsubscribe_event_inheritance(self):
|
def test_unsubscribe_event_inheritance(self):
|
||||||
@ -139,11 +139,11 @@ class ManagerTests(unittest.TestCase):
|
|||||||
events.unsubscribe(handler1, EventA)
|
events.unsubscribe(handler1, EventA)
|
||||||
|
|
||||||
ea = EventA()
|
ea = EventA()
|
||||||
events.fire(ea)
|
events.handle(ea)
|
||||||
self.assertEqual(len(ea.effects), 0)
|
self.assertEqual(len(ea.effects), 0)
|
||||||
|
|
||||||
eb = EventB()
|
eb = EventB()
|
||||||
events.fire(eb)
|
events.handle(eb)
|
||||||
self.assertEqual(len(eb.effects), 1)
|
self.assertEqual(len(eb.effects), 1)
|
||||||
self.assertTrue("handler2" in eb.effects)
|
self.assertTrue("handler2" in eb.effects)
|
||||||
|
|
||||||
|
@ -86,4 +86,4 @@ class ComponentRegistry(Service):
|
|||||||
Send event notifications to registered handlers.
|
Send event notifications to registered handlers.
|
||||||
"""
|
"""
|
||||||
for e in events:
|
for e in events:
|
||||||
self._events.fire(e)
|
self._events.handle(e)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user