def listen(receiver, soClass, signal, alsoSubclasses=True, weak=True): """ Listen for the given ``signal`` on the SQLObject subclass ``soClass``, calling ``receiver()`` when ``send(soClass, signal, ...)`` is called. If ``alsoSubclasses`` is true, receiver will also be called when an event is fired on any subclass. """ dispatcher.connect(receiver, signal=signal, sender=soClass, weak=weak) weakReceiver = ref(receiver) subclassClones.setdefault(soClass, []).append((weakReceiver, signal))
called after the class's ``__classinit__``). """ def _makeSubclassConnections(new_class_name, bases, new_attrs, post_funcs, early_funcs): early_funcs.insert(0, _makeSubclassConnectionsPost) def _makeSubclassConnectionsPost(new_class): for cls in new_class.__bases__: for weakReceiver, signal in subclassClones.get(cls, []): receiver = weakReceiver() if not receiver: continue listen(receiver, new_class, signal) dispatcher.connect(_makeSubclassConnections, signal=ClassCreateSignal) # @@: Should there be a class reload event? This would allow modules # to be reloaded, possibly. Or it could even be folded into # ClassCreateSignal, since anything that listens to that needs to pay # attention to reloads (or else it is probably buggy). class RowCreateSignal(Signal): """ Called before an instance is created, with the class as the sender. Called with the arguments ``(kwargs, post_funcs)``. There may be a ``connection`` argument. ``kwargs``may be usefully modified. ``post_funcs`` is a list of callbacks, intended to have functions appended to it, and are called with the arguments ``(new_instance)``.
def _makeSubclassConnections(new_class_name, bases, new_attrs, post_funcs, early_funcs): early_funcs.insert(0, _makeSubclassConnectionsPost) def _makeSubclassConnectionsPost(new_class): for cls in new_class.__bases__: for weakReceiver, signal in subclassClones.get(cls, []): receiver = weakReceiver() if not receiver: continue listen(receiver, new_class, signal) dispatcher.connect(_makeSubclassConnections, signal=ClassCreateSignal) # @@: Should there be a class reload event? This would allow modules # to be reloaded, possibly. Or it could even be folded into # ClassCreateSignal, since anything that listens to that needs to pay # attention to reloads (or else it is probably buggy). class RowCreateSignal(Signal): """ Called before an instance is created, with the class as the sender. Called with the arguments ``(instance, kwargs, post_funcs)``. There may be a ``connection`` argument. ``kwargs``may be usefully modified. ``post_funcs`` is a list of callbacks, intended to have functions appended to it, and are called with the arguments ``(new_instance)``.