[Libreoffice-commits] core.git: wizards/source
Jean-Pierre Ledure (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jul 2 08:50:43 UTC 2021
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 <jp at ledure.be>
AuthorDate: Thu Jul 1 15:14:28 2021 +0200
Commit: Jean-Pierre Ledure <jp at 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 <jp at ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp at 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 ' ScriptForge.SF_Exception.Properties
+REM -----------------------------------------------------------------------------
+Public Sub PythonPrint(ParamArray pvArgs() As Variant)
+''' Display the list of arguments in a readable form in the Python console
+''' Arguments are separated by a TAB character (simulated by spaces)
+''' The maximum length of each individual argument = 1024 characters
+''' Args:
+''' Any number of arguments of any type
+''' Examples:
+''' SF_Exception.PythonPrint(a, Array(1, 2, 3), , "line1" & Chr(10) & "Line2", DateSerial(2020, 04, 09))
+
+Dim sOutput As String ' Line to write in console
+Dim sArg As String ' Single argument
+Dim i As Integer
+Const cstTab = 4
+Const cstMaxLength = 1024
+Const cstPyHelper = "$" & "_SF_Exception__PythonPrint"
+Const cstThisSub = "Exception.PythonPrint"
+Const cstSubArgs = "Arg0, [Arg1, ...]"
+
+ If SF_Utils._ErrorHandling() Then On Local Error Goto Finally ' Never interrupt processing
+ SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
+Try:
+ ' Build new console line
+ sOutput = ""
+ For i = 0 To UBound(pvArgs)
+ If IsError(pvArgs(i)) Then pvArgs(i) = ""
+ sArg = Iif(i = 0, "", SF_String.sfTAB) & SF_Utils._Repr(pvArgs(i), cstMaxLength)
+ sOutput = sOutput & sArg
+ Next i
+
+ ' Add to actual console
+ sOutput = SF_String.ExpandTabs(sOutput, cstTab)
+ _SF_._AddToConsole(sOutput)
+ ' Display the message in the Python shell console
+ With ScriptForge.SF_Session
+ .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper & cstPyHelper, sOutput)
+ End With
+
+Finally:
+ SF_Utils._ExitFunction(cstThisSub)
+ Exit Sub
+End Sub ' 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
# #################################################################
More information about the Libreoffice-commits
mailing list