Files
help/source/text/sbasic/python/python_dialogs.xhp
Ilmari Lauhakangas 7e42394ecb tdf#152323 drop name attribute from <link> elements
Replacement done with

find . -name \*.xhp -print0 |xargs -0 -P 0 perl -CS -pi -e \
        's#(<link[^>]*?) +name *="[^"]*" *( [^>]+|) *>#$1$2>#g'

(note some inconsistencies with space between name and = and also having
empty value, and some more complicated expression to also clear up
double space before/after the attribute)

translation files will be prepped with:

find */helpcontent2 -name \*.po -print0 |xargs -0 -P 0 perl -CS -pi -e \
    $'s#(<link[^>]*?) +name=(?:\\\\"[^"]*\\\\"|\'[^\']*\') *( [^>]+|) *(/?>)#$1$2$3#g unless /^#/'

(note that not all languages use the " as quote character for the
attributes, but that also single quotes appera in the po file. Hence
the use of the shell $'string' syntax to be able to quote ' as \'
It also requires to quote the backslash, so that it needs to be escaped
once for the shell, then another time for perl. Also don't work on
obsolete strings (those are prefixed with #~ in the po files)
Also note that <link..></link> gets turned into <link ../> during
translation extraction (along with removal of the space between the
attribute name and the value), so the pattern needs to be slightly
different here)

Change-Id: I95e53a08e6b0095cd894109ea0de154cc4859d8f
Reviewed-on: https://gerrit.libreoffice.org/c/help/+/143713
Tested-by: Jenkins
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
2022-12-07 17:39:02 +00:00

76 lines
6.3 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<helpdocument version="1.0">
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
-->
<meta>
<topic id="text/sbasic/python/Python_Dialog">
<title id="tit" xml-lang="en-US">Opening a Dialog with Python</title>
<filename>/text/sbasic/python/python_dialogs.xhp</filename>
</topic>
</meta>
<body>
<bookmark branch="index" id="N0334">
<bookmark_value>Python;dialogs</bookmark_value>
<bookmark_value>dialog box;Python</bookmark_value>
<bookmark_value>dialogs;Python</bookmark_value>
</bookmark>
<section id="pythondialog1">
<h1 id="N0336"><variable id="pythondialog"><link href="text/sbasic/python/python_dialogs.xhp">Opening a Dialog with Python</link></variable></h1>
</section>
<paragraph role="paragraph" id="N0337">%PRODUCTNAME static dialogs are created with the <link href="text/sbasic/guide/create_dialog.xhp">Dialog editor</link> and are stored in varying places according to their personal (My Macros), shared (Application Macros) or document-embedded nature. In reverse, dynamic dialogs are constructed at runtime, from Basic or Python scripts, or using any other <link href="text/shared/guide/scripting.xhp">%PRODUCTNAME supported language</link> for that matter. Opening static dialogs with Python is illustrated herewith. Exception handling and internationalization are omitted for clarity.</paragraph>
<h2 id="N0338">My Macros or Application Macros dialogs</h2>
<paragraph role="paragraph" id="N0339">The examples below open <literal>Access2Base Trace</literal> console or the imported <literal>TutorialsDialog</literal> dialog with <menuitem>Tools - Macros - Run Macro</menuitem> menu:</paragraph>
<pycode>
<paragraph role="pycode" id="N0340" localize="false"># -*- coding: utf-8 -*-</paragraph>
<paragraph role="pycode" id="N0341" localize="false">from __future__ import unicode_literals</paragraph>
<paragraph role="pycode" id="N0342" localize="false"> </paragraph>
<paragraph role="pycode" id="N0343" localize="false">def consoleDlg():</paragraph>
<paragraph role="pycode" id="N0344" localize="false"> ctx =XSCRIPTCONTEXT.getComponentContext()</paragraph>
<paragraph role="pycode" id="N0345" localize="false"> smgr = ctx.getServiceManager()</paragraph>
<paragraph role="pycode" id="N0346" localize="false"> dp = smgr.createInstanceWithContext(&quot;com.sun.star.awt.DialogProvider&quot;, ctx)</paragraph>
<paragraph role="pycode" id="N0348" localize="false"> dlg = dp.createDialog( &quot;vnd.sun.star.script:Access2Base.dlgTrace?location=application&quot;)</paragraph>
<paragraph role="pycode" id="N0350" localize="false"> dlg.execute()</paragraph>
<paragraph role="pycode" id="N0351" localize="false"> dlg.dispose()</paragraph>
<paragraph role="pycode" id="N0352" localize="false"> </paragraph>
<paragraph role="pycode" id="N0353" localize="false">def tutorDialog():</paragraph>
<paragraph role="pycode" id="N0354" localize="false"> ctx =XSCRIPTCONTEXT.getComponentContext()</paragraph>
<paragraph role="pycode" id="N0355" localize="false"> smgr = ctx.getServiceManager()</paragraph>
<paragraph role="pycode" id="N0356" localize="false"> dp = smgr.createInstanceWithContext(&quot;com.sun.star.awt.DialogProvider&quot;, ctx)</paragraph>
<paragraph role="pycode" id="N0358" localize="false"> dlg = dp.createDialog(&quot;vnd.sun.star.script:Standard.TutorialsDialog?location=application&quot;)</paragraph>
<paragraph role="pycode" id="N0360" localize="false"> dlg.execute()</paragraph>
<paragraph role="pycode" id="N0361" localize="false"> dlg.dispose()</paragraph>
<paragraph role="pycode" id="N0362" localize="false"> </paragraph>
<paragraph role="pycode" id="N0363" localize="false">g_exportedScripts = (consoleDlg, tutorDialog)</paragraph>
</pycode>
<h2 id="N0364">Document embedded dialogs</h2>
<paragraph role="paragraph" id="N0365">The example below opens a newly edited <literal>Dialog1</literal> dialog from a document with <menuitem>Tools - Macros - Run Macro</menuitem> menu:</paragraph>
<pycode>
<paragraph role="pycode" id="N0366" localize="false"># -*- coding: utf-8 -*-</paragraph>
<paragraph role="pycode" id="N0367" localize="false">from __future__ import unicode_literals</paragraph>
<paragraph role="pycode" id="N0368" localize="false"> </paragraph>
<paragraph role="pycode" id="N0369" localize="false">def docDialog():</paragraph>
<paragraph role="pycode" id="N0370"> &quot;&quot;&quot; Display a doc-based dialog &quot;&quot;&quot;</paragraph>
<paragraph role="pycode" id="N0371" localize="false"> model = XSCRIPTCONTEXT.getDocument()</paragraph>
<paragraph role="pycode" id="N0372" localize="false"> smgr = XSCRIPTCONTEXT.getComponentContext().ServiceManager</paragraph>
<paragraph role="pycode" id="N0373" localize="false"> dp = smgr.createInstanceWithArguments( &quot;com.sun.star.awt.DialogProvider&quot;, (model,))</paragraph>
<paragraph role="pycode" id="N0375" localize="false"> dlg = dp.createDialog( &quot;vnd.sun.star.script:Standard.Dialog1?location=document&quot;)</paragraph>
<paragraph role="pycode" id="N0377" localize="false"> dlg.execute()</paragraph>
<paragraph role="pycode" id="N0378" localize="false"> dlg.dispose()</paragraph>
<paragraph role="pycode" id="N0379" localize="false"> </paragraph>
<paragraph role="pycode" id="N0380" localize="false">g_exportedScripts = (docDialog,)</paragraph>
</pycode>
<paragraph role="paragraph" id="N0381">Refer to <literal>msgbox.py</literal> in <literal>{installation}/program/</literal> directory for Python dynamic dialog examples.</paragraph>
<section id="relatedtopics" >
<embed href="text/sbasic/guide/show_dialog.xhp#show_dialog"/>
<embed href="text/sbasic/python/python_examples.xhp#pythonexamples2"/>
<embed href="text/sbasic/python/main0000.xhp#pythonscriptshelp"/>
</section>
</body>
</helpdocument>