From: <umg...@us...> - 2007-04-01 17:41:28
|
Revision: 382 http://svn.sourceforge.net/pybridge/?rev=382&view=rev Author: umgangee Date: 2007-04-01 10:41:14 -0700 (Sun, 01 Apr 2007) Log Message: ----------- SimpleEventHandler implementation of IListener: redirects update() calls to methods of its target object. Modified Paths: -------------- trunk/pybridge/pybridge/ui/eventhandler.py Modified: trunk/pybridge/pybridge/ui/eventhandler.py =================================================================== --- trunk/pybridge/pybridge/ui/eventhandler.py 2007-04-01 17:39:19 UTC (rev 381) +++ trunk/pybridge/pybridge/ui/eventhandler.py 2007-04-01 17:41:14 UTC (rev 382) @@ -1,5 +1,5 @@ # PyBridge -- online contract bridge made easy. -# Copyright (C) 2004-2006 PyBridge Project. +# Copyright (C) 2004-2007 PyBridge Project. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -10,7 +10,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. - +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -18,15 +18,33 @@ from zope.interface import implements -from pybridge.interfaces.table import ITableEvents -from pybridge.interfaces.bridgetable import IBridgeTableEvents -from pybridge.interfaces.serverstate import IServerEvents +from pybridge.interfaces.observer import IListener +class SimpleEventHandler: + """An implementation of IListener which redirects updates to its target.""" + + implements(IListener) + + + def __init__(self, target, prefix='event_'): + self.__target = target + self.__prefix = prefix + + + def update(self, event, *args, **kwargs): + """Redirects named event to target's handler method, if present.""" + method = getattr(self.__target, "%s%s" % (self.__prefix, event), None) + if method: + method(*args, **kwargs) + + + + class EventHandler: """An implementation of ITableEvents.""" - implements(IServerEvents, ITableEvents, IBridgeTableEvents) + #implements(IServerEvents, ITableEvents, IBridgeTableEvents) def __init__(self): @@ -37,7 +55,7 @@ def connectionLost(self, connector, reason): - print "lost connection -", reason.getErrorMessage() + print "Lost connection:", reason.getErrorMessage() self.runCallbacks('connectionLost', connector, reason) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |