I've found a solution which may be a bit radical, but it works, and also provides an opportunity to discuss some issues with Python in version 4 which I was looking at yesterday.
What we're doing here is sending our changes to the sheet through a socket connection.
In the python scripts folder we want SlowDown.py
- Code: Select all Expand viewCollapse view
import subprocess
def SlowDown(*dummy):
subprocess.Popen(["C:\\Program Files\\OpenOffice 4\\program\\python-core-2.7.5\\bin\\python.exe","C:\\Documents and Settings\\Charlie\\Application Data\\OpenOffice\\4\\user\\Scripts\\python\\SlowItDown.py"],creationflags=0x08000000,shell = False)
g_exportedScripts = SlowDown,
The purpose of the Windows specific
- Code: Select all Expand viewCollapse view
creationflags=0x08000000
is to suppress the creation of a pop-up window for the process.
The important thing to notice here is that python is being started, not directly from the program folder, but from
- Code: Select all Expand viewCollapse view
C:\Program Files\OpenOffice 4\program\python-core-2.7.5\bin\
Now, I found that when starting from this folder that the uno modules weren't found. One solution I found (maybe there's something easier), is to set the environment variable PYTHONPATH
- Code: Select all Expand viewCollapse view
PYTHONPATH=C:\Program Files\OpenOffice 4\program\
I just configured my system to startup with this. Other folders can be added in the usual fashion by separating them with semicolons.
So, slowdown launches SlowIItDown.py, which above is also in the scripts folder, but could be put elsewhere. It contains myTest3 in a modified form.
- Code: Select all Expand viewCollapse view
import socket # only needed on win32-OOo3.0.0
import uno
import unohelper
import time
import subprocess
def myTest3(desktop,DelayTime):
oDoc = desktop.getCurrentComponent()
oSheets = oDoc.getSheets()
mySheet = oSheets.getByName("Sheet1")
mySheet.getColumns().removeByIndex(0,1)
for i in range(0,5):
oCell = mySheet.getCellByPosition(0,i)
oCell.setValue(i)
time.sleep(DelayTime)
subprocess.Popen(["soffice","-invisible","-accept=socket,host=localhost,port=2083;urp;StarOffice.ServiceManager"],creationflags=0x08000000,shell = False)
time.sleep(2)
# get the uno component context from the PyUNO runtime
localContext = uno.getComponentContext()
# create the UnoUrlResolver
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext )
# connect to the running office
ctx = resolver.resolve( "uno:socket,host=localhost,port=2083;urp;StarOffice.ComponentContext" )
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
myTest3(desktop,1)