wizards/source/scriptforge/SF_Exception.xba            |   43 +++++++++++++++++
 wizards/source/scriptforge/python/ScriptForgeHelper.py |   14 +++++
 2 files changed, 57 insertions(+)

New commits:
commit adc0c34bcf5ccf49faf3be54fc505a4ec192fa67
Author:     Jean-Pierre Ledure <j...@ledure.be>
AuthorDate: Thu Jul 1 15:14:28 2021 +0200
Commit:     Jean-Pierre Ledure <j...@ledure.be>
CommitDate: Fri Jul 2 10:50:09 2021 +0200

    ScriptForge - (SF_Exception) new PythonPrint() method
    
    Send from BASIC the arguments of the method to the
    Python shell (APSO) console.
    The same string is added to the ScriptForge debug console.
    
    From PYTHON use simply the builtin print() statement instead.
    
    Change-Id: Iac175b2f7c5773e0369361c3f26bbc33485848db
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118225
    Tested-by: Jean-Pierre Ledure <j...@ledure.be>
    Tested-by: Jenkins
    Reviewed-by: Jean-Pierre Ledure <j...@ledure.be>

diff --git a/wizards/source/scriptforge/SF_Exception.xba 
b/wizards/source/scriptforge/SF_Exception.xba
index fd108e14f9ac..aa654de67463 100644
--- a/wizards/source/scriptforge/SF_Exception.xba
+++ b/wizards/source/scriptforge/SF_Exception.xba
@@ -545,6 +545,49 @@ Public Function Properties() As Variant
 
 End Function   &apos;  ScriptForge.SF_Exception.Properties
 
+REM 
-----------------------------------------------------------------------------
+Public Sub PythonPrint(ParamArray pvArgs() As Variant)
+&apos;&apos;&apos;     Display the list of arguments in a readable form in the 
Python console
+&apos;&apos;&apos;     Arguments are separated by a TAB character (simulated 
by spaces)
+&apos;&apos;&apos;     The maximum length of each individual argument = 1024 
characters
+&apos;&apos;&apos;     Args:
+&apos;&apos;&apos;             Any number of arguments of any type
+&apos;&apos;&apos;     Examples:
+&apos;&apos;&apos;             SF_Exception.PythonPrint(a, Array(1, 2, 3), , 
&quot;line1&quot; &amp; Chr(10) &amp; &quot;Line2&quot;, DateSerial(2020, 04, 
09))
+
+Dim sOutput As String          &apos;  Line to write in console
+Dim sArg As String                     &apos;  Single argument
+Dim i As Integer
+Const cstTab = 4
+Const cstMaxLength = 1024
+Const cstPyHelper = &quot;$&quot; &amp; &quot;_SF_Exception__PythonPrint&quot;
+Const cstThisSub = &quot;Exception.PythonPrint&quot;
+Const cstSubArgs = &quot;Arg0, [Arg1, ...]&quot;
+
+       If SF_Utils._ErrorHandling() Then On Local Error Goto Finally   &apos;  
Never interrupt processing
+       SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
+Try:
+       &apos;  Build new console line
+       sOutput = &quot;&quot;
+       For i = 0 To UBound(pvArgs)
+               If IsError(pvArgs(i)) Then pvArgs(i) = &quot;&quot;
+               sArg = Iif(i = 0, &quot;&quot;, SF_String.sfTAB) &amp; 
SF_Utils._Repr(pvArgs(i), cstMaxLength)
+               sOutput = sOutput &amp; sArg
+       Next i
+       
+       &apos;  Add to actual console
+       sOutput = SF_String.ExpandTabs(sOutput, cstTab)
+       _SF_._AddToConsole(sOutput)
+       &apos;  Display the message in the Python shell console
+       With ScriptForge.SF_Session
+               .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper &amp; 
cstPyHelper, sOutput)
+       End With
+       
+Finally:
+       SF_Utils._ExitFunction(cstThisSub)
+       Exit Sub
+End Sub                        &apos;  ScriptForge.SF_Exception.PythonPrint
+
 REM 
-----------------------------------------------------------------------------
 Public Sub Raise(Optional ByVal Number As Variant _
                                                                , Optional 
ByVal Source As Variant _
diff --git a/wizards/source/scriptforge/python/ScriptForgeHelper.py 
b/wizards/source/scriptforge/python/ScriptForgeHelper.py
index 12fbaa337ebe..19a6cbe63b48 100644
--- a/wizards/source/scriptforge/python/ScriptForgeHelper.py
+++ b/wizards/source/scriptforge/python/ScriptForgeHelper.py
@@ -84,6 +84,20 @@ def _SF_Dictionary__ImportFromJson(jsonstr: str):  # used by 
Dictionary.ImportFr
     return result
 
 
+# #################################################################
+# Exception service
+# #################################################################
+
+def _SF_Exception__PythonPrint(string: str) -> bool:
+    # used by SF_Exception.PythonPrint() Basic method
+    """
+    Write the argument to stdout.
+    If the APSO shell console is active, the argument will be displayed in the 
console window
+    """
+    print(string)
+    return True
+
+
 # #################################################################
 # FileSystem service
 # #################################################################
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to