From b21bc34d745fb5a50b1cad84b3bfc44c3229aeda Mon Sep 17 00:00:00 2001 From: Gabor Kelemen Date: Tue, 6 Aug 2019 21:43:05 +0200 Subject: Don't translate example code snippets Also avoid errors at 'make translations' such as: Helpex warning: invalid po attributes extracted from /home/gabor/src/core/helpcontent2/source/text/sbasic/python/python_2_basic.xhp No string specified! GroupID: N0344 Helpex warning: invalid po attributes extracted from /home/gabor/src/core/helpcontent2/source/text/sbasic/python/python_2_basic.xhp No string specified! GroupID: N0382 Helpex warning: invalid po attributes extracted from /home/gabor/src/core/helpcontent2/source/text/sbasic/python/python_2_basic.xhp No string specified! GroupID: N0387 Helpex warning: invalid po attributes extracted from /home/gabor/src/core/helpcontent2/source/text/sbasic/python/python_2_basic.xhp No string specified! GroupID: N0393 Helpex warning: invalid po attributes extracted from /home/gabor/src/core/helpcontent2/source/text/sbasic/python/python_2_basic.xhp No string specified! GroupID: N0395 Helpex warning: invalid po attributes extracted from /home/gabor/src/core/helpcontent2/source/text/sbasic/python/python_2_basic.xhp No string specified! GroupID: N0400 Helpex warning: invalid po attributes extracted from /home/gabor/src/core/helpcontent2/source/text/sbasic/python/python_2_basic.xhp No string specified! GroupID: N0405 Helpex warning: invalid po attributes extracted from /home/gabor/src/core/helpcontent2/source/text/sbasic/python/python_2_basic.xhp No string specified! GroupID: N0417 Change-Id: I0715209dd8cf7b044a2914cfbcd3cfabdeab66ed Reviewed-on: https://gerrit.libreoffice.org/77073 Tested-by: Jenkins Reviewed-by: Olivier Hallot Tested-by: Olivier Hallot --- source/text/sbasic/python/python_2_basic.xhp | 128 +++++++++++++-------------- 1 file changed, 64 insertions(+), 64 deletions(-) (limited to 'source/text/sbasic') diff --git a/source/text/sbasic/python/python_2_basic.xhp b/source/text/sbasic/python/python_2_basic.xhp index 19c10e5dfe..ab4a46ea64 100644 --- a/source/text/sbasic/python/python_2_basic.xhp +++ b/source/text/sbasic/python/python_2_basic.xhp @@ -40,27 +40,27 @@ API;XScriptProvider: Retrieving Basic scripts - import uno - from com.sun.star.script.provider import Xscript - - def getBasicScript(macro='Main', module='Module1', library='Standard', - isEmbedded=False) -> XScript: + import uno + from com.sun.star.script.provider import Xscript + + def getBasicScript(macro='Main', module='Module1', library='Standard', + isEmbedded=False) -> XScript: '''Grab Basic script object before invocation.''' - ctx = uno.getComponentContext() - smgr = ctx.ServiceManager - if isEmbedded: - desktop = smgr.createInstanceWithContext('com.sun.star.frame.Desktop', ctx) - scriptPro = desktop.CurrentComponent.getScriptProvider() - location = "document" - else: - mspf = smgr.createInstanceWithContext( - "com.sun.star.script.provider.MasterScriptProviderFactory", ctx) - scriptPro = mspf.createScriptProvider("") - location = "application" - scriptName = "vnd.sun.star.script:"+library+"."+module+"."+macro+ \ - "?language=Basic&location="+location - xScript = scriptPro.getScript(scriptName) - return xScript + ctx = uno.getComponentContext() + smgr = ctx.ServiceManager + if isEmbedded: + desktop = smgr.createInstanceWithContext('com.sun.star.frame.Desktop', ctx) + scriptPro = desktop.CurrentComponent.getScriptProvider() + location = "document" + else: + mspf = smgr.createInstanceWithContext( + "com.sun.star.script.provider.MasterScriptProviderFactory", ctx) + scriptPro = mspf.createScriptProvider("") + location = "application" + scriptName = "vnd.sun.star.script:"+library+"."+module+"."+macro+ \ + "?language=Basic&location="+location + xScript = scriptPro.getScript(scriptName) + return xScript

Executing %PRODUCTNAME Basic Scripts

@@ -83,62 +83,62 @@ Examples in Input/Output to Screen detail Python to Basic invocation calls. Monitoring Document Events illustrates the usage of *args Python idiom to print a variable number of parameters to Access2Base logging console dialog. At time of development you can interrupt Python script execution using Xray extension in order to inspect properties and methods of UNO objects. The ASPO extension debugger allows object introspection using either Xray either MRI extensions. - def xray(myObject): - script = getBasicScript(library="XrayTool", module="_Main", macro="Xray") - script.invoke((myObject,), (), ()) + def xray(myObject): + script = getBasicScript(library="XrayTool", module="_Main", macro="Xray") + script.invoke((myObject,), (), ())

Examples of Embedded Scripts in Documents

*argsPython simplified syntax can be used in conjunction with %PRODUCTNAME Basic routines that accept a variable number of arguments. Below Print and SUM Python functions call their Basic Print and SUM counterparts, using aforementioned getBasicScript function. Exception handling is not detailed. - # -*- coding: utf-8 -*- - from __future__ import unicode_literals - - def Print(*args): + # -*- coding: utf-8 -*- + from __future__ import unicode_literals + + def Print(*args): """Outputs the specified strings or numeric expressions in a dialog box.""" - xScript = getBasicScript("Print", "Scripting", embedded=True) - xScript.invoke((args), (), ()) - - def SUM(*args): + xScript = getBasicScript("Print", "Scripting", embedded=True) + xScript.invoke((args), (), ()) + + def SUM(*args): """SUM the specified number expression.""" - xScript = getBasicScript("SUM", "Scripting", embedded=True) - res = xScript.invoke((args), (), ()) - return res[0] - - # def getBasicScript() # see above - - def playWithArgs(): - Print("Fun with *args ", -9.81, 297864.681974, 8762E-137) - Print(SUM(45, -9.81, 297864.681974)) - Print(SUM(45, -9.81, 297864.681974, 8762E+137)) - - g_exportedScripts = (playWithArgs,) + xScript = getBasicScript("SUM", "Scripting", embedded=True) + res = xScript.invoke((args), (), ()) + return res[0] + + # def getBasicScript() # see above + + def playWithArgs(): + Print("Fun with *args ", -9.81, 297864.681974, 8762E-137) + Print(SUM(45, -9.81, 297864.681974)) + Print(SUM(45, -9.81, 297864.681974, 8762E+137)) + + g_exportedScripts = (playWithArgs,) The %PRODUCTNAME Basic Print and SUM document-based routines accept a variable number of arguments. The Private or Public attributes have no effect. The arguments type checking is skipped for clarity. - Option Compatible ' "Standard.Scripting" module - Option Explicit - - Private Sub Print(ParamArray args() As Variant, Optional sep As String = " ") + Option Compatible ' "Standard.Scripting" module + Option Explicit + + Private Sub Print(ParamArray args() As Variant, Optional sep As String = " ") ''' Print item list of variable number ''' ' all CStr() convertible args are accepted - Dim str As String, i As Integer - If UBound(args) >= 0 Then - For i = 0 To UBound(args) - str = str + Cstr(args(i))+ sep - Next i - End If - Print str - End Sub ' Standard.Scripting.Print() - - Public Function SUM(ParamArray args() As Variant) As Variant + Dim str As String, i As Integer + If UBound(args) >= 0 Then + For i = 0 To UBound(args) + str = str + Cstr(args(i))+ sep + Next i + End If + Print str + End Sub ' Standard.Scripting.Print() + + Public Function SUM(ParamArray args() As Variant) As Variant ''' SUM a variable list of numbers ''' - Dim ndx As Integer - If UBound(args) >= 0 Then - For ndx = 0 To UBound(args) - SUM = SUM + args(ndx) - Next ndx - End If - End Function ' Standard.Scripting.SUM() + Dim ndx As Integer + If UBound(args) >= 0 Then + For ndx = 0 To UBound(args) + SUM = SUM + args(ndx) + Next ndx + End If + End Function ' Standard.Scripting.SUM()