A questioneer takes measurement data from a serialport. The aim is to insert the value in consequetive calc sheet rows, together with a timestamp. Upon elaborating this further I used the code below, the observed behaviour is
- testSleep results in an idle LibO interface, showing all time values after five seconds, when for-loop execution is finished. Not very desirable in case you want to observe a logging of actual data
- testWait results in an active LibO interface, updating the next row every second.
This might also play a role in this post mouse events blocked and this listener closes ‘endless’ loop
I also observed this behaviour when moving the rowpointer in a one-to-many SubForm_Grid. A sleep command was not succesful to spare the interface some time to keep up with the program execution, the invoke basic wait did the trick.
The idleness of the interface is a bit counter intuitive. Is there an explanation, can it be made intuitive without this workaround?
LinuxMint 20 LO 6.4.7.2
import datetime
import time
def testSleep():
sheet = XSCRIPTCONTEXT.getDocument().getSheets().getByIndex(0)
for i in range(5):
dat = datetime.datetime.now().strftime("%Y-%m-%d %H-%M-%S")
cell = sheet.getCellByPosition(2,i)
time.sleep(1)
cell.setString(dat)
def testWait():
sheet = XSCRIPTCONTEXT.getDocument().getSheets().getByIndex(0)
oDoc = getBasicScript("waitPython")
for i in range(5):
dat = datetime.datetime.now().strftime("%Y-%m-%d %H-%M-%S")
cell = sheet.getCellByPosition(2,i) # = C1
oDoc.invoke((), (), ())
cell.setString(dat)
def getBasicScript(macro='Main', module='Module1', library='Standard',
isEmbedded=False) ->XScript:
if isEmbedded:
desktop = smgr.createInstanceWithContext('com.sun.star.frame.Desktop', ctx)
scriptPro = desktop.CurrentComponent.getScriptProvider()
location = "document"
else:
mspf = smgr.createInstanceWithContext(
"com.sun.star.script.provider.MasterScriptProviderFactory", ctx)
scriptPro = mspf.createScriptProvider("")
location = "application"
scriptName = "vnd.sun.star.script:"+library+"."+module+"."+macro+ \
"?language=Basic&location="+location
xScript = scriptPro.getScript(scriptName)
return xScript
# the BASIC routine is a simple
# sub waitPython()
# wait(1000)
#End Sub