Top-rated recipes tagged "slot"http://code.activestate.com/recipes/tags/slot/top/2011-12-12T22:47:25-08:00ActiveState Code RecipesImproved Signals/Slots implementation in Python (Python)
2011-12-12T22:47:25-08:00Christopher S. Casehttp://code.activestate.com/recipes/users/4180238/http://code.activestate.com/recipes/577980-improved-signalsslots-implementation-in-python/
<p style="color: grey">
Python
recipe 577980
by <a href="/recipes/users/4180238/">Christopher S. Case</a>
(<a href="/recipes/tags/events/">events</a>, <a href="/recipes/tags/qt4/">qt4</a>, <a href="/recipes/tags/signal/">signal</a>, <a href="/recipes/tags/slot/">slot</a>).
</p>
<p>I've modified the excellent <a href="http://code.activestate.com/recipes/576477-yet-another-signalslot-implementation-in-python/"><a href="http://code.activestate.com/recipes/576477/">recipe 576477</a></a> to allow for non method functions as well as method functions. This implementation also uses a WeakKeyDictionary instead of a WeakValueDictionary for reasons of code simplification/style.</p>
Named Sequences for environments containing large numbers of POD instances (Python)
2010-11-27T13:55:18-08:00Kevin L. Sitzehttp://code.activestate.com/recipes/users/4173535/http://code.activestate.com/recipes/577473-named-sequences-for-environments-containing-large-/
<p style="color: grey">
Python
recipe 577473
by <a href="/recipes/users/4173535/">Kevin L. Sitze</a>
(<a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/memory/">memory</a>, <a href="/recipes/tags/sequence/">sequence</a>, <a href="/recipes/tags/slot/">slot</a>, <a href="/recipes/tags/unittests/">unittests</a>).
</p>
<p>Generate classes with named data attributes that can be sequenced.
Useful for POD classes for which many records will exist concurrently.</p>
<p>Compare the feature set to NamedTuples by Raymond Hettinger:
<a href="http://code.activestate.com/recipes/500261-named-tuples/" rel="nofollow">http://code.activestate.com/recipes/500261-named-tuples/</a></p>
Yet another signal/slot implementation in Python (Python)
2008-09-01T23:21:28-07:00Thiago Marcos P. Santoshttp://code.activestate.com/recipes/users/4166797/http://code.activestate.com/recipes/576477-yet-another-signalslot-implementation-in-python/
<p style="color: grey">
Python
recipe 576477
by <a href="/recipes/users/4166797/">Thiago Marcos P. Santos</a>
(<a href="/recipes/tags/observer/">observer</a>, <a href="/recipes/tags/publish/">publish</a>, <a href="/recipes/tags/signal/">signal</a>, <a href="/recipes/tags/slot/">slot</a>, <a href="/recipes/tags/subscribe/">subscribe</a>, <a href="/recipes/tags/weakref/">weakref</a>).
</p>
<p>This code snippet was based on the nice <a href="http://code.activestate.com/recipes/439356/">recipe 439356</a> made by Patrick Chasco. My implementation supports only class methods callbacks. I'm keeping the idea of use weakrefs to avoid the interpreter keep the object allocated because the signal is registered (i.e. the signal object holds a reference to callback method). IMO the usage of WeakValueDictionary made the code smaller and clear and also are maintenance-free (when the object is collect by the garbage collector the signal is automatically unregistered). </p>