wizards/source/scriptforge/SF_FileSystem.xba | 4 - wizards/source/scriptforge/SF_PythonHelper.xba | 86 +++++++++++++---------- wizards/source/scriptforge/python/scriptforge.py | 14 +++ wizards/source/sfdocuments/SF_Base.xba | 10 -- wizards/source/sfdocuments/SF_Calc.xba | 10 -- wizards/source/sfdocuments/SF_Writer.xba | 12 --- 6 files changed, 67 insertions(+), 69 deletions(-)
New commits: commit 74a638011da4c2e8475d6f9d4d3a0ffbc4e10807 Author: Jean-Pierre Ledure <j...@ledure.be> AuthorDate: Tue Feb 15 15:30:38 2022 +0100 Commit: Jean-Pierre Ledure <j...@ledure.be> CommitDate: Tue Feb 15 17:50:45 2022 +0100 ScriptForge - (scriptforge.py) get lists of properties and methods To allow object introspection and some help files automatic generation (see Telegram discussions), the possibility to make the list of properties and methods used in Basic available in Python has been requested. These changes are for internal use only. Main changes: - the SFServices parent class receives new basicproperties() and basicmethods() methods - Basic PythonDispatcher() is adapted to provide the lists to the Python caller - Methods lists are reviewed in SFDocuments to NOT include the methods implemented in the parent SF_Document class, to avoid redundant entries in the list Change-Id: I80758e225b039426b46f52dd67efe54c50f9f31e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129969 Tested-by: Jean-Pierre Ledure <j...@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <j...@ledure.be> diff --git a/wizards/source/scriptforge/SF_FileSystem.xba b/wizards/source/scriptforge/SF_FileSystem.xba index c0b7e8316fe8..39ea4888e3d1 100644 --- a/wizards/source/scriptforge/SF_FileSystem.xba +++ b/wizards/source/scriptforge/SF_FileSystem.xba @@ -2121,8 +2121,8 @@ Dim sFolder As String ' Folder End If _SFInstallFolder = _ConvertFromUrl(sFolder) - + End Function ' ScriptForge.SF_FileSystem._SFInstallFolder REM ============================================ END OF SCRIPTFORGE.SF_FileSystem -</script:module> +</script:module> \ No newline at end of file diff --git a/wizards/source/scriptforge/SF_PythonHelper.xba b/wizards/source/scriptforge/SF_PythonHelper.xba index 442a4bd1b856..d2b8f3276f43 100644 --- a/wizards/source/scriptforge/SF_PythonHelper.xba +++ b/wizards/source/scriptforge/SF_PythonHelper.xba @@ -712,6 +712,7 @@ Try: vBasicObject = _SF_.PythonStorage(BasicObject) sObjectType = vBasicObject.ObjectType sServiceName = vBasicObject.ServiceName + ' Basic modules have type = "SF_*" bBasicClass = ( Left(sObjectType, 3) <> "SF_" ) sLibrary = Split(sServiceName, ".")(0) @@ -727,10 +728,17 @@ Try: ElseIf Not bBasicClass And _ (((CallType And vbMethod) + (CallType And cstArgArray)) = vbMethod + cstArgArray Or _ ((CallType And vbMethod) + (CallType And cstRetArray)) = vbMethod + cstRetArray) Then - Select Case sServiceName - Case "ScriptForge.Array" - If Script = "ImportFromCSVFile" Then vReturn = SF_Array.ImportFromCSVFile(vArgs(0), vArgs(1), vArgs(2), True) - End Select + ' Not service related + If Script = "Methods" Then + vReturn = vBasicObject.Methods() + ElseIf Script = "Properties" Then + vReturn = vBasicObject.Properties() + Else + Select Case sServiceName + Case "ScriptForge.Array" + If Script = "ImportFromCSVFile" Then vReturn = SF_Array.ImportFromCSVFile(vArgs(0), vArgs(1), vArgs(2), True) + End Select + End If ' Methods in usual modules are called by ExecuteBasicScript() except if they use a ParamArray ElseIf Not bBasicClass And (CallType And vbMethod) = vbMethod Then @@ -759,38 +767,44 @@ Try: ' 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 "SFDatabases.Database" - If Script = "GetRows" Then vReturn = vBasicObject.GetRows(vArgs(0), vArgs(1), vArgs(2), vArgs(3)) - Case "SFDialogs.Dialog" - If Script = "Controls" Then vReturn = vBasicObject.Controls(vArgs(0)) - Case "SFDialogs.DialogControl" - If Script = "SetTableData" Then vReturn = vBasicObject.SetTableData(vArgs(0), vArgs(1), vArgs(2)) - 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 "Charts" : vReturn = vBasicObject.Charts(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 - Case "SFDocuments.FormControl" - If Script = "Controls" Then vReturn = vBasicObject.Controls(vArgs(0)) - End Select + If Script = "Methods" Then + vReturn = vBasicObject.Methods() + ElseIf Script = "Properties" Then + vReturn = vBasicObject.Properties() + Else + Select Case sServiceName + Case "SFDatabases.Database" + If Script = "GetRows" Then vReturn = vBasicObject.GetRows(vArgs(0), vArgs(1), vArgs(2), vArgs(3)) + Case "SFDialogs.Dialog" + If Script = "Controls" Then vReturn = vBasicObject.Controls(vArgs(0)) + Case "SFDialogs.DialogControl" + If Script = "SetTableData" Then vReturn = vBasicObject.SetTableData(vArgs(0), vArgs(1), vArgs(2)) + 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 "Charts" : vReturn = vBasicObject.Charts(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 + Case "SFDocuments.FormControl" + If Script = "Controls" Then vReturn = vBasicObject.Controls(vArgs(0)) + End Select + End If ' Methods in class modules are invoked with CallByName ElseIf bBasicClass And ((CallType And vbMethod) = vbMethod) Then diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index 5eb0b08a5863..53a724d9b8f4 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -267,7 +267,7 @@ class ScriptForge(object, metaclass = _Singleton): Execute a given Basic script and interpret its result This method has as counterpart the ScriptForge.SF_PythonHelper._PythonDispatcher() Basic method :param basicobject: a Service subclass - :param flags: see the vb* and flg* constants below + :param flags: see the vb* and flg* constants in the SFServices class :param method: the name of the method or property to invoke, as a string :param args: the arguments of the method. Symbolic cst* constants may be necessary :return: The invoked Basic counterpart script (with InvokeSimpleScript()) will return a tuple @@ -569,6 +569,18 @@ class SFServices(object): def Properties(self): return list(self.serviceproperties) + def basicmethods(self): + if self.serviceimplementation == 'basic': + return self.ExecMethod(self.vbMethod + self.flgArrayRet, 'Methods') + else: + return [] + + def basicproperties(self): + if self.serviceimplementation == 'basic': + return self.ExecMethod(self.vbMethod + self.flgArrayRet, 'Properties') + else: + return [] + def SetProperty(self, propertyname, value): """ Set the given property to a new value in the Basic world diff --git a/wizards/source/sfdocuments/SF_Base.xba b/wizards/source/sfdocuments/SF_Base.xba index 8e8dbfb4e27e..1e6395dbfa2c 100644 --- a/wizards/source/sfdocuments/SF_Base.xba +++ b/wizards/source/sfdocuments/SF_Base.xba @@ -440,21 +440,13 @@ Public Function Methods() As Variant ''' Return the list of public methods of the Base class as an array Methods = Array( _ - "Activate" _ - , "CloseDocument" _ - , "CloseFormDocument" _ - , "CreateMenu" _ + "CloseFormDocument" _ , "FormDocuments" _ , "Forms" _ , "GetDatabase" _ , "IsLoaded" _ , "OpenFormDocument" _ , "PrintOut" _ - , "RemoveMenu" _ - , "RunCommand" _ - , "Save" _ - , "SaveAs" _ - , "SaveCopyAs" _ , "SetPrinter" _ ) diff --git a/wizards/source/sfdocuments/SF_Calc.xba b/wizards/source/sfdocuments/SF_Calc.xba index 8c9ab301370f..f7cd2005d1b5 100644 --- a/wizards/source/sfdocuments/SF_Calc.xba +++ b/wizards/source/sfdocuments/SF_Calc.xba @@ -1636,24 +1636,20 @@ Public Function Methods() As Variant Methods = Array( _ "A1Style" _ - , "Activate" _ , "Charts" _ , "ClearAll" _ , "ClearFormats" _ , "ClearValues" _ - , "CloseDocument" _ , "CopySheet" _ , "CopySheetFromFile" _ , "CopyToCell" _ , "CopyToRange" _ , "CreateChart" _ - , "CreateMenu" _ , "DAvg" _ , "DCount" _ , "DMax" _ , "DMin" _ , "DSum" _ - , "ExportAsPDF" _ , "GetColumnName" _ , "GetFormula" _ , "GetValue" _ @@ -1666,17 +1662,11 @@ Public Function Methods() As Variant , "OpenRangeSelector" _ , "Printf" _ , "PrintOut" _ - , "RemoveMenu" _ , "RemoveSheet" _ , "RenameSheet" _ - , "RunCommand" _ - , "Save" _ - , "SaveAs" _ - , "SaveCopyAs" _ , "SetArray" _ , "SetCellStyle" _ , "SetFormula" _ - , "SetPrinter" _ , "SetValue" _ , "ShiftDown" _ , "ShiftLeft" _ diff --git a/wizards/source/sfdocuments/SF_Writer.xba b/wizards/source/sfdocuments/SF_Writer.xba index 9d2234637dd4..12d3136df65f 100644 --- a/wizards/source/sfdocuments/SF_Writer.xba +++ b/wizards/source/sfdocuments/SF_Writer.xba @@ -217,18 +217,8 @@ Public Function Methods() As Variant ''' Return the list of public methods of the Writer service as an array Methods = Array( _ - "Activate" _ - , "CloseDocument" _ - , "CreateMenu" _ - , "ExportAsPDF" _ - , "Forms" _ + "Forms" _ , "PrintOut" _ - , "RemoveMenu" _ - , "RunCommand" _ - , "Save" _ - , "SaveAs" _ - , "SaveCopyAs" _ - , "SetPrinter" _ ) End Function ' SFDocuments.SF_Writer.Methods