Hello,
I have an Addin and an Addon. Addin is in C++ and the Addon is python.
In the addon I am trying the following code,
service = CreateUnoService("my_module.MyService1")
service.Initialize(a,b,c,d)
(The initialize routine is defined in service, and can be called succressfully from basic)
It doesn't work. The second line tanks....I am not good at python so I do not know how to print errors....
try:
service.Initialize(a,b,c,d)
except Exception as inst:
f = open('/tmp/err.log', 'w')
f.write('saleem\n')
f.write(type(inst))
It does create the file and put my name in it, but the next line does not do anything.....
Saleem
Create and Call Uno Service in Python
Create and Call Uno Service in Python
OpenOffice 3.4.0
Mac OS X 10.5.8
Mac OS X 10.5.8
Re: Create and Call Uno Service in Python
Code: Select all
class Office:
'''Frequently used methods in office context'''
def __init__(self, ctx=uno.getComponentContext()):
self.ctx = ctx
self.smgr = self.ctx.ServiceManager
def createUnoService(self, service):
return self.smgr.createInstance(service)
def getDesktop(self):
return self.smgr.createInstanceWithContext("com.sun.star.frame.Desktop",self.ctx)
def getCurrentComponent(self):
return self.getDesktop().getCurrentComponent()
def getCurrentFrame(self):
return self.getDesktop().getCurrentFrame()
def getCurrentComponentWindow(self):
return self.getCurrentFrame().getComponentWindow()
def getCurrentContainerWindow(self):
return self.getCurrentFrame().getContainerWindow()
def getCurrentController(self):
return self.getCurrentFrame().getController()
def callMRI(self,obj=None):
'''Create an instance of MRI inspector and inspect the given object (default is selection)'''
if not obj:
obj = self.getCurrentController().getSelection()
mri = self.createUnoService("mytools.Mri")
mri.inspect(obj)
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Create and Call Uno Service in Python
The second line should save type (i.e. name of class) of your exception. Make sure that the file is closed properly after writing. EitherIt does create the file and put my name in it, but the next line does not do anything.....
Code: Select all
f = open(.....)
f.write(...)
f.write(...)
f.close()
Code: Select all
with open(.....) as f:
f.write(...)
f.write(...)
Code: Select all
f.write(repr(type(inst)))
JJ ∙ https://forum.openoffice.org/pl/
LO (25.2|24.8) ∙ Python (3.12|3.10) ∙ Unicode 16 ∙ LᴬTEX 2ε ∙ XML ∙ Unix tools ∙ Linux (Rocky|CentOS)
LO (25.2|24.8) ∙ Python (3.12|3.10) ∙ Unicode 16 ∙ LᴬTEX 2ε ∙ XML ∙ Unix tools ∙ Linux (Rocky|CentOS)
Re: Create and Call Uno Service in Python
service = CreateUnoService("my_module.MyService1")
service.Initialize(a,b,c,d)
The exception throw is of type --
exceptions.AttributeError
Any idea what that means?? What else could I add to the logging to shed further light on whats going wrong??
Thanks,
Saleem
service.Initialize(a,b,c,d)
The exception throw is of type --
exceptions.AttributeError
Any idea what that means?? What else could I add to the logging to shed further light on whats going wrong??
Thanks,
Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
Mac OS X 10.5.8
Re: Create and Call Uno Service in Python
How did you define def CreateUnoService?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice