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 <[email protected]> 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 <[email protected]> > 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 <[email protected]> >> 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: [email protected] >> For additional commands, e-mail: [email protected] >> >>
