From 5489ccad66f7bb892c09c68baa9d38b351c01b59 Mon Sep 17 00:00:00 2001 From: Alain Romedenne Date: Wed, 20 Feb 2019 13:22:05 -0300 Subject: [PATCH] Python: Help pages on opening dialogs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib71ad229ff908c1bb7c426f2242729d53cb01ff8 Reviewed-on: https://gerrit.libreoffice.org/68100 Tested-by: Jenkins Reviewed-by: LibreOfficiant Reviewed-by: Olivier Hallot --- AllLangHelp_sbasic.mk | 1 + source/text/sbasic/python/python_dialogs.xhp | 76 +++++++++++++++++++ source/text/sbasic/python/python_examples.xhp | 2 +- 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 source/text/sbasic/python/python_dialogs.xhp diff --git a/AllLangHelp_sbasic.mk b/AllLangHelp_sbasic.mk index bc44ddbce0..859e794399 100644 --- a/AllLangHelp_sbasic.mk +++ b/AllLangHelp_sbasic.mk @@ -369,6 +369,7 @@ $(eval $(call gb_AllLangHelp_add_helpfiles,sbasic,\ helpcontent2/source/text/sbasic/shared/special_vba_func \ helpcontent2/source/text/sbasic/shared/vbasupport \ helpcontent2/source/text/sbasic/python/main0000 \ + helpcontent2/source/text/sbasic/python/python_dialogs \ helpcontent2/source/text/sbasic/python/python_examples \ helpcontent2/source/text/sbasic/python/python_ide \ helpcontent2/source/text/sbasic/python/python_import \ diff --git a/source/text/sbasic/python/python_dialogs.xhp b/source/text/sbasic/python/python_dialogs.xhp new file mode 100644 index 0000000000..2ba1ad81ff --- /dev/null +++ b/source/text/sbasic/python/python_dialogs.xhp @@ -0,0 +1,76 @@ + + + + + + Python : Opening a Dialog + /text/sbasic/python/python_dialogs.xhp + + + + + Python;dialogs + dialog box;Python + dialogs;Python + +
+

Opening a Dialog in Python

+
+ %PRODUCTNAME static dialogs are created with the Dialog editor and are stored in varying places according to their personal (My Macros), shared (%PRODUCTNAME Macros) or document-embedded nature. In reverse, dynamic dialogs are constructed at runtime, from on Basic or Python scripts, or using any other %PRODUCTNAME supported language for that matter. Opening static dialogs with Python is illustrated herewith. Exception handling and internationalization are omitted for clarity. +

My Macros or %PRODUCTNAME Macros dialogs

+ The examples below open Access2Base Trace console or the imported TutorialsDialog dialog with Tools – Macros – Run Macro... menu: + + # -*- coding: utf-8 -*- + from __future__ import unicode_literals + + def consoleDlg(): + ctx =XSCRIPTCONTEXT.getComponentContext() + smgr = ctx.getServiceManager() + dp = smgr.createInstanceWithContext("com.sun.star.awt.DialogProvider", ctx) + dlg = dp.createDialog( "vnd.sun.star.script:Access2Base.dlgTrace?location=application") + dlg.execute() + dlg.dispose() + + def tutorDialog(): + ctx =XSCRIPTCONTEXT.getComponentContext() + smgr = ctx.getServiceManager() + dp = smgr.createInstanceWithContext("com.sun.star.awt.DialogProvider", ctx) + dlg = dp.createDialog("vnd.sun.star.script:Standard.TutorialsDialog?location=application") + dlg.execute() + dlg.dispose() + + g_exportedScripts = (consoleDlg, tutorDialog) + +

Document embedded dialogs

+ The example below opens a newly edited Dialog1 dialog from a document with Tools – Macros – Run Macro... menu: + + # -*- coding: utf-8 -*- + from __future__ import unicode_literals + + def docDialog(): + """ Display a doc-based dialog """ + model = XSCRIPTCONTEXT.getDocument() + smgr = XSCRIPTCONTEXT.getComponentContext().ServiceManager + dp = smgr.createInstanceWithArguments( "com.sun.star.awt.DialogProvider", (model,)) + dlg = dp.createDialog( "vnd.sun.star.script:Standard.Dialog1?location=document") + dlg.execute() + dlg.dispose() + + g_exportedScripts = (docDialog,) + +
+ + Refer to msgbox.py in <$installation>/program/ directory for an example of Python dynamic dialogs. + + + +
+ +
diff --git a/source/text/sbasic/python/python_examples.xhp b/source/text/sbasic/python/python_examples.xhp index 3dd1c5564b..779bfddef1 100644 --- a/source/text/sbasic/python/python_examples.xhp +++ b/source/text/sbasic/python/python_examples.xhp @@ -28,13 +28,13 @@ +