It’s more of a workaround, but better than nothing. After talking on #python, turned out, type()
python function returns the type itself, not a string! So, as a workaround, you might be able to get the type from something you always has around, and then use that to compare. Here’s a demo:
test.py
:
#!python
import uno
# run libreoffice as:
# soffice --calc --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"
def connectToLO():
# get the uno component context from the PyUNO runtime
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext )
# connect to the running office
ctx = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
return desktop.CurrentComponent
model = connectToLO()
TYPE_UNO_CALLABLE = type(model.getPropertyValue)
# Example assumes you have the ActiveSheet.getColumns, which is available in LO
# Calc. I've used that to have something different from `model` to compare.
if isinstance(model.CurrentController.ActiveSheet.getColumns, TYPE_UNO_CALLABLE):
print('Hey, it works!')
else:
print("it doesn't work ☹")
In shell:
$ python test.py
Hey, it works!