diff --git a/AllLangHelp_sbasic.mk b/AllLangHelp_sbasic.mk index cc08cf424d..16cac38779 100644 --- a/AllLangHelp_sbasic.mk +++ b/AllLangHelp_sbasic.mk @@ -369,6 +369,7 @@ $(eval $(call gb_AllLangHelp_add_helpfiles,sbasic,\ helpcontent2/source/text/sbasic/python/python_examples \ helpcontent2/source/text/sbasic/python/python_ide \ helpcontent2/source/text/sbasic/python/python_locations \ + helpcontent2/source/text/sbasic/python/python_platform \ helpcontent2/source/text/sbasic/python/python_programming \ helpcontent2/source/text/sbasic/python/python_screen \ helpcontent2/source/text/sbasic/python/python_shell \ diff --git a/source/text/sbasic/python/python_examples.xhp b/source/text/sbasic/python/python_examples.xhp index 40c00f8e34..085f9ddadb 100644 --- a/source/text/sbasic/python/python_examples.xhp +++ b/source/text/sbasic/python/python_examples.xhp @@ -31,10 +31,11 @@ - - --> + + + - + diff --git a/source/text/sbasic/python/python_platform.xhp b/source/text/sbasic/python/python_platform.xhp new file mode 100644 index 0000000000..5127069fbe --- /dev/null +++ b/source/text/sbasic/python/python_platform.xhp @@ -0,0 +1,117 @@ + + + + + + Python : Platform class + /text/sbasic/python/python_platform.xhp + + + + + Platform;isLinux + Platform;isMacOsX + Platform;isWindows + Platform;ComputerName + Platform;OSName + +

Identifying the operating system

+ Identifying the operating system can be performed with Python or Basic language. + %PRODUCTNAME Basic lacks Mac OS X native recognition while ComputerName property is solely available for Windows. Basic calls to Python macros help overcome such 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:

+ + 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 Mac OS X as well + End Property ' Platform.isLinux + + Public Property Get IsWindows As Boolean + isWindows = ( GetGUIType()=1 ) + End Property ' Platform.isWindows + + Public Property Get OSName As String + Select Case GetGUIType() + Case 1 : OSName = "Windows" + Case 4 : OSName = "Linux" + End Select + End Property ' Platform.OSName + + Public Property Get PathDelimiter As String + Select Case OSName + Case "Linux" : PathDelimiter = ":" + Case "Windows" : 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 + +
+ + + + + +
+ +
diff --git a/source/text/sbasic/shared/03132100.xhp b/source/text/sbasic/shared/03132100.xhp index 07527ed07a..0f04fb8fca 100644 --- a/source/text/sbasic/shared/03132100.xhp +++ b/source/text/sbasic/shared/03132100.xhp @@ -29,7 +29,7 @@
GetGuiType function -GetGuiType Function +

GetGuiType Function

Returns a numerical value that specifies the graphical user interface.
This function is only provided for downward compatibility to previous versions. The return value is not defined in client-server environments. diff --git a/source/text/sbasic/shared/GetPathSeparator.xhp b/source/text/sbasic/shared/GetPathSeparator.xhp index 7b1215c589..6efe464561 100644 --- a/source/text/sbasic/shared/GetPathSeparator.xhp +++ b/source/text/sbasic/shared/GetPathSeparator.xhp @@ -19,8 +19,8 @@ GetPathSeparator function
- GetPathSeparator Function - Return the operating system-dependent directory separator used to specify file paths. + GetPathSeparator Function + Returns the operating system-dependent directory separator used to specify file paths.
GetPathSeparator()