Re: [pyxpcom] how to get a nsIWeakReference in pyxpcom?
by Shane Caraveo other posts by this author
Jun 21 2007 11:26AM messages near this date
view in the new Beta List Site
[pyxpcom] how to get a nsIWeakReference in pyxpcom?
|
Re: [pyxpcom] how to get a nsIWeakReference in pyxpcom?
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
|