summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlain Romedenne <alain.romedenne@libreoffice.org>2021-09-27 18:30:36 +0200
committerOlivier Hallot <olivier.hallot@libreoffice.org>2021-10-11 01:28:36 +0200
commit79cf3e922b00a74a6a29ec324589aab7f05c5886 (patch)
treee1902c8d2d6e4bd95041bf1a1c629e0163330f89
parentd155b3e2133f3eb6593d438b69dc3e42d37b11ff (diff)
Running Python Interactive Console:
- Provide a non ambiguous capture - Present APSO console as optional - Provide GNU/Linux appropriate information Change-Id: Ice7069242fc900b5c7c60a576671f62f841a313d Reviewed-on: https://gerrit.libreoffice.org/c/help/+/122732 Tested-by: Jenkins Reviewed-by: Olivier Hallot <olivier.hallot@libreoffice.org>
-rw-r--r--Package_html_media.mk1
-rw-r--r--source/media/helpimg/python/python_interactive_console.pngbin0 -> 33373 bytes
-rw-r--r--source/text/sbasic/python/python_shell.xhp38
3 files changed, 31 insertions, 8 deletions
diff --git a/Package_html_media.mk b/Package_html_media.mk
index 6258055767..25ddb7910b 100644
--- a/Package_html_media.mk
+++ b/Package_html_media.mk
@@ -349,6 +349,7 @@ $(eval $(call gb_Package_add_files_with_dir,helpcontent2_html_media,$(LIBO_SHARE
helpimg/starmath/un21214.svg \
helpimg/starmath/un21215.svg \
helpimg/starmath/un21221.svg \
+ helpimg/python/python_interactive_console.png \
helpimg/python/python_shell.png \
helpimg/sw_paste_range.png \
helpimg/sw_signatureline01.png \
diff --git a/source/media/helpimg/python/python_interactive_console.png b/source/media/helpimg/python/python_interactive_console.png
new file mode 100644
index 0000000000..94c9452b24
--- /dev/null
+++ b/source/media/helpimg/python/python_interactive_console.png
Binary files differ
diff --git a/source/text/sbasic/python/python_shell.xhp b/source/text/sbasic/python/python_shell.xhp
index 0b724b88d4..745b22d18d 100644
--- a/source/text/sbasic/python/python_shell.xhp
+++ b/source/text/sbasic/python/python_shell.xhp
@@ -20,18 +20,23 @@
<bookmark_value>Python Interactive Shell</bookmark_value>
</bookmark>
<section id="pythonshell">
- <paragraph role="heading" level="1" id="N0118"><variable id="pythonshell1"><link href="text/sbasic/python/python_shell.xhp" name="python shell">Running Python Interactive Console</link></variable></paragraph>
+ <h1 id="N0118"><variable id="pythonshell1"><link href="text/sbasic/python/python_shell.xhp" name="python shell">Running Python Interactive Console</link></variable></h1>
</section>
<paragraph role="paragraph" id="N0119">The Python interactive console, also known as Python interpreter or Python shell, provides programmers with a quick way to execute commands and try out and test code without creating a file. UNO objects introspection as well as %PRODUCTNAME Python modules documentation can be obtained from the terminal.</paragraph>
- <paragraph role="heading" level="2" id="N0121">Using a Basic macro:</paragraph>
+
+ <note id="par_id851633601202270">From a full-featured %PRODUCTNAME installed package, use either Basic or Python:</note>
+ <h2 id="N0121">Using a Basic macro</h2>
<bascode>
<paragraph role="bascode" id="N0122" localize="false">Sub interpreter_console</paragraph>
+ <paragraph role="bascode" id="bas_id731633624333087" localize="false"> Const UNIX = 4</paragraph>
<paragraph role="bascode" id="N0123" localize="false"> ps = CreateUnoService(&quot;com.sun.star.util.PathSettings&quot;)</paragraph>
<paragraph role="bascode" id="N0124" localize="false"> install_path = ConvertFromURL(ps.Module)</paragraph>
- <paragraph role="bascode" id="N0125" localize="false"> Shell( install_path + GetPathSeparator() + &quot;python&quot; )</paragraph>
+ <paragraph role="bascode" id="bas_id461633624179286" localize="false"> cmd = IIF(GetGuiType()=UNIX,"x-terminal-emulator -e ","")</paragraph>
+ <paragraph role="bascode" id="N0125" localize="false"> Shell(cmd + install_path + GetPathSeparator() + &quot;python&quot; )</paragraph>
<paragraph role="bascode" id="N0126" localize="false">End Sub</paragraph>
</bascode>
- <paragraph role="heading" level="2" id="N0127">Using a Python macro:</paragraph>
+
+ <h2 id="N0127">Using a Python macro</h2>
<pycode>
<paragraph role="pycode" id="N0128" localize="false"># -*- coding: utf-8 -*-</paragraph>
<paragraph role="pycode" id="N0129" localize="false">from __future__ import unicode_literals</paragraph>
@@ -47,13 +52,30 @@
<paragraph role="pycode" id="N0139" localize="false"> subprocess.Popen(pgm) # Start Python interactive Shell</paragraph>
<paragraph role="pycode" id="N0140" localize="false"> </paragraph>
</pycode>
- <paragraph role="heading" level="2" id="N0141">Usage:</paragraph>
+ <h3 id="N0141">Example output</h3>
<paragraph role="paragraph" id="N0142">
- <image src="media/helpimg/python/python_shell.png" id="N0143"><alt id="N0144">Python Interactive Console</alt></image>
+ <image src="media/helpimg/python/python_interactive_console.png" id="N0143"><alt id="N0143">Python Interactive Console</alt></image>
+ </paragraph>
+
+ <switch select="sys">
+ <case select="UNIX">
+ <h2 id="hd_id381633446811095">Using the Terminal</h2>
+ <note id="par_id801633601715910">From a %PRODUCTNAME copy included in a GNU/Linux platform, use the terminal as shown:</note>
+ <paragraph role="paragraph" id="par_id531633444780190"><literal>whereis</literal> or <literal>type</literal> terminal commands help locate Python interactive console:</paragraph>
+ <paragraph role="paragraph" id="par_id871633361808210" localize="false"><br/><input>user@computer:~$ </input><emph>type -p python3</emph><br/><input>/usr/bin/python3</input><br/> <input>user@computer:~$ </input><emph>/usr/bin/python3</emph><br/> <input>Python 3.7.5 (default, Nov 20 2019, 09:21:52)</input><br/><input>[GCC 9.2.1 20191008] on linux</input><br/><input>Type "help", "copyright", "credits" or "license" for more information.</input><br/><input>>>> </input><emph>import uno</emph><br/><input>>>> </input><emph>dir(uno)</emph><br/><input>['Any', 'Bool', 'ByteSequence', 'Char', 'Enum', 'PY2', 'Type', '_ConstantGroup', '__builtin__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_builtin_import', '_component_context', '_impl_getConstantGroupByName', '_uno_extract_printable_stacktrace', '_uno_import', '_uno_struct__eq__', '_uno_struct__getattr__', '_uno_struct__init__', '_uno_struct__ne__', '_uno_struct__repr__', '_uno_struct__setattr__', '_uno_struct__str__', 'absolutize', 'createUnoStruct', 'fileUrlToSystemPath', 'generateUuid', 'getClass', 'getComponentContext', 'getConstantByName', 'getCurrentContext', 'getTypeByName', 'invoke', 'isInterface', 'os', 'pyuno', 'setCurrentContext', 'six_string_types', 'socket', 'sys', 'systemPathToFileUrl', 'traceback', 'warnings']</input><br/><input>>>> </input><emph>exit()</emph><br/><input>user@computer:~$</input></paragraph>
+ </case>
+ </switch>
+
+ <h2 id="hd_id311633513620803">Alternative console</h2>
+ <paragraph role="paragraph" id="par_id81632760673283">Use <link href="https://extensions.libreoffice.org/extensions/apso-alternative-script-organizer-for-Python" name="APSO extension">APSO extension</link> console as an alternative:</paragraph>
+ <paragraph role="paragraph" id="N0144">
+ <image src="media/helpimg/python/python_shell.png" id="N0144"><alt id="N0144">APSO console</alt></image>
</paragraph>
<section id="relatedtopics">
+ <paragraph role="paragraph" id="par_id351633599611244"><link href="text/sbasic/shared/03/sf_exception.html?#PythonShell" name="PythonShell method"><literal>PythonShell</literal></link> function in <link href="text/sbasic/shared/03/sf_exception.html" name="ScriptForge.Exception service"><literal>ScriptForge.Exception</literal></link> service</paragraph>
<embed href="text/sbasic/python/python_examples.xhp#pythonexamples2"/>
<embed href="text/sbasic/python/main0000.xhp#pythonscriptshelp"/>
+
</section>
-</body>
-</helpdocument>
+ </body>
+</helpdocument> \ No newline at end of file