On 26.02.2015 12:09, Stephan Bergmann wrote: > On 02/26/2015 11:42 AM, Michael Stahl wrote: >> On 26.02.2015 01:16, Jens Tröger wrote: >>> Thanks Michael. Looking at 13. in this FAQ >>> >>> http://www.openoffice.org/udk/python/python-bridge.html#faq >>> >>> it seems that queryInterface() is not needed. Thus, I'm using the >> >> that is true if you know that the interface is implemented (and very >> convenient), but i don't know what happens in case the service does not >> actually support the interface you want to call (i.e. looking up the >> method fails). probably you get some kind of exception. > > According to Miklos: "afaik the usual way to check if a python object > has a method "foo" is 'if "foo" in dir(obj):', hope that also works with > pyuno objects."
guess that would work, unless a service implements 2 different interfaces that overload the same method name (i hope we don't have any such overloading...). or you could call the method and catch the "AttributeError" if it does not exist. it's also possible to manually call queryInterface though probably that is not idiomatic in Python: >>> import uno >>> from com.sun.star.uno.TypeClass import INTERFACE >>> x = uno.getComponentContext() >>> y = x.queryInterface(uno.Type("com.sun.star.uno.XComponentContext", INTERFACE)) >>> y pyuno object (com.sun.star.uno.XComponentContext)0x7f0941697060{, supportedInterfaces={com.sun.star.uno.XComponentContext,com.sun.star.container.XNameContainer,com.sun.star.lang.XTypeProvider,com.sun.star.uno.XWeak,com.sun.star.lang.XComponent}} >>> z = x.queryInterface(uno.Type("com.sun.star.util.XCloseable", INTERFACE)) >>> z is None True _______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice