Pagkilala sa operating system

Ang pagkilala sa operating system ay maaaring gawin gamit ang Python o Basic na wika.

Gamit ang isang klase ng 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
    

Gamit ang isang Basic classmodule:

tip

Ang LibreOffice Basic ay walang katutubong pagkilala sa MacOS X. Posible ang pagkakakilanlan ng platform gamit ang LibreOffice Application Programming Interface (API).



        ''' Pangalan ng module: Platform '''
        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
            ' Ibalik ang pangalan ng platform bilang "MAC", "UNIX", "WIN"
            ' Hinuha mula sa function na "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
    
note

Ang variable ng kapaligiran ng ComputerName ay magagamit lamang para sa Windows. Ang mga pangunahing tawag sa Python macro ay nakakatulong na malampasan ang LibreOffice Pangunahing limitasyon.


Mga halimbawa:

Gamit ang Python

>>> from < the_module > import Platform

>>> print(Platform().isMacOSX) # object property

True

>>> input(Platform().OSName) # object property

Darwin

Mula sa Mga Tool – Macro - Patakbuhin ang Macro... menu.


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

Gamit ang LibreOffice Basic


        Sub Platform_example()
            Dim p Bilang Bagong Platform ' halimbawa ng klase ng Platform
            MsgBox p.isLinux ' object property
            I-print ang p.isWindows, p.OSName ' na mga katangian ng object
        End Sub ' Platform_example
    

Mangyaring suportahan kami!