Author: tack
Date: Thu Jan 17 16:00:39 2008
New Revision: 2972
Log:
Ability to defer emission until there is callback connected to the signal.
Modified:
trunk/base/src/notifier/callback.py
Modified: trunk/base/src/notifier/callback.py
==============================================================================
--- trunk/base/src/notifier/callback.py (original)
+++ trunk/base/src/notifier/callback.py Thu Jan 17 16:00:39 2008
@@ -261,6 +261,7 @@
def __init__(self, changed_cb = None):
self._callbacks = []
self._changed_cb = changed_cb
+ self._deferred_args = []
def __iter__(self):
@@ -323,6 +324,12 @@
self._callbacks.insert(pos, callback)
if self._changed_cb:
self._changed_cb(self, Signal.SIGNAL_CONNECTED)
+
+ if self._deferred_args:
+ for args, kwargs in self._deferred_args:
+ self.emit(*args, **kwargs)
+ del self._deferred_args[:]
+
return callback
@@ -397,6 +404,26 @@
return retval
+ def emit_deferred(self, *args, **kwargs):
+ """
+ Queues the emission until after the next callback is connected. This
+ allows a signal to be 'primed' by its creator, and the handler that
+ subsequently connects to it will be called with the given arguments.
+ """
+ self._deferred_args.append((args, kwargs))
+
+
+ def emit_when_handled(self, *args, **kwargs):
+ """
+ Emits the signal if there are callbacks connected, or defer it until
+ the first callback is connected.
+ """
+ if self.count():
+ return self.emit(*args, **kwargs)
+ else:
+ self.emit_deferred(*args, **kwargs)
+
+
def _weakref_destroyed(self, weakref, callback):
if _python_shutting_down == False:
self._disconnect(callback, (), {})
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog