[Libreoffice-commits] core.git: wizards/source

Jean-Pierre Ledure (via logerrit) logerrit at kemper.freedesktop.org
Sun Feb 21 16:06:56 UTC 2021


 wizards/source/scriptforge/SF_Platform.xba             |   24 ++++++++++++++++-
 wizards/source/scriptforge/python/ScriptForgeHelper.py |    5 +++
 2 files changed, 28 insertions(+), 1 deletion(-)

New commits:
commit 4b448758a98670efe259965829e5ce0861392caf
Author:     Jean-Pierre Ledure <jp at ledure.be>
AuthorDate: Sun Feb 21 15:48:01 2021 +0100
Commit:     Jean-Pierre Ledure <jp at ledure.be>
CommitDate: Sun Feb 21 17:06:18 2021 +0100

    ScriptForge - (SF_Platform) new Locale and PythonVersion properties
    
    - 'Locale' returns a la-CO (language-COUNTRY) string
       derived from com.sun.star.lang.Locale
    - 'PythonVersion' returns Python major.minor.patchlevel
       supplied by ScriptForgeHelper.py platform class
    
    Change-Id: I2b8495c03253b17c5e4ba14765b1f359eee67813
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111284
    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_Platform.xba b/wizards/source/scriptforge/SF_Platform.xba
index 80f3ab97a182..69045404b5ba 100644
--- a/wizards/source/scriptforge/SF_Platform.xba
+++ b/wizards/source/scriptforge/SF_Platform.xba
@@ -70,6 +70,14 @@ Property Get CurrentUser() As String
 	CurrentUser = _PropertyGet("CurrentUser")
 End Property	'	ScriptForge.SF_Platform.CurrentUser (get)
 
+REM -----------------------------------------------------------------------------
+Property Get Locale() As String
+'''	Returns the locale combining language-COUNTRY (la-CO)
+'''	Example:
+'''		MsgBox platform.Locale
+	Locale = _PropertyGet("Locale")
+End Property	'	ScriptForge.SF_Platform.Locale (get)
+
 REM -----------------------------------------------------------------------------
 Property Get Machine() As String
 '''	Returns the machine type like 'i386' or 'x86_64'
@@ -138,6 +146,14 @@ Property Get Processor() As String
 	Processor = _PropertyGet("Processor")
 End Property	'	ScriptForge.SF_Platform.Processor (get)
 
+REM -----------------------------------------------------------------------------
+Property Get PythonVersion() As String
+'''	Returns the Python version as string 'Python major.minor.patchlevel'
+'''	Example:
+'''		MsgBox platform.PythonVersion	'	Python 3.7.7
+	PythonVersion = _PropertyGet("PythonVersion")
+End Property	'	ScriptForge.SF_Platform.PythonVersion (get)
+
 REM ===================================================================== METHODS
 
 REM -----------------------------------------------------------------------------
@@ -190,6 +206,7 @@ Public Function Properties() As Variant
 					, "ComputerName" _
 					, "CPUCount" _
 					, "CurrentUser" _
+					, "Locale" _
 					, "Machine" _
 					, "OfficeVersion" _
 					, "OSName" _
@@ -197,6 +214,7 @@ Public Function Properties() As Variant
 					, "OSRelease" _
 					, "OSVersion" _
 					, "Processor" _
+					, "PythonVersion" _
 					)
 
 End Function	'	ScriptForge.SF_Platform.Properties
@@ -238,6 +256,7 @@ Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
 '''		psProperty: the name of the property
 
 Dim sOSName As String			'	Operating system
+Dim oLocale As Object			'	com.sun.star.lang.Locale
 
 Const cstPyHelper = "$" & "_SF_Platform"
 Dim cstThisSub As String
@@ -248,10 +267,13 @@ Const cstSubArgs = ""
 
 	Select Case psProperty
 		Case "Architecture", "ComputerName", "CPUCount", "CurrentUser", "Machine" _
-				, "OSPlatform", "OSRelease", "OSVersion", "Processor"
+				, "OSPlatform", "OSRelease", "OSVersion", "Processor", "PythonVersion"
 			With ScriptForge.SF_Session
 				_PropertyGet = .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper & cstPyHelper, psProperty)
 			End With
+		Case "Locale"
+			Set oLocale = SF_Utils._GetUNOService("Locale")
+			_PropertyGet = oLocale.Language & "-" & oLocale.Country
 		Case "OfficeVersion"
 			_PropertyGet = _GetProductName()
 		Case "OSName"
diff --git a/wizards/source/scriptforge/python/ScriptForgeHelper.py b/wizards/source/scriptforge/python/ScriptForgeHelper.py
index ca520434a2a9..aec9311a3f3f 100644
--- a/wizards/source/scriptforge/python/ScriptForgeHelper.py
+++ b/wizards/source/scriptforge/python/ScriptForgeHelper.py
@@ -171,6 +171,8 @@ def _SF_Platform(propertyname: str):       # used by SF_Platform Basic module
         return pf.OSVersion
     elif propertyname == 'Processor':
         return pf.Processor
+    elif propertyname == 'PythonVersion':
+        return pf.PythonVersion
     else:
         return None
 
@@ -210,6 +212,9 @@ class Platform(object, metaclass = _Singleton):
     @property  # real processor name e.g. 'amdk'
     def Processor(self): return platform.processor()
 
+    @property  # Python major.minor.patchlevel
+    def PythonVersion(self): return 'Python ' + platform.python_version()
+
 
 # #################################################################
 # Session service


More information about the Libreoffice-commits mailing list