Author: dmeyer
Date: Fri Jan 12 15:00:01 2007
New Revision: 2381
Added:
trunk/base/test/signals.py
Modified:
trunk/base/src/notifier/callback.py
Log:
add Signals class (dict) for easier use of signal dicts
Modified: trunk/base/src/notifier/callback.py
==============================================================================
--- trunk/base/src/notifier/callback.py (original)
+++ trunk/base/src/notifier/callback.py Fri Jan 12 15:00:01 2007
@@ -30,7 +30,7 @@
#
# -----------------------------------------------------------------------------
-__all__ = [ 'Callback', 'WeakCallback', 'Signal' ]
+__all__ = [ 'Callback', 'WeakCallback', 'Signal', 'Signals' ]
# Python imports
import _weakref
@@ -485,6 +485,42 @@
return len(self._callbacks)
+class Signals(dict):
+ """
+ Dict of Signal object.
+ """
+ def __init__(self, *signals):
+ dict.__init__(self)
+ for s in signals:
+ if isinstance(s, dict):
+ # parameter is a dict/Signals object
+ self.update(s)
+ elif isinstance(s, str):
+ # parameter is a string
+ self[s] = Signal()
+ else:
+ # parameter is something else, bad
+ raise AttributeError('signal key must be string')
+
+
+ def __getattr__(self, attr):
+ """
+ Get attribute function from Signal().
+ """
+ if attr.startswith('_') or not hasattr(Signal, attr):
+ return dict.__getattr__(self, attr)
+ callback = Callback(self.__callattr__, attr)
+ callback.set_user_args_first(True)
+ return callback
+
+
+ def __callattr__(self, attr, signal, *args, **kwargs):
+ """
+ Call attribute function from Signal().
+ """
+ return getattr(self[signal], attr)(*args, **kwargs)
+
+
def _shutdown_weakref_destroyed():
global _python_shutting_down
_python_shutting_down = True
Added: trunk/base/test/signals.py
==============================================================================
--- (empty file)
+++ trunk/base/test/signals.py Fri Jan 12 15:00:01 2007
@@ -0,0 +1,13 @@
+import kaa.notifier
+
+def myfunc(value):
+ print 'x', value
+
+signals = kaa.notifier.Signals('foo', 'bar')
+signals.connect('foo', myfunc)
+
+signals['foo'].emit(1)
+signals.emit('foo', 2)
+
+sig2 = kaa.notifier.Signals(signals, 'new')
+print sig2.keys()
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog