wizards/source/scriptforge/SF_PythonHelper.xba    |   35 +++++++++++++++++++++-
 wizards/source/scriptforge/python/scriptforge.py  |    4 ++
 wizards/source/scriptforge/python/scriptforge.pyi |   10 ++++++
 wizards/source/scriptforge/script.xlb             |   14 ++++----
 4 files changed, 55 insertions(+), 8 deletions(-)

New commits:
commit 92494fbbec5c95130d58cf8ecf76210a1e243c7f
Author:     Jean-Pierre Ledure <j...@ledure.be>
AuthorDate: Sat May 10 14:53:00 2025 +0200
Commit:     Jean-Pierre Ledure <j...@ledure.be>
CommitDate: Sat May 10 16:07:43 2025 +0200

    ScriptForge (Basic) new Wait() method
    
    Constructions (Python) like
        import time
        while some_event is False:
            time.sleep(1)
    watching for some_event becoming True
    have the drawback to freeze the LibreOffice
    user interface.
    
    While next (Basic) snippet
        Do While Not some_event
            Wait(1000)
    does not.
    
    The Python example prevents for waiting for events
    that require user input,f.i. entering a value
    in a cell.
    
    The here proposed alternative is (Python):
        basic = CreateScriptService('Basic')
        while some_event is False:
            basic.Wait(1000)
    This works smoothly.
    The Wait() method executes in the background
    a Basic Wait statement.
    
    This impacts only Python user scripts.
    The change requires an update of the user
    documentation.
    
    Change-Id: Idb73907a5e27cf288310e306fb41c0aba9c8a388
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185137
    Tested-by: Jenkins
    Reviewed-by: Jean-Pierre Ledure <j...@ledure.be>

diff --git a/wizards/source/scriptforge/SF_PythonHelper.xba 
b/wizards/source/scriptforge/SF_PythonHelper.xba
index beb0d16f1306..2b3a3c820d9e 100644
--- a/wizards/source/scriptforge/SF_PythonHelper.xba
+++ b/wizards/source/scriptforge/SF_PythonHelper.xba
@@ -446,7 +446,7 @@ Public Function PyGlobalScope(ByVal Library As Variant) As 
Object
 &apos;&apos;&apos;     Returns:
 &apos;&apos;&apos;             The GlobalScope value
 &apos;&apos;&apos;     Example: (Python code)
-&apos;&apos;&apos;         MsgBox bas.GlobalScope.BasicLibraries()
+&apos;&apos;&apos;         bas.Xray(bas.GlobalScope.BasicLibraries())
 
 Const cstThisSub = &quot;Basic.GlobalScope.BasicLibraries&quot;        &apos;  
or DialogLibraries
 Const cstSubArgs = &quot;&quot;
@@ -551,6 +551,39 @@ Catch:
        GoTo Finally
 End Function   &apos;  ScriptForge.SF_PythonHelper.PyMsgBox
 
+REM 
-----------------------------------------------------------------------------
+Public Sub PyWait(ByVal Millisec As Variant)
+&apos;&apos;&apos;     Convenient function to replicate Wait() in Python 
scripts
+&apos;&apos;&apos;     This method is normally not necessary. But 
constructions like:
+&apos;&apos;&apos;             import time
+&apos;&apos;&apos;             while True:
+&apos;&apos;&apos;                     time.sleep(1)
+&apos;&apos;&apos;     have the drawback to often freeze the LibreOffice user 
interface.
+&apos;&apos;&apos;             basic = CreateScriptService(&apos;Basic&apos;)
+&apos;&apos;&apos;             white True:
+&apos;&apos;&apos;                     basic.Wait(1000)
+&apos;&apos;&apos;     might be a good alternative, although less precise due 
to the Python/Basic exchnages.
+&apos;&apos;&apos;     Args:
+&apos;&apos;&apos;             Millisec: the amount of time (in milliseconds) 
to wait before the program is continued
+
+Const cstThisSub = &quot;Basic.Wait&quot;
+Const cstSubArgs = &quot;millisec&quot;
+
+       If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
+
+Check:
+       SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
+
+Try:
+       Wait Millisec
+
+Finally:
+       SF_Utils._ExitFunction(cstThisSub)
+       Exit Sub
+Catch:
+       GoTo Finally
+End Sub        &apos;  ScriptForge.SF_PythonHelper.PyWait
+
 REM ============================================================= PRIVATE 
METHODS
 
 REM 
-----------------------------------------------------------------------------
diff --git a/wizards/source/scriptforge/python/scriptforge.py 
b/wizards/source/scriptforge/python/scriptforge.py
index ba710a2d4354..dc6a8cfbe7ca 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -960,6 +960,10 @@ class SFScriptForge:
 
         thisDatabaseDocument, thisdatabasedocument = ThisDatabaseDocument, 
ThisDatabaseDocument
 
+        @classmethod
+        def Wait(cls, millisec):
+            return cls.SIMPLEEXEC(cls.module + '.PyWait', millisec)
+
         @classmethod
         def Xray(cls, unoobject = None):
             return cls.SIMPLEEXEC('XrayTool._main.xray', unoobject)
diff --git a/wizards/source/scriptforge/python/scriptforge.pyi 
b/wizards/source/scriptforge/python/scriptforge.pyi
index d399f98e5b18..637422ecce57 100644
--- a/wizards/source/scriptforge/python/scriptforge.pyi
+++ b/wizards/source/scriptforge/python/scriptforge.pyi
@@ -673,6 +673,16 @@ class SFScriptForge:
                 """
             ...
 
+        @classmethod
+        def Wait(cls, millisec: Union[int, float]) -> None:
+            """
+                Interrupts the program execution for the amount of time that 
you specify in milliseconds.
+                The method is an alternative to ``time.sleep()`` that 
sometimes freezes the LibreOffice
+                user interface.
+                    Args
+                        ``millisec``: The amount of time (in milliseconds) to 
wait before the program is continued.
+                """
+            ...
 
         @classmethod
         def Xray(cls, unoobject: UNO) -> None:
diff --git a/wizards/source/scriptforge/script.xlb 
b/wizards/source/scriptforge/script.xlb
index 3318b6c54a1c..af8f6a75dc96 100644
--- a/wizards/source/scriptforge/script.xlb
+++ b/wizards/source/scriptforge/script.xlb
@@ -1,6 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 
1.0//EN" "library.dtd">
 <library:library xmlns:library="http://openoffice.org/2000/library"; 
library:name="ScriptForge" library:readonly="false" 
library:passwordprotected="false">
+ <library:element library:name="_CodingConventions"/>
+ <library:element library:name="_ModuleModel"/>
+ <library:element library:name="SF_String"/>
+ <library:element library:name="__License"/>
+ <library:element library:name="SF_Root"/>
+ <library:element library:name="SF_TextStream"/>
  <library:element library:name="SF_Utils"/>
  <library:element library:name="SF_Platform"/>
  <library:element library:name="SF_PythonHelper"/>
@@ -12,12 +18,6 @@
  <library:element library:name="SF_Session"/>
  <library:element library:name="SF_Exception"/>
  <library:element library:name="SF_Dictionary"/>
- <library:element library:name="SF_Timer"/>
  <library:element library:name="SF_FileSystem"/>
- <library:element library:name="SF_TextStream"/>
- <library:element library:name="SF_Root"/>
- <library:element library:name="__License"/>
- <library:element library:name="SF_String"/>
- <library:element library:name="_ModuleModel"/>
- <library:element library:name="_CodingConventions"/>
+ <library:element library:name="SF_Timer"/>
 </library:library>
\ No newline at end of file

Reply via email to