<bookmarkvalue>Plataforma;isLinux</bookmarkvalue> <bookmarkvalue>plataforma;isMacOsX</bookmarkvalue><bookmarkvalue>plataforma;isWindows</bookmarkvalue> <bookmarkvalue>plataforma;ComputerName</bookmarkvalue> <bookmarkvalue>Plataforma;OSName</bookmarkvalue> <bookmarkvalue>API;ConfigurationAccess</bookmarkvalue> <bookmarkvalue>Eines;GetRegistryContent</bookmarkvalue>

Identificació del sistema operatiu

És possible identificar el sistema operatiu a través dels llenguatges Python i Basic.

note

La propietat ComputerName només està disponible per al Windows. Les crides bàsiques a les macros de Python ajuden a superar les limitacions del Collabora Office Basic.


Mitjançant una classe del Python:

""" the_module """
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

Mitjançant un mòdul de classe del Basic:

tip

El Basic de Collabora Office no té reconeixement natiu MacOS X. És possible identificar les plataformes utilitzant la interfície de programació d'aplicacions (API) de Collabora Office.


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
    ' Retorna el nom de la plataforma com a "MAC" "UNIX" "WIN"
    ' Deduït de la funció "Tools.UCB.ShowHelperDialog".
    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

Exemples:

Amb el Python

>>> from < the_module > import Platform

>>> print(Platform().isMacOSX) # propietat de l'objecte

True

>>> input(Platform().OSName) # propietat de l'objecte

Darwin

Des del menú Eines ▸ Macros ▸ Executa una macro....

from < the_module > import Platform
import screen_io as ui
p = Platform()
ui.MsgBox(''.join(['isMacOS: ',str(p.isMacOSX)]),0,p.OSName)

Amb el Collabora Office Basic

Sub Platform_example()
    Dim p As New Platform ' instància de la classe Platform
    MsgBox p.isLinux ' propietat de l'objecte
    Print p.isWindows, p.OSName ' propietats de l'objecte
End Sub ' Platform_example

Ens cal la vostra ajuda!