summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2021-04-07 16:22:46 +0200
committerJean-Pierre Ledure <jp@ledure.be>2021-04-08 15:12:35 +0200
commit33ec919b6302a3e768488cb9e86a2b2c475cb177 (patch)
tree9c37cd421960494c5686bd3cd4fa13b3dee9023e
parenttdf#132293 removed all the unused imports from the folder sw (diff)
downloadcore-33ec919b6302a3e768488cb9e86a2b2c475cb177.tar.gz
core-33ec919b6302a3e768488cb9e86a2b2c475cb177.zip
ScriptForge - (scriptforge.py) Base and Form classes
Completion of the SFDocuments.SF_Base and addition of the SFDocuments.SF_Form classes Config of properties and methods Some methods require an hardcoded processing in _PythonDispatcher() - SF_PythonHelper.xba because they potentially may return arrays (cfr. bug #138155) Addition of SF_String etc shortcuts in Python for compatibility with Basic Change-Id: Id9852c214618e863b2fdf60aa5f80e36b3547a36 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113739 Tested-by: Jean-Pierre Ledure <jp@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
-rw-r--r--wizards/source/scriptforge/SF_PythonHelper.xba24
-rw-r--r--wizards/source/scriptforge/python/scriptforge.py103
-rw-r--r--wizards/source/sfdocuments/SF_Form.xba1
3 files changed, 113 insertions, 15 deletions
diff --git a/wizards/source/scriptforge/SF_PythonHelper.xba b/wizards/source/scriptforge/SF_PythonHelper.xba
index 728cb7b52fcc..e3d988c38aa9 100644
--- a/wizards/source/scriptforge/SF_PythonHelper.xba
+++ b/wizards/source/scriptforge/SF_PythonHelper.xba
@@ -704,20 +704,30 @@ Try:
ElseIf (CallType And vbLet) = vbLet Then
vReturn = vBasicObject.SetProperty(Script, vArgs(0))
- &apos; Methods in class modules using a 2D array or returning arrays are hardcoded as exceptions
+ &apos; Methods in class modules using a 2D array or returning arrays are hardcoded as exceptions. Bug #138155
ElseIf ((CallType And vbMethod) + (CallType And cstArgArray)) = vbMethod + cstArgArray Or _
((CallType And vbMethod) + (CallType And cstRetArray)) = vbMethod + cstRetArray Then
Select Case sServiceName
Case &quot;SFDocuments.Document&quot;
If Script = &quot;Forms&quot; Then vReturn = vBasicObject.Forms(vArgs(0))
+ Case &quot;SFDocuments.Base&quot;
+ Select Case Script
+ Case &quot;FormDocuments&quot; : vReturn = vBasicObject.FormDocuments()
+ Case &quot;Forms&quot; : vReturn = vBasicObject.Forms(vArgs(0), vArgs(1))
+ End Select
Case &quot;SFDocuments.Calc&quot;
Select Case Script
- Case &quot;Forms&quot; : vReturn = vBasicObject.Forms(vArgs(0), vArgs(1))
- Case &quot;GetFormula&quot; : vReturn = vBasicObject.GetFormula(vArgs(0))
- Case &quot;GetValue&quot; : vReturn = vBasicObject.GetValue(vArgs(0))
- Case &quot;SetArray&quot; : vReturn = vBasicObject.SetArray(vArgs(0), vArgs(1))
- Case &quot;SetFormula&quot; : vReturn = vBasicObject.SetFormula(vArgs(0), vArgs(1))
- Case &quot;SetValue&quot; : vReturn = vBasicObject.SetValue(vArgs(0), vArgs(1))
+ Case &quot;Forms&quot; : vReturn = vBasicObject.Forms(vArgs(0), vArgs(1))
+ Case &quot;GetFormula&quot; : vReturn = vBasicObject.GetFormula(vArgs(0))
+ Case &quot;GetValue&quot; : vReturn = vBasicObject.GetValue(vArgs(0))
+ Case &quot;SetArray&quot; : vReturn = vBasicObject.SetArray(vArgs(0), vArgs(1))
+ Case &quot;SetFormula&quot; : vReturn = vBasicObject.SetFormula(vArgs(0), vArgs(1))
+ Case &quot;SetValue&quot; : vReturn = vBasicObject.SetValue(vArgs(0), vArgs(1))
+ End Select
+ Case &quot;SFDocuments.Form&quot;
+ Select Case Script
+ Case &quot;Controls&quot; : vReturn = vBasicObject.Controls(vArgs(0))
+ Case &quot;Subforms&quot; : vReturn = vBasicObject.Subforms(vArgs(0))
End Select
End Select
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py
index 66079f63b472..c143d196e3b7 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -350,14 +350,14 @@ class ScriptForge(object, metaclass = _Singleton):
for method in methods:
func = getattr(cls, method)
if callable(func):
- # Assign the synonyms to the original method
+ # Assign to each synonym a reference to the original method
m = method.lower()
if hasattr(cls, m) is False:
setattr(cls, m, func)
m = camelCase(method)
if hasattr(cls, m) is False:
setattr(cls, m, func)
- return True
+ return
# #####################################################################################################################
@@ -427,10 +427,11 @@ class SFServices(object):
"""
# Python-Basic protocol constants and flags
vbGet, vbLet, vbMethod, vbSet = 2, 4, 1, 8 # CallByName constants
+ flgPost = 32 # The method or the property implies a hardcoded post-processing
flgDateArg = 64 # Invoked service method may contain a date argument
flgDateRet = 128 # Invoked service method can return a date
flgArrayArg = 512 # 1st argument can be a 2D array
- flgArrayRet = 1024 # Invoked service method can return a 2D array
+ flgArrayRet = 1024 # Invoked service method can return a 2D array (standard modules) or any array (class modules)
flgUno = 256 # Invoked service method/property can return a UNO object
flgObject = 2048 # 1st argument may be a Basic object
# Basic class type
@@ -1372,10 +1373,6 @@ class SFDocuments:
# Force for each property to get its value from Basic - due to intense interactivity with user
forceGetProperty = True
- @property
- def XComponent(self):
- return self.Execute(self.vbGet + self.flgUno, 'XComponent')
-
def Activate(self):
return self.Execute(self.vbMethod, 'Activate')
@@ -1414,6 +1411,24 @@ class SFDocuments:
IsDraw = False, IsImpress = False, IsMath = False, IsWriter = False,
XComponent = False)
+ def CloseDocument(self, saveask = True):
+ return self.Execute(self.vbMethod, 'CloseDocument', saveask)
+
+ def FormDocuments(self):
+ return self.Execute(self.vbMethod + self.flgArrayRet, 'FormDocuments')
+
+ def Forms(self, formdocument, form = ''):
+ return self.Execute(self.vbMethod + self.flgArrayRet, 'Forms', formdocument, form)
+
+ def GetDatabase(self, user = '', password = ''):
+ return self.Execute(self.vbMethod, 'GetDatabase', user, password)
+
+ def IsLoaded(self, formdocument):
+ return self.Execute(self.vbMethod, 'IsLoaded', formdocument)
+
+ def OpenFormDocument(self, formdocument, designmode = False):
+ return self.Execute(self.vbMethod, 'OpenFormDocument', formdocument, designmode)
+
# #########################################################################
# SF_Calc CLASS
# #########################################################################
@@ -1580,6 +1595,64 @@ class SFDocuments:
servicesynonyms = ()
serviceproperties = dict()
+ # #########################################################################
+ # SF_Form CLASS
+ # #########################################################################
+ class SF_Form(SFServices):
+ """
+ Management of forms defined in LibreOffice documents. Supported types are Base, Calc and Writer documents.
+ It includes the management of subforms
+ Each instance of the current class represents a single form or a single subform
+ A form may optionally be (understand "is often") linked to a data source manageable with
+ the SFDatabases.Database service. The current service offers a rapid access to that service.
+ """
+ # Mandatory class properties for service registration
+ serviceimplementation = 'basic'
+ servicename = 'SFDocuments.Form'
+ servicesynonyms = ()
+ serviceproperties = dict(AllowDeletes = True, AllowInserts = True, AllowUpdates = True, BaseForm = False,
+ Bookmark = True, CurrentRecord = True, Filter = True, LinkChildFields = False,
+ LinkParentFields = False, Name = False,
+ OnApproveCursorMove = True, OnApproveParameter = True, OnApproveReset = True,
+ OnApproveRowChange = True, OnApproveSubmit = True, OnConfirmDelete = True,
+ OnCursorMoved = True, OnErrorOccurred = True, OnLoaded = True, OnReloaded = True,
+ OnReloading = True, OnResetted = True, OnRowChanged = True, OnUnloaded = True,
+ OnUnloading = True,
+ OrderBy = True, Parent = False, RecordSource = True, XForm = False)
+
+ def Activate(self):
+ return self.Execute(self.vbMethod, 'Activate')
+
+ def CloseFormDocument(self):
+ return self.Execute(self.vbMethod, 'CloseFormDocument')
+
+ def Controls(self, controlname = ''):
+ return self.Execute(self.vbMethod + self.flgArrayRet, 'Controls', controlname)
+
+ def GetDatabase(self, user = '', password = ''):
+ return self.Execute(self.vbMethod, 'GetDatabase', user, password)
+
+ def MoveFirst(self):
+ return self.Execute(self.vbMethod, 'MoveFirst')
+
+ def MoveLast(self):
+ return self.Execute(self.vbMethod, 'MoveLast')
+
+ def MoveNew(self):
+ return self.Execute(self.vbMethod, 'MoveNew')
+
+ def MoveNext(self, offset = 1):
+ return self.Execute(self.vbMethod, 'MoveNext', offset)
+
+ def MovePrevious(self, offset = 1):
+ return self.Execute(self.vbMethod, 'MovePrevious', offset)
+
+ def Requery(self):
+ return self.Execute(self.vbMethod, 'Requery')
+
+ def Subforms(self, subform = ''):
+ return self.Execute(self.vbMethod + self.flgArrayRet, 'Subforms', subform)
+
# ##############################################False##################################################################
# CreateScriptService() ###
@@ -1642,8 +1715,22 @@ createScriptService, createscriptservice = CreateScriptService, CreateScriptServ
# #####################################################################################################################
# Services shortcuts ###
# #####################################################################################################################
+def _CreateScriptService(service):
+ """
+ Mini CreateScriptService() function to create singleton predefined Basic services
+ The ScriptForge() initialization is SKIPPED.
+ """
+ if service in ScriptForge.servicesmodules:
+ serv = ScriptForge.serviceslist[service]
+ return serv(ScriptForge.servicesmodules[service], classmodule = SFServices.moduleStandard)
+ return None
+
+
+# Shortcuts below are for compatibility with the Basic ScriptForge API
SF_Basic = SFScriptForge.SF_Basic()
-# SF_String = None
+SF_Array = _CreateScriptService('ScriptForge.SF_Array')
+SF_Exception = _CreateScriptService('ScriptForge.SF_Exception')
+SF_String = _CreateScriptService('ScriptForge.SF_String')
# ######################################################################
diff --git a/wizards/source/sfdocuments/SF_Form.xba b/wizards/source/sfdocuments/SF_Form.xba
index 2fc8f6d60038..197aad194a28 100644
--- a/wizards/source/sfdocuments/SF_Form.xba
+++ b/wizards/source/sfdocuments/SF_Form.xba
@@ -958,6 +958,7 @@ Public Function Properties() As Variant
&quot;AllowDeletes&quot; _
, &quot;AllowInserts&quot; _
, &quot;AllowUpdates&quot; _
+ , &quot;BaseForm&quot; _
, &quot;Bookmark&quot; _
, &quot;CurrentRecord&quot; _
, &quot;Filter&quot; _