Add controls to a Dialog With A Python Macro

The method is:

addControl ( Name as string, Control as com.sun.star.awt.XControl )

I cannot find out what the con.sun.star.awt.XControl verbiage should be. It sounds simple but…

For example, this looks like it should work: “com.sun.star.awt.UnoControlCheckBox”

But, it just throws this error message:

(<class ‘ooo_script_framework.com.sun.star.script.CannotConvertException’>: value is not interface

Thanks.

Hello,

Dialogs and macros inserting controls is a broad topic.

In this post is an example → How to get Active Tab/Page ID from a python dialog box?

Here is a link to documentation → UnoControl Service Reference

Short answer, used easymacro.py:
https://git.elmau.net/elmau/zaz/src/branch/develop/source/easymacro2.py

def dialog_example():

    opt = dict(
        Name = 'dialog',
        Title = 'My Dialog',
        Width = 200,
        Height = 200,
    )
    dlg = app.create_dialog(opt)

    opt = dict(
        Type = 'Label',
        Name = 'label',
        Label = 'My label',
        Width = 100,
        Height = 15,
        X = 10,
        Y = 10,
    )
    dlg.add_control(opt)

    opt = dict(
        Type = 'CheckBox',
        Name = 'check',
        Label = 'My Option 1',
        Width = 100,
        Height = 15,
    )
    dlg.add_control(opt)
    dlg.check.move(dlg.label)
    dlg.open()

    return

image description

Large answer:

easymacro is in develop, but, many functions is ready for used in production. Feel free ask me any questions.

  1. Create dialog: https://git.elmau.net/elmau/zaz/src/branch/develop/source/easymacro2.py#L4013
  2. Add controls: https://git.elmau.net/elmau/zaz/src/branch/develop/source/easymacro2.py#L4155