This wiki is in the process of being archived due to lack of usage and the resources necessary to serve it — predominately to bots, crawlers, and LLM companies. Edits are discouraged.
Pages are preserved as they were at the time of archival. For current information, please visit python.org.
If a change to this archive is absolutely needed, requests can be made via the infrastructure@python.org mailing list.

Delegation Event Model is ...


pro


cons

   1 # Code is Public Domain.
   2 # Basic objects:
   3 
   4 class Event(object):
   5     """ Object that contain information on the event message """
   6     def __init__(self):
   7         self._source = None
   8         
   9     def getSource(self):
  10         return self._source
  11 
  12     def setSource(self,value):
  13         self._source = value
  14 
  15     source = property(getSource,setSource)
  16 
  17     def getEventType(self):
  18         return self.__class__.__name__
  19 
  20     eventType = property(getEventType)
  21 
  22 class Listener(object):
  23     """ Object that wait for Event Message """
  24     def processEvent(self,event):
  25         funcName = "process%sEvent" % event.eventType
  26         if hasattr(self,funcName):
  27             getattr(self,funcName)(event)
  28 
  29 class Source(object):
  30     """ Object that produce Event Message """
  31     def __init__(self):
  32         self._listeners = {}
  33 
  34     def _initListenersList(self,eventType):
  35         if not eventType in self._listeners:
  36             self._listeners[eventType] = []
  37 
  38     def addEventListener(self,eventType,listener):
  39         self._initListenersList(eventType)
  40         self._listeners[eventType].append(listener)
  41 
  42     def publishEvent(self,event):
  43         self._initListenersList(event.eventType)
  44