Re: [pyxpcom] how to get a nsIWeakReference in pyxpcom?
by Shane Caraveo other posts by this author
Jun 21 2007 12:23PM messages near this date
view in the new Beta List Site
Re: [pyxpcom] how to get a nsIWeakReference in pyxpcom?
|
Re: [pyxpcom] how to get a nsIWeakReference in pyxpcom?
Ahh, I see the problem. pyxpcom WeakReference class != nsIWeakReference
instance, but is a wrapper of that instead to may xpcom weakreferences
work like python weakreferences. So you cannot use
xpcom.client.WeakReference directly. What you had in the first place is
the correct thing to do:
self.browser.addWebBrowserListener(weak_ref2._comobj_,
interfaces.nsIWebProgressListener)
Shane
Tomeu Vizoso wrote:
> Yeah, I have read that at least a dozen times today ;)
>
> self.browser.addWebBrowserListener(WeakReference(chrome, interfaces.nsIWebProgressListener
),
> interfaces.nsIWebProgressListener)
>
> doesn't work:
>
> File "<XPCOMObject method 'addWebBrowserListener'>", line 3, in addWebBrowserListener
> TypeError: Objects of type 'instance' can not be used as COM objects
>
> On Thu, 2007-06-21 at 11:29 -0700, Shane Caraveo wrote:
> > From the doc string for WeakReference:
> >
> > class WeakReference:
> > """A weak-reference object. You construct a weak reference by passing
> > any COM object you like. If the object does not support weak
> > refs, you will get a standard NS_NOINTERFACE exception.
> >
> > Once you have a weak-reference, you can "call" the object to get
> > back a strong reference. Eg:
> >
> > >>> some_ob = components.classes['...']
> > >>> weak_ref = WeakReference(some_ob)
> > >>> new_ob = weak_ref() # new_ob is effectively "some_ob" at this point
> > >>> # EXCEPT: new_ob may be None if some_ob has already died - a
> > >>> # weak reference does not keep the object alive (that is the point)
> >
> > You should never hold onto this resulting strong object for a long
> > time,
> > or else you defeat the purpose of the weak-reference.
> > """
> >
> >
> > Tomeu Vizoso wrote:
> >> Hi all,
> >>
> >> I need to pass a reference to a nsIWeakReference to
> >> nsIWebBrowser.addWebBrowserListener(nsIWeakReference listener, nsIIDRef
> >> IID).
> >>
> >> The only way I've found to do it is this:
> >>
> >> listener = xpcom.server.WrapObject(chrome, interfaces.nsIWebProgressListener)
> >> weak_ref2 = xpcom.client.WeakReference(listener)
> >> self.browser.addWebBrowserListener(weak_ref2._comobj_,
> >> interfaces.nsIWebProgressListener)
> >>
> >> I guess weak_ref2._comobj_ is not the best way to get a nsIWeakReference.
> >>
> >> Any suggestion?
> >>
> >> Thanks,
> >>
> >> Tomeu
> >>
> >> _______________________________________________
> >> pyxpcom mailing list
> >> pyxpcom@[...].com
> >> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
pyxpcom mailing list
pyxpcom@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Tomeu Vizoso
Shane Caraveo
Tomeu Vizoso
Shane Caraveo
Tomeu Vizoso
Mark Hammond
|