From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- .../source/text/sbasic/python/python_platform.xhp | 129 +++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 helpcontent2/source/text/sbasic/python/python_platform.xhp (limited to 'helpcontent2/source/text/sbasic/python/python_platform.xhp') diff --git a/helpcontent2/source/text/sbasic/python/python_platform.xhp b/helpcontent2/source/text/sbasic/python/python_platform.xhp new file mode 100644 index 000000000..364e067f3 --- /dev/null +++ b/helpcontent2/source/text/sbasic/python/python_platform.xhp @@ -0,0 +1,129 @@ + + + + + + Python : Platform class + /text/sbasic/python/python_platform.xhp + + + + + Platform;isLinux + Platform;isMacOsX + Platform;isWindows + Platform;ComputerName + Platform;OSName + API;ConfigurationAccess + Tools;GetRegistryContent + +

Identifying the operating system

+ Identifying the operating system can be performed with Python or Basic language. + ComputerName property is solely available for Windows. Basic calls to Python macros help overcome %PRODUCTNAME Basic limitations. +

Using a Python class:

+ + import os, platform + class Platform(): + @property + def ComputerName(self): return platform.node() + @property + def DirSeparator(self): return os.sep + @property + def isLinux(self): return (self.OSName=='Linux') + @property + def isMacOSX(self): return (self.OSName=='Darwin') + @property + def isWindows(self): return (self.OSName=='Windows') + @property + def OSName(self): return platform.system() + @property + def PathDelimiter(self): return os.pathsep + +

Using a Basic classmodule:

+ %PRODUCTNAME Basic lacks MacOS X native recognition. Platform identification is possible using %PRODUCTNAME Application Programming Interface (API). + + Option Compatible + Option ClassModule + Option Explicit + + Public Property Get ComputerName As String + If isWindows Then ComputerName = Environ("ComputerName") + End Property ' Platform.ComputerName + + Public Property Get DirSeparator As String + DirSeparator = GetPathSeparator() + End Property ' Platform.DirSeparator + + Public Property Get IsLinux As Boolean + isLinux = ( GetGUIType()=4 ) ' Applies to macOS as well + End Property ' Platform.isLinux + + Public Property Get IsMacOSX As Boolean + isMacOSX = ( OSName="MAC" ) + End Property ' Platform.isMacOSX + + Public Property Get IsWindows As Boolean + isWindows = ( GetGUIType()=1 ) + End Property ' Platform.isWindows + + Public Property Get OSName As String + ' Return platform name as "MAC", "UNIX", "WIN" + ' Inferred from "Tools.UCB.ShowHelperDialog" function + With GlobalScope.Basiclibraries + If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools") + End With + Dim keyNode As Object ' com.sun.star.configuration.ConfigurationAccess + keyNode = Tools.Misc.GetRegistryKeyContent("org.openoffice.Office.Common/Help") + OSName = keyNode.GetByName("System") + End Property ' Platform.OSName + + Public Property Get PathDelimiter As String + Select Case OSName + Case "MAC", "UNIX" : PathDelimiter = ":" + Case "WIN" : PathDelimiter = ";" + End Select + End Property ' Platform.PathDelimiter + +

Examples:

+ With Python + >>> from <the_module> import Platform + >>> print(Platform().isMacOSX) # object property + True + >>> input(Platform().OSName) # object property + Darwin + + From Tools – Macros - Run Macro... menu. + + from <the_module> import Platform + import screen_io as ui + p = Platform() + ui.MsgBox(''.join(['isMacOS: ',str(p.isMacOSX)]),0,p.OSName) + + With %PRODUCTNAME Basic + + Sub Platform_example() + Dim p As New Platform ' instance of Platform class + MsgBox p.isLinux ' object property + Print p.isWindows, p.OSName ' object properties + End Sub ' Platform_example + +
+ + + + + + +
+ +
\ No newline at end of file -- cgit v1.2.3