[Solved] Embedded dialog in python extension

Creating a macro - Writing a Script - Using the API

[Solved] Embedded dialog in python extension

Postby Bastien » Fri Feb 14, 2020 5:14 pm

It's quite easy to open a dialog box created by the Basic IDE in python.

Code: Select all   Expand viewCollapse view
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=application")
    dlg.execute()
    dlg.dispose()


But what if you created your dialog file in an embedded extension? How to know the right location?

My dialog file is located in extension_name/dialogs/dialog1.xdl.

I tried to replace the dp.createDialog argument with :

Code: Select all   Expand viewCollapse view
"vnd.sun.star.script:ExtensionName.oxt|dialogs|dialog1?location=application"

But my dialog file is still not found.
Last edited by Bastien on Tue Feb 18, 2020 4:01 pm, edited 2 times in total.
LibreOffice 6.2.3.2 on Ubuntu 19.04
Bastien
 
Posts: 54
Joined: Mon May 12, 2014 2:45 pm

Re: Embedded dialod in python extension

Postby Villeroy » Fri Feb 14, 2020 8:30 pm

With protocol vnd.sun.star.script: you call a macro. You have to register the dialog model in the configuration of your extension, create a dialog, set its model and execute. Can't you find some extension with a dialog?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 27892
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Embedded dialog in python extension

Postby Bastien » Mon Feb 17, 2020 6:06 pm

Villeroy wrote:You have to register the dialog model in the configuration of your extension, create a dialog, set its model and execute.


This is the point, indeed. I miss something.

So far I tried this:

Code: Select all   Expand viewCollapse view
def test_stuff(*args):
    ctx = XSCRIPTCONTEXT.getComponentContext()
    service = ctx.getServiceManager().createInstanceWithContext(
        "com.sun.star.awt.DialogProvider", ctx
    )
    dlg = service.createDialog("/dialogs/qc_dialog.xdl")
    dlg.execute()
 


And the result is **void** for dlg, so it means that /dialogs/qc_dialog.xdl is not properly referenced. What do you mean by register the dialog model in the configuration of your extension ?
LibreOffice 6.2.3.2 on Ubuntu 19.04
Bastien
 
Posts: 54
Joined: Mon May 12, 2014 2:45 pm

Re: Embedded dialog in python extension

Postby RoryOF » Mon Feb 17, 2020 6:29 pm

You may find some helpful hints in
Transfer from Basic to Python
Apache OpenOffice 4.1.7 on Xubuntu 18.04.4 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 30646
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Embedded dialog in python extension

Postby Bastien » Mon Feb 17, 2020 6:52 pm

Thanks. I know this page which doesn't solve this problem.
LibreOffice 6.2.3.2 on Ubuntu 19.04
Bastien
 
Posts: 54
Joined: Mon May 12, 2014 2:45 pm

Re: Embedded dialog in python extension

Postby Villeroy » Mon Feb 17, 2020 8:57 pm

I confirm that the following fails with my extenstion "FreeHSQLDB" being installed.
Code: Select all   Expand viewCollapse view
def dialog_example():
     ctx = XSCRIPTCONTEXT.getComponentContext()
     smgr = ctx.getServiceManager()
     dp = smgr.createInstanceWithContext("com.sun.star.awt.DialogProvider", ctx)
     dialog = dp.createDialog("vnd.sun.star.script:FreeHSQLDB.dlgFreeHSQLDB?location=user")
     dialog.execute()
     dialog.dispose()

LibreOffice: 'uno.com.sun.star.lang.IllegalArgumentException'>: DialogProviderImpl::getDialog: library container not found!
OpenOffice: c.s.s.lang.WrappedTarget exception

whereas this code in StarBasic displays my extension's dialog:
Code: Select all   Expand viewCollapse view
sub Main
GlobalScope.DialogLibraries.loadLibrary("FreeHSQLDB")
dialog = CreateUnoDialog(DialogLibraries.FreeHSQLDB.dlgFreeHSQLDB)
dialog.execute()
dialog.dispose()
End Sub
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 27892
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Embedded dialog in python extension

Postby Villeroy » Tue Feb 18, 2020 5:15 am

THIS WORKS:
Code: Select all   Expand viewCollapse view
def dialog_example():
    ctx = XSCRIPTCONTEXT.getComponentContext()
    smgr = ctx.getServiceManager()
    dp = smgr.createInstanceWithContext("com.sun.star.awt.DialogProvider", ctx)
    dialog = dp.createDialog("vnd.sun.star.script:FreeHSQLDB.dlgFreeHSQLDB?location=application")
    dialog.execute()
    dialog.dispose()

The URL's argument needs to be location=application as in StarBasic and not location=user as in other script languages because the dialogs are stored in the "realm" of StarBasic.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 27892
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Embedded dialog in python extension

Postby Bastien » Tue Feb 18, 2020 10:43 am

Could you show me how your extension is organized?

In my case, extension name is as following "name-2.3.3.oxt" and the dialog is in a folder /dialogs/.
LibreOffice 6.2.3.2 on Ubuntu 19.04
Bastien
 
Posts: 54
Joined: Mon May 12, 2014 2:45 pm

Re: Embedded dialog in python extension

Postby Villeroy » Tue Feb 18, 2020 10:48 am

It is this one: viewtopic.php?f=21&t=77543
A library with 4 Basic modules and one dialog.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 27892
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Embedded dialog in python extension

Postby Bastien » Tue Feb 18, 2020 11:23 am

Thank you very much for your help.
Here is what I've done:
Code: Select all   Expand viewCollapse view
def test_dialog(*args):
    ctx = XSCRIPTCONTEXT.getComponentContext()
    service = ctx.getServiceManager().createInstanceWithContext(
        "com.sun.star.awt.DialogProvider", ctx
    )
    path = get_package_location(ctx)
    dlg = service.createDialog(path + "/dialogs/qc_dialog.xdl")

def get_package_location(ctx):
    srv = ctx.getByName("/singletons/com.sun.star.deployment.PackageInformationProvider")
    return srv.getPackageLocation("com.rdt.comp.Bal")


"com.rdt.comp.Bal" is the implementation name of my extension.
LibreOffice 6.2.3.2 on Ubuntu 19.04
Bastien
 
Posts: 54
Joined: Mon May 12, 2014 2:45 pm

Re: Embedded dialog in python extension

Postby Villeroy » Tue Feb 18, 2020 11:45 am

I have no clue how to address a dialog in that namespace. My only Python extension generates its dialogs dynamically at runtime for the simple reason that I really hate that packaging fuzz and try to avoid it whereever possible.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 27892
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Embedded dialog in python extension

Postby Villeroy » Tue Feb 18, 2020 5:49 pm

One thing: XSCRIPTCONTEXT does not exist within your extension. XSCRIPTCONTEXT exists in macros.
After you have installed some extension with some Python/Java/Cpp code, you have a new service added to your office suite.
If that service has an interface "com.sun.star.task.Job", a GUI element can trigger that service.

If you want to trigger this service by means of macro code:
Code: Select all   Expand viewCollapse view
ctx = uno.getComponentContext()
smgr = ctx.getServiceManager()
obj = smgr.createInstance('org.myExtension.DialogClass')
obj.trigger('dummy text')

(I can't learn the difference between XSCRIPTCONTEXT and uno.getComponentContext() in this life...)
If the service manager can create a new instance of your class (calling the __init__ method of your class), the trigger method should call the dialog somehow.

In my extension "SpecialCells" (made in 2006), the dialog is created dynamically as in this simplified snippet:
Code: Select all   Expand viewCollapse view
import uno
import unohelper
from com.sun.star.task import XJobExecutor

class DialogClass(XJobExecutor, unohelper.Base):
    def __init__(self):
        ctx = uno.getComponentContext()
        model = self.makeDialogModel() #a routine which creates all objects with all properties
        self.Dialog = createUnoService(self.ctx,"com.sun.star.awt.UnoControlDialog")           
        self.Dialog.setModel(model)
        arrangeControls(self.Dialog) #a routine which resizes and arranges all controls and the dialog window

    def trigger(*args):
        self.Dialog.setVisible(True)
        retVal = self.Dialog.execute()

## addon-implementation:
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(Dialog1,
                        "org.foo.MyExtension.Dialog1",
                        ("com.sun.star.task.Job",),)

Too ugly, too complicated, obscure, poorly documented, let alone the bizarr XML configuration.
I really tried to compose a quick demo extension with most simple python code and dialog but failed because I do not have the time to learn this again and again because my mind refuses to keep all this bullshit in memory.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 27892
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Embedded dialog in python extension

Postby Bastien » Tue Feb 18, 2020 6:02 pm

Villeroy wrote:I really tried to compose a quick demo extension with most simple python code and dialog but failed because I do not have the time to learn this again and again because my mind refuses to keep all this bullshit in memory.


I truly understand you !
LibreOffice 6.2.3.2 on Ubuntu 19.04
Bastien
 
Posts: 54
Joined: Mon May 12, 2014 2:45 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 9 guests