From 7bb0e54187ed11a169f682c49c07a461f0e84d13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LibreO=EF=AC=83ciant?= Date: Thu, 21 Feb 2019 11:58:38 +0100 Subject: [PATCH] Copying/Pasting sample code results in compiler error. Embed tags in place of link within relatedtopics Change-Id: I05d899e77a51c15d69e066bc94bd5bbb9ed69c8f Reviewed-on: https://gerrit.libreoffice.org/68142 Tested-by: Jenkins Reviewed-by: Olivier Hallot --- source/text/sbasic/python/python_session.xhp | 36 +++++++++----------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/source/text/sbasic/python/python_session.xhp b/source/text/sbasic/python/python_session.xhp index 3d54a6ffe0..2a35081a35 100644 --- a/source/text/sbasic/python/python_session.xhp +++ b/source/text/sbasic/python/python_session.xhp @@ -28,7 +28,7 @@

Examples:

With Python shell. >>> from <the_module> import Session - >>> print(Session.SharedPythonScripts()) # class method + >>> print(Session.SharedPythonScripts()) # static method >>> print(Session().UserName) # object property >>> input(Session().UserProfile) # object property

From Tools – Macros - Run Macro... menu.

@@ -37,8 +37,8 @@ def demo_session(): import screen_io as ui - ui.MsgBox(Session.Share(),title='Installation Share') # class method - ui.Print(Session.SharedPythonScripts()) # class method + 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 @@ -76,31 +76,31 @@ 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) + 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")) + inst = uno.fileUrlToSystemPath(Session.substitute("$(prog)")) + return os.path.normpath(inst.replace('program', "Share")) @staticmethod def SharedScripts(): - return ''.join([Session.Share(), os.sep, "Scripts"]) + return ''.join([Session.Share(), os.sep, "Scripts"]) @staticmethod def SharedPythonScripts(): - return ''.join([Session.SharedScripts(), os.sep, 'python']) + 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)")) + return uno.fileUrlToSystemPath(Session.substitute("$(user)")) @property def UserScripts(self): - return ''.join([self.UserProfile, os.sep, 'Scripts']) + return ''.join([self.UserProfile, os.sep, 'Scripts']) @property def UserPythonScripts(self): - return ''.join([self.UserScripts, os.sep, "python"]) + return ''.join([self.UserScripts, os.sep, "python"]) Unlike Basic, pathname normalization is performed with Python inside Session class.

%PRODUCTNAME Basic Session class:

@@ -148,12 +148,8 @@ End Property ' Session.userPythonScripts
- - Importing Python modules - - - Input/Output to Screen - + +