[Solved] Packaging a Dialog Box with an Addon

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

[Solved] Packaging a Dialog Box with an Addon

Post by saleem145 »

Hello,

I am developing an add-on and almost have everything working. What I would like to do it is have it throw up a dialog box so the user can enter some parameters which are then used to make a chart. Couple of questions --

1. What files are needed -- an xml that describes the specifications of the dialog box?? So I need any other file??

2. Do I need to make changes to the manifest.xml file??

3. Finally how do I pop it in python --

Code: Select all

def create_dialog(ctx, doc, lib_name, dialog_name):
    
    dialog_lib = doc.DialogLibraries
    if not dialog_lib.isLibraryLoaded(lib_name):
        dialog_lib.loadLibrary(lib_name)
    lib = dialog_lib.getByName(lib_name)
    input_provider = lib.getByName(dialog_name)
    
    return ctx.getServiceManager().createInstanceWithArgumentsAndContext(
                "com.sun.star.awt.DialogProvider",
                (None, input_provider.createInputStream(), lib, None),
                ctx).createDialog("")
The code above could be used to pop the dialog box if it were part of the document. In this case it will be part of the oxt or Addon. So how do I alter this code.

Thanks in advance for your help!!

Saleem
Last edited by saleem145 on Wed Aug 01, 2012 11:49 pm, edited 1 time in total.
OpenOffice 3.4.0
Mac OS X 10.5.8
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Packaging a Dialog Box with an Addon

Post by hanya »

1. What files are needed -- an xml that describes the specifications of the dialog box?? So I need any other file??

2. Do I need to make changes to the manifest.xml file??
If you pack dialogs into your package as part of basic library or as dialog only library, add entry to manifest file for it according to : http://wiki.services.openoffice.org/wik ... ile_Format

If you need to use your dialog only through your Python macro or component, you can put them into your package as normal file without their entries in manifest. Simply put xdl files into your package.
3. Finally how do I pop it in python --
Use css.awt.DialogProvider service to instantiate dialog, see: http://www.openoffice.org/api/docs/comm ... ider2.html
The methods of the interface supported by the service take URL to a dialog to instantiate.

You can get your package location as URL by css.deployment.PackageInformationProvider singleton , see: http://www.openoffice.org/api/docs/comm ... vider.html
If you do not have extension identifier for your extension, you have to add it, see: http://wiki.services.openoffice.org/wik ... dentifiers
After version 3.3, once extension identifier is given to your extension package, you do not need to use PackageInformationProvider to get your package location. You can use "vnd.sun.star.extension:" protocol to specify it, see: http://wiki.services.openoffice.org/wik ... _Providers

Assuming extension identifier of a package is "org.foo.bar.Hoge", a dialog can be instantiated from its package with the protocol mentioned above as follows:

Code: Select all

def create_dialog(ctx, url):
    return ctx.getServiceManager().createInstanceWithContext("com.sun.star.awt.DialogProvider", ctx).createDialog(url)

# dialog placed in dialogs/ directory in the package
dialog = create_dialog(ctx, "vnd.sun.star.extension://org.foo.bar.Hoge/dialogs/dialog.xdl")
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: Packaging a Dialog Box with an Addon

Post by saleem145 »

What is an xdl file?? Is it just the xml file containing the specification of the dialog box??

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="Dialog1" dlg:left="221" dlg:top="105" dlg:width="201" 
dlg:height="164" dlg:closeable="true" dlg:moveable="true">
 <dlg:styles>
  <dlg:style dlg:style-id="0" dlg:background-color="0xebe6e6"/>
  <dlg:style dlg:style-id="1" dlg:background-color="0xebe5e5" dlg:font-name="Times New Roman" dlg:font-height="10" dlg:font-stylename="Bold" dlg:font-family="roman" dlg:
font-weight="150"/>
  <dlg:style dlg:style-id="2" dlg:background-color="0xebe5e5" dlg:font-name="Times New Roman" dlg:font-height="10" dlg:font-stylename="Bold" dlg:font-family="roman" dlg:
font-weight="150"/>
 </dlg:styles>
 <dlg:bulletinboard>
  <dlg:numericfield dlg:id="Amplitude" dlg:tab-index="0" dlg:left="6" dlg:top="49" dlg:width="91" dlg:height="12" dlg:decimal-accuracy="5" dlg:value-min="0"/>
  <dlg:numericfield dlg:id="Frequency" dlg:tab-index="2" dlg:left="6" dlg:top="89" dlg:width="91" dlg:height="12" dlg:decimal-accuracy="5" dlg:value-min="0"/>
  <dlg:numericfield dlg:id="Phase" dlg:tab-index="4" dlg:left="6" dlg:top="126" dlg:width="91" dlg:height="12" dlg:decimal-accuracy="5" dlg:value-min="0"/>
  <dlg:text dlg:style-id="0" dlg:id="Label1" dlg:tab-index="7" dlg:left="54" dlg:top="33" dlg:width="91" dlg:height="9" dlg:value="Amplitude (>=0)" dlg:align="center"
/>
  <dlg:button dlg:id="CommandButton1" dlg:tab-index="6" dlg:left="33" dlg:top="142" dlg:width="47" dlg:height="12" dlg:value="OK" dlg:button-type="ok"/>
  <dlg:text dlg:style-id="0" dlg:id="Label2" dlg:tab-index="8" dlg:left="56" dlg:top="72" dlg:width="91" dlg:height="9" dlg:value="Frequency (>=0)" dlg:align="center"
/>
  <dlg:text dlg:style-id="0" dlg:id="Label3" dlg:tab-index="9" dlg:left="54" dlg:top="112" dlg:width="91" dlg:height="9" dlg:value="Phase" dlg:align="center"/>
  <dlg:numericfield dlg:id="CosAmplitude" dlg:tab-index="1" dlg:left="101" dlg:top="49" dlg:width="91" dlg:height="12" dlg:decimal-accuracy="5" dlg:value-min="0"/>
  <dlg:numericfield dlg:id="CosFrequency" dlg:tab-index="3" dlg:left="101" dlg:top="89" dlg:width="91" dlg:height="12" dlg:decimal-accuracy="5" dlg:value-min="0"/>
  <dlg:numericfield dlg:id="CosPhase" dlg:tab-index="5" dlg:left="103" dlg:top="126" dlg:width="91" dlg:height="12" dlg:decimal-accuracy="5" dlg:value-min="0"/>
  <dlg:button dlg:id="CommandButton2" dlg:tab-index="10" dlg:left="121" dlg:top="142" dlg:width="47" dlg:height="12" dlg:value="Cancel" dlg:button-type="cancel"/>
  <dlg:text dlg:style-id="1" dlg:id="Label4" dlg:tab-index="11" dlg:left="29" dlg:top="14" dlg:width="39" dlg:height="12" dlg:value="Sine" dlg:align="center"/>
  <dlg:text dlg:style-id="0" dlg:id="Label5" dlg:tab-index="12" dlg:left="54" dlg:top="33" dlg:width="91" dlg:height="9" dlg:value="Amplitude (>=0)" dlg:align="center
"/>
  <dlg:text dlg:style-id="2" dlg:id="Label6" dlg:tab-index="13" dlg:left="123" dlg:top="14" dlg:width="39" dlg:height="12" dlg:value="Cosine" dlg:align="center"/>
 </dlg:bulletinboard>
</dlg:window>
OpenOffice 3.4.0
Mac OS X 10.5.8
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: Packaging a Dialog Box with an Addon

Post by saleem145 »

Figured it out actually....lets hope I can get it to work!!
OpenOffice 3.4.0
Mac OS X 10.5.8
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Packaging a Dialog Box with an Addon

Post by hanya »

You can copy dialog files having xdl file extension from your basic libraries or you can store individual dialog file by Export Dialog button on the Basic IDE.
When the dialog is localized using Manage Language button of the Basic IDE, it has additional resource files contains string resources for each language you have added. When you load your dialog using DialogProvider service, it is loaded automatically.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: Packaging a Dialog Box with an Addon

Post by saleem145 »

Hanya,

I have the following code...

Code: Select all

def GetDialogURL(ctx, identifier, xdl):

  PIP = ctx.getByName("/singletons/com.sun.star.deployment.PackageInformationProvider")
  return PIP.getPackageLocation(identifier)  + "/" + xdl

def CreateDialogPlacedInTheExtension(dialogURL):

    return CreateUnoService("com.sun.star.awt.DialogProvider").createDialog(dialogURL)
I have tested GetDialogURL(ctx, "my_module", "MakeChart.xdl") and it returns a file path....but the dialog does not show up.

Interestingly the same code implemented in basic works which means the returned path is correct and the dialog exists and nothing is wrong with the file.

The part that is not working is

CreateUnoService("com.sun.star.awt.DialogProvider")

which leads me to suspect I am missing an import or something.

Thanks,

Saleem


FYI my imports are --

Code: Select all

import os
import unohelper
import math
import array
import sys
from com.sun.star.lang import Locale
from com.sun.star.awt import Rectangle
from com.sun.star.awt import XDialog
from com.sun.star.awt import XDialogProvider
from com.sun.star.table import CellRangeAddress
from com.sun.star.chart.ChartAxisPosition import ZERO
from com.sun.star.awt.FontWeight import BOLD
from com.sun.star.task import XJobExecutor
OpenOffice 3.4.0
Mac OS X 10.5.8
saleem145
Posts: 130
Joined: Mon Jul 02, 2012 4:47 pm

Re: [Solved] Packaging a Dialog Box with an Addon

Post by saleem145 »

I have it working. In python we need to implement CreateUnoService which I have done as follows,

Code: Select all

def CreateUnoService(serviceName):

    sm = uno.getComponentContext().ServiceManager

    return sm.createInstanceWithContext(serviceName, uno.getComponentContext())
OpenOffice 3.4.0
Mac OS X 10.5.8
Post Reply