Saioaren informazioa eskuratzea

LibreOffice erabiltzaile-profila eta modulu partekatuen sistemaren fitxategi-izenak kalkulatzeko, Python edo Basic lengoaiak erabil daitezke. BeanShell, Java, JavaScript eta Python scripten kokalekua informazio horretatik eratorri daiteke.

Adibideak:

Python shell-arekin.

>>> from <the_module> import Session

>>> print(Session.SharedPythonScripts()) # metodo estatikoa

>>> print(Session().UserName) # objektu-propietatea

>>> input(Session().UserProfile) # objektu-propietatea

Tresnak - Makroak - Exekutatu makroa... menutik.


        from <the_module> import Session
            
        def demo_session():
            import screen_io as ui
            ui.MsgBox(Session.Share(),title='Installation Share')  # metodo estatikoa
            ui.Print(Session.SharedPythonScripts())  # metodo estatikoa
            s = Session()  # instantziaren sorrera
            ui.MsgBox(s.UserName,title='Kaixo')  # objektu-propietatea
            ui.Print(s.UserPythonScripts)  # objektu-propietatea
            
        g_exportedScripts = (demo_session,)  # makro publikoak
    

LibreOffice Basic lengoaiarekin.


        Sub Session_example()
            Dim s As New Session ' instance of Session class
            Print "Script partekatuen kokalekua:", s.SharedScripts
            MsgBox s.UserName,,"Kaixo"
            Print s.UserScripts, Chr(13), s.UserPythonScripts
        End Sub ' Session_example
    

COM/OLE eta Visual Basic Scripting lengoaia erabilita.


        ' Zerbitzu-kudeatzailea beti da sarrera-puntua
        ' Bulegotika-aplikazioa exekutatzen ari ez bada, abiarazi egingo da
        Set sm = WScript.CreateObject("com.sun.star.ServiceManager")
        ' PathSubstitution zerbitzuak ondorioak ateratzeko informazioa erakusten du
        ' <UserProfile|Share>/Scripts/python kokalekuak hemendik:
        Set obj = sm.createInstance("com.sun.star.util.PathSubstitution")
            
        MsgBox CreateObject("WScript.Network").UserName,, "Hello"
        user = obj.getSubstituteVariableValue("$(user)")
        MsgBox user & "/Scripts",, "User scripts location"
        libO = Replace(obj.getSubstituteVariableValue("$(inst)"), "program/..", "Share")
        MsgBox libO & "/Scripts",, "Shared scripts location"
    

Pythonen Session klasea:


        import getpass, os, os.path, uno
            
        class Session():
            @staticmethod
            def substitute(var_name):
                ctx = uno.getComponentContext()
                ps = ctx.getServiceManager().createInstanceWithContext(
                    'com.sun.star.util.PathSubstitution', ctx)
                return ps.getSubstituteVariableValue(var_name)
            @staticmethod
            def Share():
                inst = uno.fileUrlToSystemPath(Session.substitute("$(prog)"))
                return os.path.normpath(inst.replace('program', "Share"))
            @staticmethod
            def SharedScripts():
                return ''.join([Session.Share(), os.sep, "Scripts"])
            @staticmethod
            def SharedPythonScripts():
                return ''.join([Session.SharedScripts(), os.sep, 'python'])
            @property  # '$(username)' aldaiaren ordezkoa
            def UserName(self): return getpass.getuser()
            @property
            def UserProfile(self):
                return uno.fileUrlToSystemPath(Session.substitute("$(user)"))
            @property
            def UserScripts(self):
                return ''.join([self.UserProfile, os.sep, 'Scripts'])
            @property
            def UserPythonScripts(self):
                return ''.join([self.UserScripts, os.sep, "python"])
    
note

Basic lengoaian ez bezala, Pythonen Session klasearen barruan gauzatzen da bide-izenen normalizazioa.


LibreOffice Basic Session klasea:


        Option Explicit
        Option Compatible
        Option ClassModule
            
        Private _ps As Object ' Kide pribatua
            
        Private Sub Class_Initialize()
            GlobalScope.BasicLibraries.LoadLibrary("Tools")
            Set _ps = CreateUnoService("com.sun.star.util.PathSubstitution")
        End Sub ' Eraikitzailea
            
        Private Sub Class_Terminate()
            _ps = Nothing
        End Sub ' Suntsitzailea
            
        Public Property Get SharedScripts() As String
            Dim inst As String, shr As String
            inst = ConvertFromURL(_ps.getSubstituteVariableValue("$(prog)"))
            shr = Tools.Strings.ReplaceString(inst,"Share","program")
            SharedScripts = shr & GetPathSeparator() &"Scripts"
        End Property ' Session.sharedScripts
            
        Public Property Get SharedPythonScripts() As String
            sharedPythonScripts = sharedScripts() & GetPathSeparator() &"python"
        End Property ' Session.sharedPythonScripts
            
        Public Property Get UserName() As String ' Erabiltzailearen kontu-izena
            userName = _ps.getSubstituteVariableValue("$(username)")
        End Property ' Session.userName
            
        Public Property Get UserProfile() As String ' Erabiltzaile-profilaren bidea sisteman
            userProfile = ConvertFromURL(_ps.getSubstituteVariableValue("$(user)"))
        End Property ' Session.userProfile
            
        Public Property Get UserScripts() As String ' Erabiltzailearen scripten bidea sisteman
            userScripts = userProfile() & GetPathSeparator() &"Scripts"
        End Property ' Session.userScripts
            
        Public Property Get UserPythonScripts() As String ' Erabiltzailearen Python scripten bidea sisteman
            userPythonScripts = userScripts() & GetPathSeparator() &"python"
        End Property ' Session.userPythonScripts
    

Emaguzu laguntza!