You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openoffice.apache.org by Damjan Jovanovic <da...@apache.org> on 2026/04/24 04:03:09 UTC
Progress in Python script editing and embedding
Hi
Our Python script/macro integration is the worst of all our scripting
languages. While StarBasic, BeanShell and Javascript can be created, edited
and debugged within OpenOffice, Python can only be run. Python scripts can
only be embedded into documents manually, by unzipping the OpenDocument
file, copying in the scripts, and then zipping it back up (
https://wiki.openoffice.org/wiki/Python_as_a_macro_language).
Also Python works as badly in LO as it does with us.
On bugs 60849 and 75132 I started trying to improve that, so Python scripts
can be embedded into documents, and created/deleted/renamed within
OpenOffice, and have made considerable progress.
The ScriptProvider implementations for Java, Javascript, and BeanShell are
within main/scripting/java/org, while Python one is in
main/scripting/source/pyprov/pythonscript.py. The fact that Java
implementation had much more code, including UI dialogs, first led me to
try adding a script provider for Python in there. But when I did, I
realized that won't work well, as invoke() is called in Java but must reach
Python, requiring a double UNO call: C++ -> Java -> Python, which would be
bad for performance. Also further investigation led me to realize the UI
dialogs in the Java code are unused, all the UI elements come from
main/cui/source/dialogs/scriptdlg.cxx instead.
What finally convinced me to go back to improving the Python ScriptProvider
is that the scripting framework specifications (
https://www.openoffice.org/specs/scripting_framework/index.html) explained
how each language ScriptProvider is supposed to operate independently, and
can nest its XBrowseNodes in whatever way best represents that language's
scripts. The Java/JavaScript/BeanShell ScriptProviders uses
parcel-descriptor.xml files to define the scripts, using an entire file as
a script, and have a nesting of root -> library -> macro. Python is
completely different, with no parcel-descriptor.xml, instead of complete
files it is the functions in the .py files that are scripts, and the
nesting is root -> library -> macro -> function.
Eventually by comparing Java's XBrowseNode implementations with Python's, I
saw Java's XBrowseNode was implementing XPropertySet and XInvocation on
some of its nodes, while Python wasn't. When I added those to Python, and
handled the "Creatable", "Editable" and other properties, the macro dialog
started enabling buttons that were previously greyed out, but only on
existing libraries, I couldn't create new libraries from root sources like
the document, and really struggled to understand why.
I thought it was a lost cause and was about to give up, but then an idea
came to me. I realized that PythonScriptProvider itself implement
XBrowseNode, and forwards method calls to XBrowseNode methods to its
DirBrowseNode field, and reasoned that just like XPropertySet and
XInvocation had to be added to DirBrowseNode, they might have to be added
to the PythonScriptProvider too, and also forwarded to that DirBrowseNode
field. When I did that, top-level sources like the document started
allowing creation of libraries within them :-).
Implementing XPropertySet and XInvocation on FileBrowseNode even got macro
creation to work, successfully embedding (admittedly empty) .py files into
documents :-) :-).
A number of issues however were discovered:
- All macro operations (creating, renaming, deleting) give false errors
saying they failed, but actually succeed, you need to close and re-open the
macro dialog to see the changes. I suspect this is a bug in the Python UNO
bridge.
- Creating libraries inside documents is completely broken on Windows, the
UI buttons stay greyed out. This is some kind of a permission issue when
calling isReadOnly() on the SimpleFileAccess interface for the document.
- The documentation for Python development leaves a lot to be desired. It
took me forever to find how to create the UNO Any type. Handling "out"
parameters is completely different to other languages. The best document is
actually https://www.openoffice.org/udk/python/python-bridge.html which is
also completely hidden and I only found it by accident.
Apart from those issues, we now need to add Python editing in OpenOffice
for it to be really useful. Still considering what to do there. The scripts
embedded in documents especially, need to be accessed through a custom URL
and our UCB system, and won't be easily accessible to external
applications. There is some code in main/scripting/java that allows
NetBeans to edit BeanShell files, but might require OpenOffice to be
started with an UNO listening port
(scripting/java/org/openoffice/idesupport/localoffice/LocalOfficeImpl.java),
something that won't fly in production.
Developing OpenOffice in Python is actually remarkably simple and pleasant,
It is a first-class UNO language, capable of both consuming UNO components,
and implementing them. Python is probably too slow for serious development,
but given how Python components don't need compiling to redeploy changes,
just OpenOffice restart, it is much faster to develop with.
My preliminary changes have been pushed to the python-editing-embedding
branch. There is no need to build, you can just copy
main/scripting/source/pyprov/pythonscript.py over the one in an existing
OpenOffice instance, it's in the same directory as the main soffice[.exe]
executable. Then start OpenOffice, create or open a document, and compare
Tools -> Macros -> Organize Macros -> Python before and after. Creating,
renaming, and deleting Python libraries and macros should work (to some
degree, on *nix at least), although with false errors afterwards (close and
reopen the dialog to see the changes).
You can also run OpenOffice with the environment
variables PYSCRIPT_LOG_LEVEL=DEBUG PYSCRIPT_LOG_STDOUT=1 set, so that the
Python ScriptProvider logs debugging info to standard output. (It would be
best to change this to the XLogger logging framework eventually.)
Regards
Damjan
Re: Progress in Python script editing and embedding
Posted by Arrigo Marchiori <ar...@apache.org>.
Hello,
a possibly interesting note:
On Wed, Apr 29, 2026 at 10:33:31PM +0200, Arrigo Marchiori wrote:
[...]
> Now, the "Save" button does not seem to have any effect.
>
> If I make some edits to the Python macros, then "Close" the macro
> editing window, and then I open it again (Tools -> Macros -> Organize
> macros -> Python -> file.odt -> Library1 -> Macro1, Edit) I find the
> previous contents, with my changes lost.
The Python code _is_ saved, but only once, when I create a new macro.
If I edit existing code, the changes are not saved.
I hope this helps.
Best regards,
--
Arrigo
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org
Re: Progress in Python script editing and embedding
Posted by Pe...@apache.org.
great! thanks Damjan for this effort. :)
Am 24.05.2026 um 04:42 schrieb Damjan Jovanovic:
> Hi
>
> I've now merged the python-editing-embedding branch into trunk, and
> cherry-picked it to AOO42X.
>
> Should I cherry-pick it to AOO41X as well?
>
> One minor change I made since my last update is using a fixed-width font
> for the Python editor window.
>
> Regards
> Damjan
>
>
> On Thu, Apr 30, 2026 at 5:23 AM Damjan Jovanovic <da...@apache.org> wrote:
>
>> Thank you so much for the thorough testing Arrigo.
>>
>> What happens there is:
>> - KeyError gets thrown from removeModuleByUrl() because the "del
>> self.modules[ url ]" is trying to delete a key that isn't in the
>> dictionary, causes saving to fail after the file is written but before the
>> ".orig" file is deleted.
>> - The exception is swallowed in actionPerformed() and logged, but the
>> logging is invisible unless you run AOO with the Python debugging
>> environment variables.
>> - Future saves then fail because an earlier statement
>> "self.provCtx.sfa.move( self.uri(), copyUrl )" throws an exception, because
>> copyUrl is the ".orig" file, and it already exists from the first save
>> because of that KeyError, so the move() refuses to overwrite it.
>>
>> From what I see, no other ScriptProvider uses that technique of renaming
>> the intended file to a ".orig" file, then saving to the intended file, then
>> deleting the ".orig" file. I've now removed that from the Python script
>> provider as well. Also I've started using "self.modules.pop( url, None )"
>> instead of "del self.modules[ url ]", so the KeyError isn't thrown on keys
>> that don't exist in the dictionary.
>>
>> It now always saves successfully and always runs the latest code.
>>
>> Regards
>> Damjan
>>
>>
>> On Wed, Apr 29, 2026 at 10:33 PM Arrigo Marchiori <ar...@apache.org>
>> wrote:
>>
>>> Hello Damjan, All,
>>>
>>> On Wed, Apr 29, 2026 at 05:39:56AM +0200, Damjan Jovanovic wrote:
>>>
>>>> On Mon, Apr 27, 2026 at 9:39 PM Arrigo Marchiori <ar...@apache.org>
>>> wrote:
>>> [...]
>>>>> I've played a bit with Python macros and I think I found a small bug.
>>>>>
>>>>> On Sun, Apr 26, 2026 at 08:36:07PM +0200, Damjan Jovanovic wrote:
>>>>>
>>>>> [...]
>>>>>
>>>>>> Most of all, Python scripts can now be edited :-), in a custom
>>> little
>>>>>> dialog window with "Run", "Save" and "Close" buttons. It all works,
>>> they
>>>>>> run, they are successfully saved into the document, and can be
>>> re-opened.
>>>>>> The editing could still be improved a lot, with line numbers,
>>> debugging,
>>>>> a
>>>>>> resizable window and fixed width font, etc., but I don't have time
>>> for
>>>>> that
>>>>>> now, and to be fair, the BeanShell editor isn't much better.
>>>>> When we click button "Save" of the new Python editing dialog, the code
>>>>> is saved, but apparently is not ``active'' yet.
>>>>>
>>>>> In other words, the ``old'' Python source code is still executed
>>>>> whenever we ask to ``run'' a macro.
>>>>>
>>>>> In order to run the new code, we have to close and reopen the
>>>>> _document_.
>>>>>
>>>> Thank you for testing. You're right, there was a bug there. I think it's
>>>> fixed now:
>>>>
>>>> Forget Python modules from the cache after they are saved, so they
>>>> get reloaded in the future. This is necessary as getModuleByUrl()'s
>>>> self.sfa.getDateTimeModified() returns timestamps with all zeroes
>>>> for documents (== ZIP files), breaking the test for whether the
>>>> embedded Python file has been changed. Also even if it worked, the
>>>> minimum granularity for timestamps in ZIP files is 2 seconds, which
>>>> isn't good enough.
>>> Now, the "Save" button does not seem to have any effect.
>>>
>>> If I make some edits to the Python macros, then "Close" the macro
>>> editing window, and then I open it again (Tools -> Macros -> Organize
>>> macros -> Python -> file.odt -> Library1 -> Macro1, Edit) I find the
>>> previous contents, with my changes lost.
>>>
>>> I hope this helps.
>>>
>>> Best regards,
>>> --
>>> Arrigo
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
>>> For additional commands, e-mail: dev-help@openoffice.apache.org
>>>
>>>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org
Re: Progress in Python script editing and embedding
Posted by Arrigo Marchiori <ar...@apache.org>.
Dear All,
On Sun, May 24, 2026 at 07:37:10PM +0200, Damjan Jovanovic wrote:
> On Sun, May 24, 2026 at 10:28 AM Pedro Lino wrote:
>
> > Hi Damjan
> >
> > > On 05/24/2026 3:42 AM WEST Damjan Jovanovic <da...@apache.org> wrote:
> > >
> > > I've now merged the python-editing-embedding branch into trunk, and
> > > cherry-picked it to AOO42X.
> > >
> > > Should I cherry-pick it to AOO41X as well?
> >
> > Thank you for your fixes!
+1
> > Please do include this in branch 41X
+1
> It's now included :-).
Great!
Best regards,
--
Arrigo
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org
Re: Progress in Python script editing and embedding
Posted by Pedro Lino via dev <de...@openoffice.apache.org>.
Hi Damjan
Compiled trunk and installed the resulting build on Linux Mint 22.3 x64
The edit window for Python works as expected (tested with https://www.openoffice.org/udk/python/scriptingframework/ the push button script)
Well done!
All the best,
Pedro
> On 05/24/2026 6:37 PM WEST Damjan Jovanovic <da...@apache.org> wrote:
>
>
> On Sun, May 24, 2026 at 10:28 AM Pedro Lino via dev <
> dev@openoffice.apache.org> wrote:
>
> > Hi Damjan
> >
> > > On 05/24/2026 3:42 AM WEST Damjan Jovanovic <da...@apache.org> wrote:
> > >
> > > I've now merged the python-editing-embedding branch into trunk, and
> > > cherry-picked it to AOO42X.
> > >
> > > Should I cherry-pick it to AOO41X as well?
> >
> > Thank you for your fixes!
> >
> > Please do include this in branch 41X
> >
>
> It's now included :-).
>
>
> >
> > All the best,
> > Pedro
> >
> >
> Thank you
> Damjan
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org
Re: Progress in Python script editing and embedding
Posted by Damjan Jovanovic <da...@apache.org>.
On Sun, May 24, 2026 at 10:28 AM Pedro Lino via dev <
dev@openoffice.apache.org> wrote:
> Hi Damjan
>
> > On 05/24/2026 3:42 AM WEST Damjan Jovanovic <da...@apache.org> wrote:
> >
> > I've now merged the python-editing-embedding branch into trunk, and
> > cherry-picked it to AOO42X.
> >
> > Should I cherry-pick it to AOO41X as well?
>
> Thank you for your fixes!
>
> Please do include this in branch 41X
>
It's now included :-).
>
> All the best,
> Pedro
>
>
Thank you
Damjan
Re: Progress in Python script editing and embedding
Posted by Pedro Lino via dev <de...@openoffice.apache.org>.
Hi Damjan
> On 05/24/2026 3:42 AM WEST Damjan Jovanovic <da...@apache.org> wrote:
>
> I've now merged the python-editing-embedding branch into trunk, and
> cherry-picked it to AOO42X.
>
> Should I cherry-pick it to AOO41X as well?
Thank you for your fixes!
Please do include this in branch 41X
All the best,
Pedro
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org
Re: Progress in Python script editing and embedding
Posted by Damjan Jovanovic <da...@apache.org>.
Hi
I've now merged the python-editing-embedding branch into trunk, and
cherry-picked it to AOO42X.
Should I cherry-pick it to AOO41X as well?
One minor change I made since my last update is using a fixed-width font
for the Python editor window.
Regards
Damjan
On Thu, Apr 30, 2026 at 5:23 AM Damjan Jovanovic <da...@apache.org> wrote:
> Thank you so much for the thorough testing Arrigo.
>
> What happens there is:
> - KeyError gets thrown from removeModuleByUrl() because the "del
> self.modules[ url ]" is trying to delete a key that isn't in the
> dictionary, causes saving to fail after the file is written but before the
> ".orig" file is deleted.
> - The exception is swallowed in actionPerformed() and logged, but the
> logging is invisible unless you run AOO with the Python debugging
> environment variables.
> - Future saves then fail because an earlier statement
> "self.provCtx.sfa.move( self.uri(), copyUrl )" throws an exception, because
> copyUrl is the ".orig" file, and it already exists from the first save
> because of that KeyError, so the move() refuses to overwrite it.
>
> From what I see, no other ScriptProvider uses that technique of renaming
> the intended file to a ".orig" file, then saving to the intended file, then
> deleting the ".orig" file. I've now removed that from the Python script
> provider as well. Also I've started using "self.modules.pop( url, None )"
> instead of "del self.modules[ url ]", so the KeyError isn't thrown on keys
> that don't exist in the dictionary.
>
> It now always saves successfully and always runs the latest code.
>
> Regards
> Damjan
>
>
> On Wed, Apr 29, 2026 at 10:33 PM Arrigo Marchiori <ar...@apache.org>
> wrote:
>
>> Hello Damjan, All,
>>
>> On Wed, Apr 29, 2026 at 05:39:56AM +0200, Damjan Jovanovic wrote:
>>
>> > On Mon, Apr 27, 2026 at 9:39 PM Arrigo Marchiori <ar...@apache.org>
>> wrote:
>> [...]
>> > > I've played a bit with Python macros and I think I found a small bug.
>> > >
>> > > On Sun, Apr 26, 2026 at 08:36:07PM +0200, Damjan Jovanovic wrote:
>> > >
>> > > [...]
>> > >
>> > > > Most of all, Python scripts can now be edited :-), in a custom
>> little
>> > > > dialog window with "Run", "Save" and "Close" buttons. It all works,
>> they
>> > > > run, they are successfully saved into the document, and can be
>> re-opened.
>> > > > The editing could still be improved a lot, with line numbers,
>> debugging,
>> > > a
>> > > > resizable window and fixed width font, etc., but I don't have time
>> for
>> > > that
>> > > > now, and to be fair, the BeanShell editor isn't much better.
>> > >
>> > > When we click button "Save" of the new Python editing dialog, the code
>> > > is saved, but apparently is not ``active'' yet.
>> > >
>> > > In other words, the ``old'' Python source code is still executed
>> > > whenever we ask to ``run'' a macro.
>> > >
>> > > In order to run the new code, we have to close and reopen the
>> > > _document_.
>> > >
>> >
>> > Thank you for testing. You're right, there was a bug there. I think it's
>> > fixed now:
>> >
>> > Forget Python modules from the cache after they are saved, so they
>> > get reloaded in the future. This is necessary as getModuleByUrl()'s
>> > self.sfa.getDateTimeModified() returns timestamps with all zeroes
>> > for documents (== ZIP files), breaking the test for whether the
>> > embedded Python file has been changed. Also even if it worked, the
>> > minimum granularity for timestamps in ZIP files is 2 seconds, which
>> > isn't good enough.
>>
>> Now, the "Save" button does not seem to have any effect.
>>
>> If I make some edits to the Python macros, then "Close" the macro
>> editing window, and then I open it again (Tools -> Macros -> Organize
>> macros -> Python -> file.odt -> Library1 -> Macro1, Edit) I find the
>> previous contents, with my changes lost.
>>
>> I hope this helps.
>>
>> Best regards,
>> --
>> Arrigo
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
>> For additional commands, e-mail: dev-help@openoffice.apache.org
>>
>>
Re: Progress in Python script editing and embedding
Posted by Damjan Jovanovic <da...@apache.org>.
Thank you so much for the thorough testing Arrigo.
What happens there is:
- KeyError gets thrown from removeModuleByUrl() because the "del
self.modules[ url ]" is trying to delete a key that isn't in the
dictionary, causes saving to fail after the file is written but before the
".orig" file is deleted.
- The exception is swallowed in actionPerformed() and logged, but the
logging is invisible unless you run AOO with the Python debugging
environment variables.
- Future saves then fail because an earlier statement
"self.provCtx.sfa.move( self.uri(), copyUrl )" throws an exception, because
copyUrl is the ".orig" file, and it already exists from the first save
because of that KeyError, so the move() refuses to overwrite it.
From what I see, no other ScriptProvider uses that technique of renaming
the intended file to a ".orig" file, then saving to the intended file, then
deleting the ".orig" file. I've now removed that from the Python script
provider as well. Also I've started using "self.modules.pop( url, None )"
instead of "del self.modules[ url ]", so the KeyError isn't thrown on keys
that don't exist in the dictionary.
It now always saves successfully and always runs the latest code.
Regards
Damjan
On Wed, Apr 29, 2026 at 10:33 PM Arrigo Marchiori <ar...@apache.org> wrote:
> Hello Damjan, All,
>
> On Wed, Apr 29, 2026 at 05:39:56AM +0200, Damjan Jovanovic wrote:
>
> > On Mon, Apr 27, 2026 at 9:39 PM Arrigo Marchiori <ar...@apache.org>
> wrote:
> [...]
> > > I've played a bit with Python macros and I think I found a small bug.
> > >
> > > On Sun, Apr 26, 2026 at 08:36:07PM +0200, Damjan Jovanovic wrote:
> > >
> > > [...]
> > >
> > > > Most of all, Python scripts can now be edited :-), in a custom little
> > > > dialog window with "Run", "Save" and "Close" buttons. It all works,
> they
> > > > run, they are successfully saved into the document, and can be
> re-opened.
> > > > The editing could still be improved a lot, with line numbers,
> debugging,
> > > a
> > > > resizable window and fixed width font, etc., but I don't have time
> for
> > > that
> > > > now, and to be fair, the BeanShell editor isn't much better.
> > >
> > > When we click button "Save" of the new Python editing dialog, the code
> > > is saved, but apparently is not ``active'' yet.
> > >
> > > In other words, the ``old'' Python source code is still executed
> > > whenever we ask to ``run'' a macro.
> > >
> > > In order to run the new code, we have to close and reopen the
> > > _document_.
> > >
> >
> > Thank you for testing. You're right, there was a bug there. I think it's
> > fixed now:
> >
> > Forget Python modules from the cache after they are saved, so they
> > get reloaded in the future. This is necessary as getModuleByUrl()'s
> > self.sfa.getDateTimeModified() returns timestamps with all zeroes
> > for documents (== ZIP files), breaking the test for whether the
> > embedded Python file has been changed. Also even if it worked, the
> > minimum granularity for timestamps in ZIP files is 2 seconds, which
> > isn't good enough.
>
> Now, the "Save" button does not seem to have any effect.
>
> If I make some edits to the Python macros, then "Close" the macro
> editing window, and then I open it again (Tools -> Macros -> Organize
> macros -> Python -> file.odt -> Library1 -> Macro1, Edit) I find the
> previous contents, with my changes lost.
>
> I hope this helps.
>
> Best regards,
> --
> Arrigo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
> For additional commands, e-mail: dev-help@openoffice.apache.org
>
>
Re: Progress in Python script editing and embedding
Posted by Arrigo Marchiori <ar...@apache.org>.
Hello Damjan, All,
On Wed, Apr 29, 2026 at 05:39:56AM +0200, Damjan Jovanovic wrote:
> On Mon, Apr 27, 2026 at 9:39 PM Arrigo Marchiori <ar...@apache.org> wrote:
[...]
> > I've played a bit with Python macros and I think I found a small bug.
> >
> > On Sun, Apr 26, 2026 at 08:36:07PM +0200, Damjan Jovanovic wrote:
> >
> > [...]
> >
> > > Most of all, Python scripts can now be edited :-), in a custom little
> > > dialog window with "Run", "Save" and "Close" buttons. It all works, they
> > > run, they are successfully saved into the document, and can be re-opened.
> > > The editing could still be improved a lot, with line numbers, debugging,
> > a
> > > resizable window and fixed width font, etc., but I don't have time for
> > that
> > > now, and to be fair, the BeanShell editor isn't much better.
> >
> > When we click button "Save" of the new Python editing dialog, the code
> > is saved, but apparently is not ``active'' yet.
> >
> > In other words, the ``old'' Python source code is still executed
> > whenever we ask to ``run'' a macro.
> >
> > In order to run the new code, we have to close and reopen the
> > _document_.
> >
>
> Thank you for testing. You're right, there was a bug there. I think it's
> fixed now:
>
> Forget Python modules from the cache after they are saved, so they
> get reloaded in the future. This is necessary as getModuleByUrl()'s
> self.sfa.getDateTimeModified() returns timestamps with all zeroes
> for documents (== ZIP files), breaking the test for whether the
> embedded Python file has been changed. Also even if it worked, the
> minimum granularity for timestamps in ZIP files is 2 seconds, which
> isn't good enough.
Now, the "Save" button does not seem to have any effect.
If I make some edits to the Python macros, then "Close" the macro
editing window, and then I open it again (Tools -> Macros -> Organize
macros -> Python -> file.odt -> Library1 -> Macro1, Edit) I find the
previous contents, with my changes lost.
I hope this helps.
Best regards,
--
Arrigo
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org
Re: Progress in Python script editing and embedding
Posted by Damjan Jovanovic <da...@apache.org>.
On Mon, Apr 27, 2026 at 9:39 PM Arrigo Marchiori <ar...@apache.org> wrote:
> Hello Damjan, All,
>
> this is great!
>
Thank you.
>
> I've played a bit with Python macros and I think I found a small bug.
>
> On Sun, Apr 26, 2026 at 08:36:07PM +0200, Damjan Jovanovic wrote:
>
> [...]
>
> > Most of all, Python scripts can now be edited :-), in a custom little
> > dialog window with "Run", "Save" and "Close" buttons. It all works, they
> > run, they are successfully saved into the document, and can be re-opened.
> > The editing could still be improved a lot, with line numbers, debugging,
> a
> > resizable window and fixed width font, etc., but I don't have time for
> that
> > now, and to be fair, the BeanShell editor isn't much better.
>
> When we click button "Save" of the new Python editing dialog, the code
> is saved, but apparently is not ``active'' yet.
>
> In other words, the ``old'' Python source code is still executed
> whenever we ask to ``run'' a macro.
>
> In order to run the new code, we have to close and reopen the
> _document_.
>
Thank you for testing. You're right, there was a bug there. I think it's
fixed now:
Forget Python modules from the cache after they are saved, so they
get reloaded in the future. This is necessary as getModuleByUrl()'s
self.sfa.getDateTimeModified() returns timestamps with all zeroes
for documents (== ZIP files), breaking the test for whether the
embedded Python file has been changed. Also even if it worked, the
minimum granularity for timestamps in ZIP files is 2 seconds, which
isn't good enough.
Regards
Damjan
Re: Progress in Python script editing and embedding
Posted by Arrigo Marchiori <ar...@apache.org>.
Hello Damjan, All,
this is great!
I've played a bit with Python macros and I think I found a small bug.
On Sun, Apr 26, 2026 at 08:36:07PM +0200, Damjan Jovanovic wrote:
[...]
> Most of all, Python scripts can now be edited :-), in a custom little
> dialog window with "Run", "Save" and "Close" buttons. It all works, they
> run, they are successfully saved into the document, and can be re-opened.
> The editing could still be improved a lot, with line numbers, debugging, a
> resizable window and fixed width font, etc., but I don't have time for that
> now, and to be fair, the BeanShell editor isn't much better.
When we click button "Save" of the new Python editing dialog, the code
is saved, but apparently is not ``active'' yet.
In other words, the ``old'' Python source code is still executed
whenever we ask to ``run'' a macro.
In order to run the new code, we have to close and reopen the
_document_.
> All my changes have been pushed to the python-editing-embedding branch.
> Please test. I'll merge it in a few days if there are no objections.
--
Arrigo
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org
Re: Progress in Python script editing and embedding
Posted by Damjan Jovanovic <da...@apache.org>.
On Sat, Apr 25, 2026 at 5:32 PM Damjan Jovanovic <da...@apache.org> wrote:
>
>
> After some cleanups, and a way to edit Python macros, that branch should
> be ready to merge :-).
>
>
I've now also fixed a bug where the file and script nodes were getting
greyed out buttons when the library gets renamed, because after renaming
their URI (relative to their parent library) becomes invalid. In Java they
fixed that by calling updateURI() on each child during rename, but in
Python I took a different approach: the child stores a reference to the
parent instead of the URI, and dynamically derives the URI using a uri()
method, which looks up the parent's URI and concates the child's name, so
the child always has the correct URI when the parent is renamed.
Otherwise, cleanups and better parameter verification, and also
found PackageBrowseNode also needed to implement XPropertySet and
XInvocation interfaces, without which the macro selection dialog breaks
when UNO packages with Python scripts are added.
Most of all, Python scripts can now be edited :-), in a custom little
dialog window with "Run", "Save" and "Close" buttons. It all works, they
run, they are successfully saved into the document, and can be re-opened.
The editing could still be improved a lot, with line numbers, debugging, a
resizable window and fixed width font, etc., but I don't have time for that
now, and to be fair, the BeanShell editor isn't much better.
All my changes have been pushed to the python-editing-embedding branch.
Please test. I'll merge it in a few days if there are no objections.
Regards
Damjan
Re: Progress in Python script editing and embedding
Posted by Pe...@apache.org.
Am 25.04.2026 um 18:10 schrieb Pedro Lino via dev:
> Hi Damjan
>
> Excellent news!
+1
>
> If I understood correctly all these changes are included in a Python script file so this fix can be merged to trunk and cherry picked to both branch 41X and 42X?
>
> Best,
> Pedro
>
>> On 04/25/2026 4:32 PM WEST Damjan Jovanovic <da...@apache.org> wrote:
>>
>>
>> On Fri, Apr 24, 2026 at 6:03 AM Damjan Jovanovic <da...@apache.org> wrote:
>>
>>> A number of issues however were discovered:
>>> - All macro operations (creating, renaming, deleting) give false errors
>>> saying they failed, but actually succeed, you need to close and re-open the
>>> macro dialog to see the changes. I suspect this is a bug in the Python UNO
>>> bridge.
>>> - Creating libraries inside documents is completely broken on Windows, the
>>> UI buttons stay greyed out. This is some kind of a permission issue when
>>> calling isReadOnly() on the SimpleFileAccess interface for the document.
>>>
>> This is fully fixed now. All library and macro operations (creating,
>> renaming, deleting) fully work everywhere, including on Windows.
>>
>> The problem with the false error has that an UNO IDL function with this
>> definition:
>> (
>> https://www.openoffice.org/api/docs/common/ref/com/sun/star/script/XInvocation.html#invoke
>> )
>> any
>> *invoke*( [in] string aFunctionName,
>>
>> [in] sequence< any > aParams,
>>
>> [out] sequence< short > aOutParamIndex,
>>
>> [out] sequence< any > aOutParam )
>> normally compiles into a programming language function taking 4 parameters
>> and returning the "any".
>> But on Python, the "[out]" parameters are passed as None, and need to be
>> returned as a tuple, so the Python function:
>>
>> def invoke( self, name, params, outparamindex, outparams ):
>>
>> needs to return a tuple of 3 values: the "any" return value, the
>> aOutParamIndex, and the aOutParam. This wasn't being done, either
>> previously in that code, or with the new invoke() methods I added. When I
>> added it in, the error disappeared.
>>
>> (That gotcha is documented
>> on https://www.openoffice.org/udk/python/python-bridge.html)
>>
>> As for isReadOnly() on the SimpleFileAccess interface failing, I changed it
>> to only run on the child nodes of the root node, and always allow the root
>> node to create, like is done by the "user" and "share" sources as well.
>>
>> My changes have been pushed to the python-editing-embedding branch.
>>
>> After some cleanups, and a way to edit Python macros, that branch should be
>> ready to merge :-).
>>
>> Regards
>> Damjan
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
> For additional commands, e-mail: dev-help@openoffice.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org
Re: Progress in Python script editing and embedding
Posted by Damjan Jovanovic <da...@apache.org>.
On Sat, Apr 25, 2026 at 6:10 PM Pedro Lino via dev <
dev@openoffice.apache.org> wrote:
> Hi Damjan
>
> Excellent news!
>
Thank you.
>
> If I understood correctly all these changes are included in a Python
> script file so this fix can be merged to trunk and cherry picked to both
> branch 41X and 42X?
>
Yes that will be possible.
>
> Best,
> Pedro
>
>
Regards
Damjan
Re: Progress in Python script editing and embedding
Posted by Pedro Lino via dev <de...@openoffice.apache.org>.
Hi Damjan
Excellent news!
If I understood correctly all these changes are included in a Python script file so this fix can be merged to trunk and cherry picked to both branch 41X and 42X?
Best,
Pedro
> On 04/25/2026 4:32 PM WEST Damjan Jovanovic <da...@apache.org> wrote:
>
>
> On Fri, Apr 24, 2026 at 6:03 AM Damjan Jovanovic <da...@apache.org> wrote:
>
> >
> > A number of issues however were discovered:
> > - All macro operations (creating, renaming, deleting) give false errors
> > saying they failed, but actually succeed, you need to close and re-open the
> > macro dialog to see the changes. I suspect this is a bug in the Python UNO
> > bridge.
> > - Creating libraries inside documents is completely broken on Windows, the
> > UI buttons stay greyed out. This is some kind of a permission issue when
> > calling isReadOnly() on the SimpleFileAccess interface for the document.
> >
>
> This is fully fixed now. All library and macro operations (creating,
> renaming, deleting) fully work everywhere, including on Windows.
>
> The problem with the false error has that an UNO IDL function with this
> definition:
> (
> https://www.openoffice.org/api/docs/common/ref/com/sun/star/script/XInvocation.html#invoke
> )
> any
> *invoke*( [in] string aFunctionName,
>
> [in] sequence< any > aParams,
>
> [out] sequence< short > aOutParamIndex,
>
> [out] sequence< any > aOutParam )
> normally compiles into a programming language function taking 4 parameters
> and returning the "any".
> But on Python, the "[out]" parameters are passed as None, and need to be
> returned as a tuple, so the Python function:
>
> def invoke( self, name, params, outparamindex, outparams ):
>
> needs to return a tuple of 3 values: the "any" return value, the
> aOutParamIndex, and the aOutParam. This wasn't being done, either
> previously in that code, or with the new invoke() methods I added. When I
> added it in, the error disappeared.
>
> (That gotcha is documented
> on https://www.openoffice.org/udk/python/python-bridge.html)
>
> As for isReadOnly() on the SimpleFileAccess interface failing, I changed it
> to only run on the child nodes of the root node, and always allow the root
> node to create, like is done by the "user" and "share" sources as well.
>
> My changes have been pushed to the python-editing-embedding branch.
>
> After some cleanups, and a way to edit Python macros, that branch should be
> ready to merge :-).
>
> Regards
> Damjan
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@openoffice.apache.org
For additional commands, e-mail: dev-help@openoffice.apache.org
Re: Progress in Python script editing and embedding
Posted by Damjan Jovanovic <da...@apache.org>.
On Fri, Apr 24, 2026 at 6:03 AM Damjan Jovanovic <da...@apache.org> wrote:
>
> A number of issues however were discovered:
> - All macro operations (creating, renaming, deleting) give false errors
> saying they failed, but actually succeed, you need to close and re-open the
> macro dialog to see the changes. I suspect this is a bug in the Python UNO
> bridge.
> - Creating libraries inside documents is completely broken on Windows, the
> UI buttons stay greyed out. This is some kind of a permission issue when
> calling isReadOnly() on the SimpleFileAccess interface for the document.
>
This is fully fixed now. All library and macro operations (creating,
renaming, deleting) fully work everywhere, including on Windows.
The problem with the false error has that an UNO IDL function with this
definition:
(
https://www.openoffice.org/api/docs/common/ref/com/sun/star/script/XInvocation.html#invoke
)
any
*invoke*( [in] string aFunctionName,
[in] sequence< any > aParams,
[out] sequence< short > aOutParamIndex,
[out] sequence< any > aOutParam )
normally compiles into a programming language function taking 4 parameters
and returning the "any".
But on Python, the "[out]" parameters are passed as None, and need to be
returned as a tuple, so the Python function:
def invoke( self, name, params, outparamindex, outparams ):
needs to return a tuple of 3 values: the "any" return value, the
aOutParamIndex, and the aOutParam. This wasn't being done, either
previously in that code, or with the new invoke() methods I added. When I
added it in, the error disappeared.
(That gotcha is documented
on https://www.openoffice.org/udk/python/python-bridge.html)
As for isReadOnly() on the SimpleFileAccess interface failing, I changed it
to only run on the child nodes of the root node, and always allow the root
node to create, like is done by the "user" and "share" sources as well.
My changes have been pushed to the python-editing-embedding branch.
After some cleanups, and a way to edit Python macros, that branch should be
ready to merge :-).
Regards
Damjan