Hi,
I’m trying to write a macro in python that opens a scanner application and waits for the scanner to produce an image at a specific location in the file system.
This is to replace a similar macro I wrote once in basic, but the python environment is more suitable for integration in this case.
For the basic macro the scanner application was invoked using the “Shell” command. That command would wait for the scanner application to finish and then continue the macro script for further post-processing.
To to something similar in python I tried to use “subprocess.run” instead of basic’s “Shell”. It also waits for the command to complete before it continues.
However when the python macro is executed it seems to block all mouse events until the macro has completely finished. That means the scanner application opens, but I can’t click anything. Not in the scanner interface and even anywhere on screen. The computer stops responding completely to mouse clicks. On the other hand keyboard input is still possible. I can even switch windows using the proper modifier keys. This is however not a reasonable solution.
Next I also tried using libreoffice’s “SystemShellExecute.execute” instead of “subprocess.run”. That command however is asynchronous so it continues the macro code right after the scanner application is launched, not after it has finished. So I added a loop after it to wait for the scanner application to finish. But then again mouse events get ignored.
It seems the issue is not really with the external command being executed. If I replace that part with a simple “time.sleep(10)”, mouse events are ignored for the next 10 seconds.
Is there any way I can have normal mouse events while waiting for a subprocess to finish when running a python macro ?
Some extra details that may be helpful:
- The document I’m creating the macro for is a libreoffice Writer document
- The macro is executed when selecting an embedded image element, but the same happens if I add a form with a button and set the macro to fire when the button is clicked
- LibreOffice version 6.4.7.2 on Fedora 32