Re: [Zope3-Users] fine grained subscriber
El mié, 28-03-2007 a las 13:39 +0200, Lorenzo Gil Sanchez escribió: > El mié, 28-03-2007 a las 12:50 +0200, FB escribió: > > > > You need a dispatcher - a quite common concept in zope3: > > > > [events.py, not tested] > > from zope.event import notify > > > > def removeIntId(event): > > notify(event.object,event) > > > I changed the removeIntId dispatcher to this code: def removeIntId(event): adapters = zope.component.subscribers((event.object, event), None) for adapter in adapters: pass # getting them does the work and now it works!! My subscriber is called only when an IntId is removed on objects that provide IMyInterface. Thanks a lot Mark, for showing me the right direction. Regards, Lorenzo ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] fine grained subscriber
El mié, 28-03-2007 a las 12:50 +0200, FB escribió: > > You need a dispatcher - a quite common concept in zope3: > > [events.py, not tested] > from zope.event import notify > > def removeIntId(event): > notify(event.object,event) > I think the notify call should be like notify((event.object, event)) > def addIntId(event): > notify(event.object,event) > > > > [configure.zcml, not tested] >[...] > handler=".event.addIntId" > /> > handler=".events.removeIntId" > /> >[...] > Ok, the removeIntId function is called and it dispatch the event through the notify call. Then, my original subscriber, e.g.: is still not called. I have checked that in the removeIntId subscriber the object in event.object provides IMyInterface, but this makes no difference. Anyway, thanks for this answer (and all the other answer you gave me before) :-) Regards, Lorenzo ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] fine grained subscriber
Hi, On Wed, Mar 28, 2007 at 12:16:23PM +0200, Lorenzo Gil Sanchez wrote: [snip] > But I'd like to avoid the if clause inside my subscriber function by > doing something similar to this: > > def intIdRemovedSubscriber(obj, event): > # do some stuff with obj, which is garanteed to provide IMyInterface > > handler=".intIdRemovedSubscriber" > for=".interfaces.IMyInterface > zope.app.intid.interfaces.IIntIdRemovedEvent" > /> [snip] > So the question is: why the intid package is succesful in registering a > subscriber only for ILocation objects and I can't do the same with > IMyInterface objects? > > I want to avoid a lot of calls to my subscriber which will happend > everytime an IntId is removed from *any* object. [snip] You need a dispatcher - a quite common concept in zope3: [events.py, not tested] from zope.event import notify def removeIntId(event): notify(event.object,event) def addIntId(event): notify(event.object,event) [configure.zcml, not tested] [...] [...] Thanks to zope3's component infrastructure, a package (like intid) doesn't have to provide the dispatcher - a different package providing the dispatcher is perfectly fine. Regards, Frank ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
[Zope3-Users] fine grained subscriber
Hi, I'm writing an event subscriber to the IIntIdRemoveEvent event type. It looks like this: def intIdRemovedSubscriber(event): if IMyInterface.providedBy(event.object): # do some stuff with event.object and the zcml: But I'd like to avoid the if clause inside my subscriber function by doing something similar to this: def intIdRemovedSubscriber(obj, event): # do some stuff with obj, which is garanteed to provide IMyInterface But when doing this second aproach my subscriber is not called. I supposed I could do this by looking in the zope source code and finding this in zope.app.intid.__init__.py @adapter(ILocation, IObjectRemovedEvent) def removeIntIdSubscriber(ob, event): # and So the question is: why the intid package is succesful in registering a subscriber only for ILocation objects and I can't do the same with IMyInterface objects? I want to avoid a lot of calls to my subscriber which will happend everytime an IntId is removed from *any* object. Thanks in advance Lorenzo Gil ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users