Really thought there’d be a simple answer here.
I found this page. This didn’t seem applicable to my case.
And I found XInterface.queryInterface() from consulting the docs.
But this doesn’t work with this, where I want to check whether something implements XComponent:
def documentEventOccured(self, event):
if event.EventName == 'OnSubComponentOpened':
# this print out shows that event.Supplement does indeed implement com.sun.star.lang.XComponent
print(f'doc event.Supplement {event.Supplement}')
print(f'event.Supplement.queryInterface(XComponent) {event.Supplement.queryInterface(XComponent)}')
This gives:
uno.com.sun.star.uno.RuntimeException: Couldn’t convert <class ‘uno.com.sun.star.lang.XComponent’> to a UNO type; caught exception: <class ‘AttributeError’>: type object ‘com.sun.star.lang.XComponent’ has no attribute ‘getTypes’, traceback follows
no traceback available
So, despite the name, it would appear that queryInterface
is not for checking interfaces (at least not those of the kind beginning X…). How might I check that an object implements a particular UNO interface such as XComponent
?
Incidentally I also tried a vanilla Python isinstance
test:
print(f'isinstance(event.Supplement, XComponent) {isinstance(event.Supplement, XComponent)}')
… False.