[Libreoffice-commits] core.git: wizards/source
Jean-Pierre Ledure (via logerrit)
logerrit at kemper.freedesktop.org
Wed Mar 24 17:39:30 UTC 2021
wizards/source/scriptforge/SF_PythonHelper.xba | 5 +
wizards/source/scriptforge/python/scriptforge.py | 64 ++++++++++++++++++++++-
2 files changed, 66 insertions(+), 3 deletions(-)
New commits:
commit 137b08799808d93614045aba7f7c2e77b7eaf9d3
Author: Jean-Pierre Ledure <jp at ledure.be>
AuthorDate: Tue Mar 23 16:20:13 2021 +0100
Commit: Jean-Pierre Ledure <jp at ledure.be>
CommitDate: Wed Mar 24 18:38:42 2021 +0100
ScriptForge - (scriptforge.py) String class
Only a subset of the available methods is implemented:
HashStr, IsADate, IsEmail, IsFileName, IsIBAN,
IsIPv4, IsLike, IsSheetName, IsUrl,
SplitNotQuoted, Wrap
The other methods are better replaced by Python builtin
functions.
The flgDateArg flag has been introduced to distinguish
a date argument passed as a string that does not require
conversion from a date passed in iso-format that
requires a conversion to a Basic variable of type Date
Change-Id: I80f7e816dfeaee793862f3c3d35488da7c573c8f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113002
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 7368390c97bf..5acd2dfc9228 100644
--- a/wizards/source/scriptforge/SF_PythonHelper.xba
+++ b/wizards/source/scriptforge/SF_PythonHelper.xba
@@ -558,6 +558,7 @@ Const cstNoArgs = "+++NOARGS+++", cstSymEmpty = "+++EMPTY+++"
' Determines the CallType
Const vbGet = 2, vbLet = 4, vbMethod = 1, vbSet = 8
' Protocol flags
+Const cstDateArg = 64 ' May contain a date argument
Const cstDateRet = 128 ' Return value can be a date
Const cstArgArray = 512 ' 1st argument can be a 2D array
Const cstRetArray = 1024 ' Return value can be an array
@@ -589,9 +590,9 @@ Check:
vArg = Null
ElseIf vArg = cstSymMissing Then
Exit For ' Next arguments must be missing also
- Else
+ ElseIf ( CallType And cstDateArg ) = cstDateArg Then ' Arguments might be dates
vArg = SF_Utils._CStrToDate(vArg)
- If vArg < 0 Then vArg = Args(i) 'Conversion of iso format failed => forget
+ If vArg < 0 Then vArg = Args(i) ' Conversion of iso format failed => reset
End If
End If
iNbArgs = iNbArgs + 1
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py
index 14ba1e48c8db..92f214c34e52 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -360,6 +360,7 @@ class SFServices(object):
"""
# Python-Basic protocol constants and flags
vbGet, vbLet, vbMethod, vbSet = 2, 4, 1, 8 # CallByName constants
+ 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
@@ -764,7 +765,7 @@ class SFScriptForge:
result = []
for pv in iter(propertyvalues):
key = pv.Name
- if key not in self:
+ if overwrite is True or key not in self:
item = pv.Value
if 'com.sun.star.util.DateTime' in repr(type(item)):
item = datetime.datetime(item.Year, item.Month, item.Day,
@@ -1056,6 +1057,67 @@ class SFScriptForge:
return self.SIMPLEEXEC(self.py, 'Processor')
processor = Processor
+ # #########################################################################
+ # SF_String CLASS
+ # #########################################################################
+ class SF_String(SFServices, metaclass = _Singleton):
+ """
+ Focus on string manipulation, regular expressions, encodings and hashing algorithms.
+ The methods implemented in Basic that are redundant with Python builtin functions
+ are not duplicated
+ """
+ # Mandatory class properties for service registration
+ serviceimplementation = 'basic'
+ servicename = 'ScriptForge.String'
+ servicesynonyms = ('string', 'scriptforge.string')
+ serviceproperties = dict()
+ propertysynonyms = SFServices._getAttributeSynonyms(serviceproperties)
+
+ def HashStr(self, inputstr, algorithm):
+ py = ScriptForge.pythonhelpermodule + '$' + '_SF_String__HashStr'
+ return self.SIMPLEEXEC(py, inputstr, algorithm.lower())
+ hashStr, hashstr = HashStr, HashStr
+
+ def IsADate(self, inputstr, dateformat = 'YYYY-MM-DD'):
+ return self.Execute(self.vbMethod, 'IsADate', inputstr, dateformat)
+ isADate, isadate = IsADate, IsADate
+
+ def IsEmail(self, inputstr):
+ return self.Execute(self.vbMethod, 'IsEmail', inputstr)
+ isEmail, isemail = IsEmail, IsEmail
+
+ def IsFileName(self, inputstr, osname = ScriptForge.cstSymEmpty):
+ return self.Execute(self.vbMethod, 'IsFileName', inputstr, osname)
+ isFileName, isfilename = IsFileName, IsFileName
+
+ def IsIBAN(self, inputstr):
+ return self.Execute(self.vbMethod, 'IsIBAN', inputstr)
+ isIBAN, isiban = IsIBAN, IsIBAN
+
+ def IsIPv4(self, inputstr):
+ return self.Execute(self.vbMethod, 'IsIPv4', inputstr)
+ isIPv4, isipv4 = IsIPv4, IsIPv4
+
+ def IsLike(self, inputstr, pattern, casesensitive = False):
+ return self.Execute(self.vbMethod, 'IsLike', inputstr, pattern, casesensitive)
+ isLike, islike = IsLike, IsLike
+
+ def IsSheetName(self, inputstr):
+ return self.Execute(self.vbMethod, 'IsSheetName', inputstr)
+ isSheetName, issheetname = IsSheetName, IsSheetName
+
+ def IsUrl(self, inputstr):
+ return self.Execute(self.vbMethod, 'IsUrl', inputstr)
+ isUrl, isurl = IsUrl, IsUrl
+
+ def SplitNotQuoted(self, inputstr, delimiter = ' ', occurrences = 0, quotechar = '"'):
+ return self.Execute(self.vbMethod, 'SplitNotQuoted', inputstr, delimiter, occurrences, quotechar)
+ splitNotQuoted, splitnotquoted = SplitNotQuoted, SplitNotQuoted
+
+ def Wrap(self, inputstr, width = 70, tabsize = 8):
+ return self.Execute(self.vbMethod, 'Wrap', inputstr, width, tabsize)
+ wrap = Wrap
+
# #########################################################################
# SF_TextStream CLASS
# #########################################################################
More information about the Libreoffice-commits
mailing list