summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wizards/source/scriptforge/SF_Exception.xba43
-rw-r--r--wizards/source/scriptforge/python/ScriptForgeHelper.py14
2 files changed, 57 insertions, 0 deletions
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
@@ -546,6 +546,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 _
, Optional ByVal Description 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
@@ -85,6 +85,20 @@ def _SF_Dictionary__ImportFromJson(jsonstr: str): # used by Dictionary.ImportFr
# #################################################################
+# 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
# #################################################################