diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2021-06-17 14:58:24 +0200 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2021-06-18 12:20:42 +0200 |
commit | 7c0d8c646b8fd3e31c325ac4dd6636a2ce684be2 (patch) | |
tree | 917f110f9aff1a4bee91287cab6def5808f47dbf /wizards | |
parent | d50501d1b4c015232c31c75a16b96143d43f7a3f (diff) |
ScriptForge - (scriptforge.py/CreateScriptService) allow keyword args
For Python scripts only:
the CreateScriptService() method accepts now both positional
(as before) and keyword arguments.
The impacted services are:
- database
- dialog
- document
- base
- calc
Done with the ReviewServiceArgs() class method that returns the
input arguments as a tuple in the correct sequence. This method
is inserted in each of the impacted service definitions.
Change-Id: I545ca5ef0a4e7946d598eed07a2122885e4f864a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117387
Tested-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards')
-rw-r--r-- | wizards/source/scriptforge/python/scriptforge.py | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py index d2126b435126..d94a7781cb97 100644 --- a/wizards/source/scriptforge/python/scriptforge.py +++ b/wizards/source/scriptforge/python/scriptforge.py @@ -1541,6 +1541,13 @@ class SFDatabases: servicesynonyms = ('database', 'sfdatabases.database') serviceproperties = dict(Queries = False, Tables = False, XConnection = False, XMetaData = False) + @classmethod + def ReviewServiceArgs(cls, filename = '', registrationname = '', readonly = True, user = '', password = ''): + """ + Transform positional and keyword arguments into positional only + """ + return (filename, registrationname, readonly, user, password) + def CloseDatabase(self): return self.ExecMethod(self.vbMethod, 'CloseDatabase') @@ -1608,21 +1615,12 @@ class SFDialogs: OKBUTTON, CANCELBUTTON = 1, 0 @classmethod - def PreProcessArgs(cls, args): + def ReviewServiceArgs(cls, container = '', library = 'Standard', dialogname = ''): """ - Review the arguments of the creation of the Basic service (must be a class method) - - accept None as default values for Container and Library arguments - - add the XComponentContext as last argument + Transform positional and keyword arguments into positional only + Add the XComponentContext as last argument """ - listargs = list(args) # Make a mutable list because args is an immutable tuple - if len(listargs) >= 1: - if listargs[0] is None: # Container - listargs[0] = '' - if len(listargs) >= 2: - if listargs[1] is None: - listargs[1] = 'Standard' # Library - newargs = (*listargs, ScriptForge.componentcontext) - return newargs + return (container, library, dialogname, ScriptForge.componentcontext) def Activate(self): return self.ExecMethod(self.vbMethod, 'Activate') @@ -1726,6 +1724,13 @@ class SFDocuments: # Force for each property to get its value from Basic - due to intense interactivity with user forceGetProperty = True + @classmethod + def ReviewServiceArgs(cls, windowname = ''): + """ + Transform positional and keyword arguments into positional only + """ + return (windowname,) + def Activate(self): return self.ExecMethod(self.vbMethod, 'Activate') @@ -1765,6 +1770,13 @@ class SFDocuments: IsDraw = False, IsImpress = False, IsMath = False, IsWriter = False, XComponent = False) + @classmethod + def ReviewServiceArgs(cls, windowname = ''): + """ + Transform positional and keyword arguments into positional only + """ + return (windowname,) + def CloseDocument(self, saveask = True): return self.ExecMethod(self.vbMethod, 'CloseDocument', saveask) @@ -1804,6 +1816,13 @@ class SFDocuments: # Force for each property to get its value from Basic - due to intense interactivity with user forceGetProperty = True + @classmethod + def ReviewServiceArgs(cls, windowname = ''): + """ + Transform positional and keyword arguments into positional only + """ + return (windowname,) + # Next functions are implemented in Basic as read-only properties with 1 argument def Height(self, rangename): return self.GetProperty('Height', rangename) @@ -2045,7 +2064,7 @@ class SFDocuments: # ##############################################False################################################################## # CreateScriptService() ### # ##################################################################################################################### -def CreateScriptService(service, *args): +def CreateScriptService(service, *args, **kwargs): """ A service being the name of a collection of properties and methods, this method returns either @@ -2095,9 +2114,9 @@ def CreateScriptService(service, *args): # The requested service is to be found in the Basic world # Check if the service must review the arguments if serv is not None: - if hasattr(serv, 'PreProcessArgs'): - # PreProcessArgs() must be a class method - args = serv.PreProcessArgs(args) + if hasattr(serv, 'ReviewServiceArgs'): + # ReviewServiceArgs() must be a class method + args = serv.ReviewServiceArgs(*args, **kwargs) # Get the service object back from Basic if len(args) == 0: serv = ScriptForge.InvokeBasicService('SF_Services', SFServices.vbMethod, 'CreateScriptService', service) |