scriptforge.py - improve debugging mode

To facilitate the debugging of the
ScriptForge Basic code called by the
python scripts, 2 methods have been
added to the ScriptForge() class:

- initializeRoot(force = False)
  Initialize the global scriptforge
  data structure.
  - When force = False, only when
    not yet done.
  - When force = True, reinitialize it
    whatever its status.

- errorHandling(standard = True)
  Determine how errors in the ScriptForge
  Basic code are handled. Either
  - the standard mode, i.e. display a "crash" message
    to the user
  - the debugging mode, i.e. the execution stops
    on the line causing the error

Example (cfr. tdf#162962)

from scriptforge import CreateScriptService, ScriptForge
sf = ScriptForge()
sf.errorHandling(False)

def testSF():
    srv = CreateScriptService("Calc")

g_exportedScripts = (testSF,)

Change-Id: I25d7d8e36e71d95ff8a04191bb8344794886d69e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173458
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
This commit is contained in:
Jean-Pierre Ledure 2024-09-16 16:23:00 +02:00
parent 8b07b631f3
commit acbbf33d67

View file

@ -97,6 +97,8 @@ class ScriptForge(object, metaclass = _Singleton):
- Coexistence with UNO
The class may be instantiated several times. Only the first instance will be retained ("Singleton").
All its properties and methods are for INTERNAL / DEBUGGING use only.
"""
# #########################################################################
@ -407,6 +409,26 @@ class ScriptForge(object, metaclass = _Singleton):
pass
return returnvalue
@classmethod
def initializeRoot(cls, force = False):
"""
Initialize the global scriptforge data structure.
When force = False, only when not yet done.
When force = True, reinitialize it whatever its status.
"""
script = 'application#ScriptForge.SF_Utils._InitializeRoot'
return cls.InvokeSimpleScript(script, force)
@classmethod
def errorHandling(cls, standard = True):
"""
Determine how errors in the ScriptForge Basic code are handled. Either
- the standard mode, i.e. display a "crash" message to the user
- the debugging mode, i.e. the execution stops on the line causing the error
"""
script = 'application#ScriptForge.SF_Utils._ErrorHandling'
return cls.InvokeSimpleScript(script, standard)
@classmethod
def SetAttributeSynonyms(cls):
"""