Hi,
I made an extension my_utils as an uno_package.
In a second extension I need some of the functions I did in the previous package. Is there a way to import module from the previous pakcage my_utils ?
For now, I tried to play with pythonloader or pythonscript looking for a way to list available with no concrete result.
[Python] Import module from other extension
[Python] Import module from other extension
Last edited by Bastien on Thu Oct 14, 2021 5:22 pm, edited 1 time in total.
LibreOffice 6.2.3.2 on Ubuntu 19.04
Re: [Python] Import module from other extension
Have a look at the StarBasic code delivered with MRI.
You can do the same with Python:
If your extension is just some macro code not providing any UNO service,
<user_profile>/Scripts/python/pythonpath/ is the path where macros can find user defined modules. You may experiment with symlinks in that directory pointing to your script file.
Code: Select all
oMRI = CreateUnoService( "mytools.Mri" )
oMRI.inspect( MriTargetObject )
Code: Select all
ctx = uno.getComponentContext
smgr = ctx.ServiceManager
oMRI = smgr.createInstance( "mytools.Mri" )
oMRI.inspect( MriTargetObject )
<user_profile>/Scripts/python/pythonpath/ is the path where macros can find user defined modules. You may experiment with symlinks in that directory pointing to your script file.
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: [Python] Import module from other extension
So I followed your advice and indeed, seems I get closer ! I created extensions, so I don't use the
<user_profile>/Scripts/python/pythonpath/.
There is no method inspect() in oBal. It's a pyuno object which not seems to contains macros from the main module (called rdt_bal.py) in the package.
<user_profile>/Scripts/python/pythonpath/.
Code: Select all
ctx = uno.getComponentContext()
smgr = ctx.ServiceManager
oBal = smgr.createInstance('com.rdt.comp.Bal')
LibreOffice 6.2.3.2 on Ubuntu 19.04
Re: [Python] Import module from other extension
inspect(obj) is a function of the mri service.
Does your service include com.sun.star.task.Job with interface com.sun.star.task.XJobExecutor having method trigger?
Same in Basic
The string argument (empty here) can be used to pass additional info about the caller.
Does your service include com.sun.star.task.Job with interface com.sun.star.task.XJobExecutor having method trigger?
Code: Select all
ctx = uno.getComponentContext()
smgr = ctx.ServiceManager
oBal = smgr.createInstance('com.rdt.comp.Bal')
oBal.trigger('')
Code: Select all
oBal = CreateUnoService("com.rdt.comp.Bal")
oBal.trigger("")
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
-
- Posts: 14
- Joined: Wed Oct 06, 2010 6:26 am
Re: [Python] Import module from other extension
Also posted at https://ask.libreoffice.org/t/load-modu ... er-package.
LO / AOO on Ubuntu / Windows
Re: [Python] Import module from other extension
Indeed, this topic is to be pursued in the asklibreoffice.org forum
LibreOffice 6.2.3.2 on Ubuntu 19.04