Opening a Dialog with Python

A Collabora Office statikus párbeszédablakait a Párbeszédablak-szerkesztővel hozzuk létre, és különböző helyeken tároljuk őket személyes (Saját makrók), megosztott (Alkalmazási makrók) vagy dokumentumba ágyazott jellegük szerint. Ezzel ellentétben, a dinamikus párbeszédablakokat futásidőben, Basic vagy Python parancsfájlokból, vagy bármely más Collabora Office támogatott nyelv használatával lehet létrehozni. A statikus párbeszédablakok megnyitását Pythonnal az alábbiakban illusztráljuk. A kivételkezelést és a nemzetköziesítést az áttekinthetőség kedvéért kihagyjuk.

My Macros or Application 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)

Dokumentumba beágyazott párbeszédablakok

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 Python dynamic dialog examples.

Támogasson minket!