[Libreoffice-commits] core.git: wizards/source
Jean-Pierre Ledure (via logerrit)
logerrit at kemper.freedesktop.org
Thu Apr 8 13:13:16 UTC 2021
wizards/source/scriptforge/SF_PythonHelper.xba | 24 +++--
wizards/source/scriptforge/python/scriptforge.py | 103 +++++++++++++++++++++--
wizards/source/sfdocuments/SF_Form.xba | 1
3 files changed, 113 insertions(+), 15 deletions(-)
New commits:
commit 33ec919b6302a3e768488cb9e86a2b2c475cb177
Author: Jean-Pierre Ledure <jp at ledure.be>
AuthorDate: Wed Apr 7 16:22:46 2021 +0200
Commit: Jean-Pierre Ledure <jp at ledure.be>
CommitDate: Thu Apr 8 15:12:35 2021 +0200
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 at ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp at ledure.be>
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))
- ' Methods in class modules using a 2D array or returning arrays are hardcoded as exceptions
+ ' 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 "SFDocuments.Document"
If Script = "Forms" Then vReturn = vBasicObject.Forms(vArgs(0))
+ Case "SFDocuments.Base"
+ Select Case Script
+ Case "FormDocuments" : vReturn = vBasicObject.FormDocuments()
+ Case "Forms" : vReturn = vBasicObject.Forms(vArgs(0), vArgs(1))
+ End Select
Case "SFDocuments.Calc"
Select Case Script
- Case "Forms" : vReturn = vBasicObject.Forms(vArgs(0), vArgs(1))
- Case "GetFormula" : vReturn = vBasicObject.GetFormula(vArgs(0))
- Case "GetValue" : vReturn = vBasicObject.GetValue(vArgs(0))
- Case "SetArray" : vReturn = vBasicObject.SetArray(vArgs(0), vArgs(1))
- Case "SetFormula" : vReturn = vBasicObject.SetFormula(vArgs(0), vArgs(1))
- Case "SetValue" : vReturn = vBasicObject.SetValue(vArgs(0), vArgs(1))
+ Case "Forms" : vReturn = vBasicObject.Forms(vArgs(0), vArgs(1))
+ Case "GetFormula" : vReturn = vBasicObject.GetFormula(vArgs(0))
+ Case "GetValue" : vReturn = vBasicObject.GetValue(vArgs(0))
+ Case "SetArray" : vReturn = vBasicObject.SetArray(vArgs(0), vArgs(1))
+ Case "SetFormula" : vReturn = vBasicObject.SetFormula(vArgs(0), vArgs(1))
+ Case "SetValue" : vReturn = vBasicObject.SetValue(vArgs(0), vArgs(1))
+ End Select
+ Case "SFDocuments.Form"
+ Select Case Script
+ Case "Controls" : vReturn = vBasicObject.Controls(vArgs(0))
+ Case "Subforms" : 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
"AllowDeletes" _
, "AllowInserts" _
, "AllowUpdates" _
+ , "BaseForm" _
, "Bookmark" _
, "CurrentRecord" _
, "Filter" _
More information about the Libreoffice-commits
mailing list