summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
Diffstat (limited to 'wizards')
-rw-r--r--wizards/source/scriptforge/SF_Exception.xba44
-rw-r--r--wizards/source/scriptforge/SF_PythonHelper.xba8
-rw-r--r--wizards/source/scriptforge/SF_Root.xba2
-rw-r--r--wizards/source/scriptforge/python/scriptforge.py57
4 files changed, 105 insertions, 6 deletions
diff --git a/wizards/source/scriptforge/SF_Exception.xba b/wizards/source/scriptforge/SF_Exception.xba
index 18d562b21e7b..ba9ce109ecc8 100644
--- a/wizards/source/scriptforge/SF_Exception.xba
+++ b/wizards/source/scriptforge/SF_Exception.xba
@@ -392,6 +392,49 @@ Catch:
End Function ' ScriptForge.SF_Exception.ConsoleToFile
REM -----------------------------------------------------------------------------
+Public Sub DebugDisplay(ParamArray pvArgs() As Variant)
+''' Display the list of arguments in a readable form in a message box
+''' Arguments are separated by a LINEFEED character
+''' The maximum length of each individual argument = 1024 characters
+''' Args:
+''' Any number of arguments of any type
+''' Examples:
+''' SF_Exception.DebugDisplay(a, Array(1, 2, 3), , "line1" & Chr(10) & "Line2", DateSerial(2020, 04, 09))
+
+Dim sOutputMsg As String ' Line to display
+Dim sOutputCon As String ' Line to write in console
+Dim sArgMsg As String ' Single argument
+Dim sArgCon As String ' Single argument
+Dim i As Integer
+Const cstTab = 4
+Const cstMaxLength = 1024
+Const cstThisSub = "Exception.DebugDisplay"
+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
+ sOutputMsg = "" : sOutputCon = ""
+ For i = 0 To UBound(pvArgs)
+ If IsError(pvArgs(i)) Then pvArgs(i) = ""
+ sArgMsg = Iif(i = 0, "", SF_String.sfNEWLINE) & SF_Utils._Repr(pvArgs(i), cstMaxLength) 'Do not use SF_String.Represent()
+ sArgCon = Iif(i = 0, "", SF_String.sfTAB) & SF_Utils._Repr(pvArgs(i), cstMaxLength)
+ sOutputMsg = sOutputMsg & sArgMsg
+ sOutputCon = sOutputCon & sArgCon
+ Next i
+
+ ' Add to actual console
+ _SF_._AddToConsole(SF_String.ExpandTabs(sOutputCon, cstTab))
+ ' Display the message
+ MsgBox(sOutputMsg, MB_OK + MB_ICONINFORMATION, "DebugDisplay")
+
+Finally:
+ SF_Utils._ExitFunction(cstThisSub)
+ Exit Sub
+End Sub ' ScriptForge.SF_Exception.DebugDisplay
+
+REM -----------------------------------------------------------------------------
Public Sub DebugPrint(ParamArray pvArgs() As Variant)
''' Print the list of arguments in a readable form in the console
''' Arguments are separated by a TAB character (simulated by spaces)
@@ -403,7 +446,6 @@ Public Sub DebugPrint(ParamArray pvArgs() As Variant)
Dim sOutput As String ' Line to write in console
Dim sArg As String ' Single argument
-Dim sMainSub As String ' Temporary storage for main function
Dim i As Integer
Const cstTab = 4
Const cstMaxLength = 1024
diff --git a/wizards/source/scriptforge/SF_PythonHelper.xba b/wizards/source/scriptforge/SF_PythonHelper.xba
index c54d799ae282..38aaa0e4681b 100644
--- a/wizards/source/scriptforge/SF_PythonHelper.xba
+++ b/wizards/source/scriptforge/SF_PythonHelper.xba
@@ -481,21 +481,21 @@ Public Function PyMsgBox(ByVal Text As Variant _
''' Example: (Python code)
''' a = bas.MsgBox ('Please press a button:', bas.MB_EXCLAMATION, 'Dear User')
-Dim sMsg As String ' Return value
+Dim iMsg As Integer ' Return value
Const cstThisSub = "Basic.MsgBox"
Const cstSubArgs = "text, [dialogtype=0], [dialogtitle]"
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
- sMsg = ""
+ iMsg = -1
Check:
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
Try:
- sMsg = MsgBox(Text, DialogType, DialogTitle)
+ iMsg = MsgBox(Text, DialogType, DialogTitle)
Finally:
- PyMsgBox = sMsg
+ PyMsgBox = iMsg
SF_Utils._ExitFunction(cstThisSub)
Exit Function
Catch:
diff --git a/wizards/source/scriptforge/SF_Root.xba b/wizards/source/scriptforge/SF_Root.xba
index fcbba9039596..7ba27eb3c4ec 100644
--- a/wizards/source/scriptforge/SF_Root.xba
+++ b/wizards/source/scriptforge/SF_Root.xba
@@ -160,7 +160,7 @@ Dim sLine As String ' Alias of psLine
' Add a timestamp to the line and insert it (without date)
sLine = Mid(SF_Utils._Repr(Now()), 12) & " -> " & psLine
- ConsoleLines(lConsole + 1) = Mid(SF_Utils._Repr(Now()), 12) & " -> " & psLine
+ ConsoleLines(lConsole + 1) = sLine
' Add the new line to the actual (probably non-modal) console, if active
If Not IsNull(ConsoleDialog) Then
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py
index 9baabf42b0bf..86e35167b83b 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -751,6 +751,63 @@ class SFScriptForge:
importFromPropertyValues, importfrompropertyvalues = ImportFromPropertyValues, ImportFromPropertyValues
# #########################################################################
+ # SF_Exception CLASS
+ # #########################################################################
+ class SF_Exception(SFServices, metaclass = _Singleton):
+ """
+ The Exception service is a collection of methods for code debugging and error handling.
+
+ The Exception service console stores events, variable values and information about errors.
+ Use the console when the Python shell is not available, for example in Calc user defined functions (UDF)
+ or during events processing.
+ Use DebugPrint() method to aggregate additional user data of any type.
+
+ Console entries can be dumped to a text file or visualized in a dialogue.
+ """
+ # Mandatory class properties for service registration
+ serviceimplementation = 'basic'
+ servicename = 'ScriptForge.Exception'
+ servicesynonyms = ('exception', 'scriptforge.exception')
+ serviceproperties = dict()
+ propertysynonyms = SFServices._getAttributeSynonyms(serviceproperties)
+
+ def Console(self, modal = True):
+ # Modal is always True in Python: Basic execution lasts only the time to display the box
+ return self.Execute(self.vbMethod, 'Console', True)
+ console = Console
+
+ def ConsoleClear(self, keep = 0):
+ return self.Execute(self.vbMethod, 'ConsoleClear', keep)
+ consoleClear, consoleclear = ConsoleClear, ConsoleClear
+
+ def ConsoleToFile(self, filename):
+ return self.Execute(self.vbMethod, 'ConsoleToFile', filename)
+ consoleToFile, consoletofile = ConsoleToFile, ConsoleToFile
+
+ def DebugDisplay(self, *args):
+ # Arguments are concatenated in a single string similar to what the Python print() function would produce
+ self.DebugPrint(*args)
+ param = '\n'.join(list(map(lambda a : a.strip("'") if isinstance(a, str) else repr(a), args)))
+ bas = CreateScriptService('ScriptForge.Basic')
+ return bas.MsgBox(param, bas.MB_OK + bas.MB_ICONINFORMATION, 'DebugDisplay')
+ debugDisplay, debugdisplay = DebugDisplay, DebugDisplay
+
+ def DebugPrint(self, *args):
+ # Arguments are concatenated in a single string similar to what the Python print() function would produce
+ param = '\t'.join(list(map(repr, args))).expandtabs(tabsize = 4)
+ return self.Execute(self.vbMethod, 'DebugPrint', param)
+ debugPrint, debugprint = DebugPrint, DebugPrint
+
+ def RaiseFatal(self, errorcode, *args):
+ """
+ Generate a run-time error caused by an anomaly in a user script detected by ScriptForge
+ The message is logged in the console. The execution is STOPPED
+ For INTERNAL USE only
+ """
+ # Direct call because RaiseFatal forces an execution stop in Basic
+ return self.SIMPLEEXEC('SF_Exception.RaiseFatal', errorcode, *args)
+
+ # #########################################################################
# SF_FileSystem CLASS
# #########################################################################
class SF_FileSystem(SFServices, metaclass = _Singleton):